-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassembly_alarm.asm
1327 lines (970 loc) · 30 KB
/
assembly_alarm.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;Timer 1 ISR Generates a 2kHz square wave at pin P1.1 using
$NOLIST
$MODLP51
$LIST
; There is a couple of typos in MODLP51 in the definition of the timer 0/1 reload
; special function registers (SFRs), so:
CLK EQU 22118400 ; Microcontroller system crystal frequency in Hz
TIMER0_RATE EQU 4096 ; 2048Hz squarewave (peak amplitude of CEM-1203 speaker)
TIMER0_RELOAD EQU ((65536-(CLK/TIMER0_RATE)))
TIMER2_RATE EQU 1000 ; 1000Hz, for a timer tick of 1ms
TIMER2_RELOAD EQU ((65536-(CLK/TIMER2_RATE)))
SECONDS EQU 0
BOOT_BUTTON equ P4.5
SOUND_OUT equ P1.1
UPDOWN equ P0.0
;use button p0.5 to incriment numbers when setting time
INCRIMENT_BUTTON equ P0.5
;use button at p0.1 to go to mode where time is set
SET_TIME_MODE equ P0.1
TIMER_TOGGLE equ P0.3 ;to toggle between setting timer fields and acivating timer
; Reset vector
org 0x0000
ljmp main
; External interrupt 0 vector (not used in this code)
org 0x0003
reti
; Timer/Counter 0 overflow interrupt vector
org 0x000B
ljmp Timer0_ISR
; External interrupt 1 vector (not used in this code)
org 0x0013
reti
; Timer/Counter 1 overflow interrupt vector (not used in this code)
org 0x001B
reti
; Serial port receive/transmit interrupt vector (not used in this code)
org 0x0023
reti
; Timer/Counter 2 overflow interrupt vector
org 0x002B
ljmp Timer2_ISR
; In the 8051 we can define direct access variables starting at location 0x30 up to location 0x7F
dseg at 0x30
Count1ms: ds 2 ; Used to determine when half second has passed
seconds_field: ds 1 ; The seconds counter is incrememted in the ISR every second and it represents seconds
minutes_field: ds 1 ;for minutes
hours_field: ds 1 ;for hours
minutes_field_alarm: ds 1 ;keeping track of when to set off the alarm
hours_field_alarm: ds 1
;timer fields to tick down and ring at 0
seconds_field_timer: ds 1
minutes_field_timer: ds 1
hours_field_timer: ds 1
; In the 8051 we have variables that are 1-bit in size. We can use the setb, clr, jb, and jnb
; instructions with these variables. This is how you define a 1-bit variable:
bseg
half_seconds_flag: dbit 1 ; Set to one in the ISR every time 500 ms had passed
seconds_flag: dbit 1 ;set to one in the ISR every time 1000ms pass
AMPM_flag: dbit 1 ;set to 1 for PM and 0 for AM
AMPM_flag_alarm: dbit 1 ;choosing am/pm for the alarm
speaker_on_flag: dbit 1 ;flag to tell us whether or not to have the speaker, will be activated in alarm ringing loop
timer_on_flag: dbit 1;flag to tell the ISR to decrement seconds_field_timer every second
cseg
; These 'equ' must match the hardware wiring
LCD_RS equ P3.2
;LCD_RW equ PX.X ; Not used in this code, connect the pin to GND
LCD_E equ P3.3
LCD_D4 equ P3.4
LCD_D5 equ P3.5
LCD_D6 equ P3.6
LCD_D7 equ P3.7
$NOLIST
$include(LCD_4bit.inc) ; A library of LCD related functions and utility macros
$LIST
; 1234567890123456 <- This helps determine the location of the counter
Initial_Message: db 'TIME ', 0
set_message: db 'SET ',0
alarm_string: db 'ALARM',0
ampm_string: db 'AM/PM',0
off: db 'off',0
on: db 'on ',0
clear: db ' ',0
wake_up: db 'WAKEUP!!WAKEUP!!',0
timer: db 'TIMER',0
timer_dome: db 'TIMER!!! DONE!!!'
;---------------------------------;
; Time display subroutines ;
;---------------------------------;
;updating minutes based on hours, hours on minutes, AM/PM on hours and resetting values that hit the upper limit
update_time:
;making seconds reset at 60 and incrimenting minutes
MOV R4,seconds_field
CJNE R4,#0x60,NOT_SIXTY_SECONDS
;if 60 seconds passed, reset seconds and incriment minutes
;don't forget to decimal adjust
MOV a,minutes_field
ADD a,#0x01
da a
MOV minutes_field,a
clr a
MOV seconds_field,#0x00
;skip incrimenting minutes and resetting seconds
NOT_SIXTY_SECONDS:
;making minutes reset at 60 and incrimenting hours
MOV R4,minutes_field
CJNE R4,#0x60,NOT_SIXTY_MINUTES
;if 60 seconds passed, reset minutes and incriment hours
;don't forget to decimal adjust
MOV a,hours_field
ADD a,#0x01
da a
MOV hours_field,a
clr a
MOV minutes_field,#0x00
;skip incrimenting hours and resetting minutes
NOT_SIXTY_MINUTES:
;making hours reset at 13 and swapping AMPM_flag
MOV R4,hours_field
CJNE R4,#0x13,NOT_THIRTEEN_HOURS
MOV R4,#0x01
MOV hours_field,R4
MOV R4,AMPM_flag
cjne R4,#0b0, SWITCH_TO_AM
;JB AMPM_flag,SWITCH_TO_AM
mov AMPM_flag,#0b1
;setb AMPM_flag
sjmp DONT_SWITCH_TO_AM
SWITCH_TO_AM:
MOV AMPM_flag,#0b0
;clr AMPM_flag
DONT_SWITCH_TO_AM:
NOT_THIRTEEN_HOURS:
ret
display_time:
;display seconds
Set_Cursor(1, 12) ; the place in the LCD where we want the seconds value
Display_BCD(seconds_field) ; This macro is also in 'LCD_4bit.inc'
;display minutes
Set_Cursor(1,9)
Display_BCD(minutes_field)
;display hours
Set_Cursor(1,6)
Display_BCD(hours_field)
;picking between AM and PM
;write the M
Set_Cursor(1,16)
Display_char(#'M')
;write the A or P
Set_Cursor(1,15)
MOV R4,AMPM_flag
cjne R4,#0b0,DISPLAY_PM
;jb AMPM_flag,DISPLAY_PM
;display AM
Display_char(#'A')
sjmp DONT_DISPLAY_PM
DISPLAY_PM:
Display_char(#'P')
DONT_DISPLAY_PM:
ret
;subroutine to display the time for the alarm
display_alarm_time:
Set_Cursor(2,6)
Display_BCD(hours_field_alarm)
Set_Cursor(2,9)
Display_BCD(minutes_field_alarm)
;display colon between hours and minutes
Set_Cursor(2,8)
Display_char(#':')
;display am/pm for alarm
;write the M for alarm
Set_Cursor(2,16)
Display_char(#'M')
;write the A or P for alarm
Set_Cursor(2,15)
MOV R4,AMPM_flag_alarm
cjne R4,#0b0,DISPLAY_PM_ALARM
;jb AMPM_flag,DISPLAY_PM
;display AM
Display_char(#'A')
sjmp DONT_DISPLAY_PM_ALARM
DISPLAY_PM_ALARM:
Display_char(#'P')
DONT_DISPLAY_PM_ALARM:
ret
;---------------------------------;
; Timer display subroutines ;
;---------------------------------;
display_timer_time:
Set_cursor(2,8)
Display_BCD(hours_field_timer)
Set_cursor(2,10)
Display_char(#':')
Set_cursor(2,11)
Display_BCD(minutes_field_timer)
Set_cursor(2,13)
Display_char(#':')
Set_cursor(2,14)
Display_BCD(seconds_field_timer)
ret
update_timer:
;making seconds reset at -1 (99) and decrimenting minutes
MOV R4,seconds_field_timer
CJNE R4,#0x99,NOT_99
;if seconds go to zero, reset seconds and decriment minutes
;don't forget to decimal adjust
MOV a,minutes_field_timer
ADD a,#0x99
da a
MOV minutes_field_timer,a
clr a
MOV seconds_field_timer,#0x59
;skip decrimenting minutes and resetting seconds
NOT_99:
;making minutes reset at -1 (99) and decrimenting hours
MOV R4,minutes_field_timer
CJNE R4,#0x99,NOT_99_BOOGALOO
;if minutes roll over to 99, reset minutes and decriment hours
;don't forget to decimal adjust
MOV a,hours_field_timer
ADD a,#0x99
da a
MOV hours_field_timer,a
clr a
MOV minutes_field_timer,#0x59
;skip incrimenting hours and resetting minutes
NOT_99_BOOGALOO:
ret
;---------------------------------;
; Routine to initialize the ISR ;
; for timer 0 ;
;---------------------------------;
Timer0_Init:
mov a, TMOD
anl a, #0xf0 ; Clear the bits for timer 0
orl a, #0x01 ; Configure timer 0 as 16-timer
mov TMOD, a
mov TH0, #high(TIMER0_RELOAD)
mov TL0, #low(TIMER0_RELOAD)
; Set autoreload value
mov RH0, #high(TIMER0_RELOAD)
mov RL0, #low(TIMER0_RELOAD)
; Enable the timer and interrupts
setb ET0 ; Enable timer 0 interrupt
setb TR0 ; Start timer 0
clr TR0 ;timer 0 should be off by default
ret
;---------------------------------;
; ISR for timer 0. Set to execute;
; every 1/4096Hz to generate a ;
; 2048 Hz square wave at pin P1.1 ;
;---------------------------------;
Timer0_ISR:
;clr TF0 ; According to the data sheet this is done for us already.
cpl SOUND_OUT ; Connect speaker to P1.1!
reti
;---------------------------------;
; Routine to initialize the ISR ;
; for timer 2 ;
;---------------------------------;
Timer2_Init:
mov T2CON, #0 ; Stop timer/counter. Autoreload mode.
mov TH2, #high(TIMER2_RELOAD)
mov TL2, #low(TIMER2_RELOAD)
; Set the reload value
mov RCAP2H, #high(TIMER2_RELOAD)
mov RCAP2L, #low(TIMER2_RELOAD)
; Init One millisecond interrupt counter. It is a 16-bit variable made with two 8-bit parts
clr a
mov Count1ms+0, a
mov Count1ms+1, a
; Enable the timer and interrupts
setb ET2 ; Enable timer 2 interrupt
setb TR2 ; Enable timer 2
ret
;---------------------------------;
; ISR for timer 2 ;
;---------------------------------;
Timer2_ISR:
clr TF2 ; Timer 2 doesn't clear TF2 automatically. Do it in ISR
cpl P1.0 ; To check the interrupt rate with oscilloscope. It must be precisely a 1 ms pulse.
; The two registers used in the ISR must be saved in the stack
push acc
push psw
; Increment the 16-bit one mili second counter
inc Count1ms+0 ; Increment the low 8-bits first
mov a, Count1ms+0 ; If the low 8-bits overflow, then increment high 8-bits
jnz Inc_Done
inc Count1ms+1
Inc_Done:
; Check if a full second has passed
mov a, Count1ms+0
cjne a, #low(1000), Timer2_ISR_done ; Warning: this instruction changes the carry flag!
mov a, Count1ms+1
cjne a, #high(1000), Timer2_ISR_done
; 1000 milliseconds have passed. Set a flag so the main program knows
setb seconds_flag ; Let the main program know one full second had passed
setb AMPM_flag ;to keep track of AM or PM time, 1 is PM 0 is AM
;only want to enable timer 0 toggling if the alarm is supposed to be ringing
jnb speaker_on_flag,dont_toggle_speaker
cpl TR0 ; Enable/disable timer/counter 0. This line creates a beep-silence-beep-silence sound.
dont_toggle_speaker:
; Reset to zero the milli-seconds counter, it is a 16-bit variable
clr a
mov Count1ms+0, a
mov Count1ms+1, a
;Decrement timer counter if timer enable flag is on
jnb timer_on_flag,dont_decrement_seconds
mov a,seconds_field_timer
add a,#0x99
da a
mov seconds_field_timer,a
clr a
dont_decrement_seconds:
; Increment the seconds field counter
mov a, seconds_field
jnb UPDOWN, Timer2_ISR_decrement
add a, #0x01
sjmp Timer2_ISR_da
Timer2_ISR_decrement:
add a, #0x99 ; Adding the 10-complement of -1 is like subtracting 1.
Timer2_ISR_da:
da a ; Decimal adjust instruction. Check datasheet for more details!
mov seconds_field, a
Timer2_ISR_done:
pop psw
pop acc
reti
;---------------------------------;
; Routines for setting time ;
;---------------------------------;
;---------------------------------;
; Set hours ;
;---------------------------------;
;setting hours on the time
SET_TIME_HOURS:
keep_setting_hours:
;Let the user know they are setting hours
Set_cursor(1,1)
Send_Constant_String(#set_message)
Set_cursor(1,4)
Display_char(#'h')
Set_cursor(1,5)
Display_char(#'r')
;make sure to display the time
lcall update_time
lcall display_time
;Look for button press to switch to setting minutes
jb SET_TIME_MODE,dont_switch_to_minutes
;debounce delay
Wait_Milli_Seconds(#50)
jb SET_TIME_MODE,dont_switch_to_minutes
;wait for button release
adenosine: jnb SET_TIME_MODE, adenosine
ljmp SET_TIME_MINUTES
dont_switch_to_minutes:
;*****READ INPUTS TO INCRIMENT AND DECREMENT HOURS*****
jb INCRIMENT_BUTTON,do_not_incriment_hours
;debounce delay
Wait_Milli_Seconds(#50)
jb INCRIMENT_BUTTON,do_not_incriment_hours
;wait for button release
hyoscyamine: jnb INCRIMENT_BUTTON, hyoscyamine
;button was pressed, time to incriment
MOV a,hours_field
ADD a,#0x01
da a
MOV hours_field,a
clr a
;reset to 1 if it hits 13, skip if hours_field is not 13
MOV R4,hours_field
CJNE R4,#0x13,no_thirteen_here
MOV hours_field,#0x01
no_thirteen_here:
do_not_incriment_hours:
ljmp keep_setting_hours
ret
endless_loop:
endless_loop_part_two:
sjmp endless_loop_part_two
ret
;---------------------------------;
; Set minutes ;
;---------------------------------;
;setting minutes on the time
SET_TIME_MINUTES:
keep_setting_minutes:
;let the user know they are setting minutes
Set_cursor(1,4)
Display_char(#'m')
Set_cursor(1,5)
Display_char(#'i')
;display the time
lcall update_time
lcall display_time
;*****READ INPUTS TO INCRIMENT AND DECREMENT MINUTES*****
jb INCRIMENT_BUTTON,do_not_incriment_minutes
;debounce delay
Wait_Milli_Seconds(#50)
jb INCRIMENT_BUTTON,do_not_incriment_minutes
;wait for button release
diphenhydramine: jnb INCRIMENT_BUTTON, diphenhydramine
;button was pressed, time to incriment
MOV a,minutes_field
ADD a,#0x01
da a
MOV minutes_field,a
clr a
;reset to 0 if it hits 60, skip if minutes_field is not 60
MOV R4,minutes_field
CJNE R4,#0x60,no_sixty_minutes_here
MOV minutes_field,#0x00
no_sixty_minutes_here:
do_not_incriment_minutes:
;look for button press to transition to set am/pm mode
jb SET_TIME_MODE,keep_setting_minutes
;debounce delay
Wait_Milli_Seconds(#50)
jb SET_TIME_MODE,keep_setting_minutes
;wait for button release
atropine: jnb SET_TIME_MODE, atropine
ljmp SET_TIME_AMPM
sjmp keep_setting_minutes
ret
;DIDN'T USE THIS SUBROUTINE BECAUSE WHAT KIND OF CLOCK LETS YOU SET SECONDS LOL
;setting seconds on the time
SET_TIME_SECONDS:
keep_setting_seconds:
;let user know they are setting seconds
Set_cursor(1,4)
Display_char(#'s')
Set_cursor(1,5)
Display_char(#'e')
;*****READ INPUTS TO INCRIMENT AND DECREMENT SECONDS*****
;look for button press to set am/pm
jb SET_TIME_MODE,keep_setting_seconds
;debounce delay
Wait_Milli_Seconds(#50)
jb SET_TIME_MODE,keep_setting_seconds
;wait for button release
scopolamine: jnb SET_TIME_MODE, scopolamine
ljmp SET_TIME_AMPM
sjmp keep_setting_seconds
ret
;---------------------------------;
; AM/PM of time ;
;---------------------------------;
SET_TIME_AMPM:
keep_setting_ampm:
;let user know they are setting AM/PM
Set_Cursor(1,1)
Send_Constant_String(#ampm_string)
;show the time
lcall update_time
lcall display_time
;LOOK FOR BUTTON PRESS TO CHANGE AM TO PM AND PM TO AM
jb INCRIMENT_BUTTON,dont_change_ampm
;debounce delay
Wait_Milli_Seconds(#50)
jb INCRIMENT_BUTTON,dont_change_ampm
;wait for button release
dimenhydrinate: jnb INCRIMENT_BUTTON, dimenhydrinate
;CHANGE AM/PM FLAG HERE
MOV R4,AMPM_flag
cjne R4,#0b0, SWITCH_TO_AM_BOOGALOO
mov AMPM_flag,#0b1
sjmp DONT_SWITCH_TO_AM_BOOGALOO
SWITCH_TO_AM_BOOGALOO:
MOV AMPM_flag,#0b0
DONT_SWITCH_TO_AM_BOOGALOO:
dont_change_ampm:
;look for button press to set alarm time
jb SET_TIME_MODE,keep_setting_ampm
;debounce delay
Wait_Milli_Seconds(#50)
jb SET_TIME_MODE,keep_setting_ampm
;wait for button release
muscarine: jnb SET_TIME_MODE, muscarine
ljmp SET_ALARM_HOURS
sjmp keep_setting_ampm
ret
;---------------------------------;
; Routines for setting alarm time ;
;---------------------------------;
;---------------------------------;
; Set alarm hours ;
;---------------------------------;
;setting hours on the time
SET_ALARM_HOURS:
keep_setting_alarm_hours:
;Let the user know they are setting hours
Set_cursor(2,1)
Send_Constant_String(#set_message)
Set_cursor(2,4)
Display_char(#'h')
Set_cursor(2,5)
Display_char(#'r')
;let the user know they are not setting normal time so overwrite 'AM/PM'
Set_cursor(1,1)
Send_Constant_String(#Initial_message)
;make sure to display the time and alarm time
lcall update_time
lcall display_time
lcall display_alarm_time
;Look for button press to switch to setting alarm minutes
jb SET_TIME_MODE,dont_switch_to_alarm_minutes
;debounce delay
Wait_Milli_Seconds(#50)
jb SET_TIME_MODE,dont_switch_to_alarm_minutes
;wait for button release
benztropine: jnb SET_TIME_MODE, benztropine
ljmp SET_ALARM_MINUTES
dont_switch_to_alarm_minutes:
;*****READ INPUTS TO INCRIMENT AND DECREMENT ALARM HOURS*****
jb INCRIMENT_BUTTON,do_not_incriment_alarm_hours
;debounce delay
Wait_Milli_Seconds(#50)
jb INCRIMENT_BUTTON,do_not_incriment_alarm_hours
;wait for button release
promethazine: jnb INCRIMENT_BUTTON, promethazine
;button was pressed, time to incriment
MOV a,hours_field_alarm
ADD a,#0x01
da a
MOV hours_field_alarm,a
clr a
;reset to 1 if it hits 13, skip if hours_field is not 13
MOV R4,hours_field_alarm
CJNE R4,#0x13,no_thirteen_here_alarm
MOV hours_field_alarm,#0x01
no_thirteen_here_alarm:
do_not_incriment_alarm_hours:
ljmp keep_setting_alarm_hours
ret
;---------------------------------;
; Set alarm minutes ;
;---------------------------------;
SET_ALARM_MINUTES:
keep_setting_alarm_minutes:
;let the user know they are setting minutes
Set_cursor(2,4)
Display_char(#'m')
Set_cursor(2,5)
Display_char(#'i')
;display the time
lcall update_time
lcall display_time
lcall display_alarm_time
;*****READ INPUTS TO INCRIMENT AND DECREMENT MINUTES*****
jb INCRIMENT_BUTTON,do_not_incriment_alarm_minutes
;debounce delay
Wait_Milli_Seconds(#50)
jb INCRIMENT_BUTTON,do_not_incriment_alarm_minutes
;wait for button release
biperiden: jnb INCRIMENT_BUTTON, biperiden
;button was pressed, time to incriment
MOV a,minutes_field_alarm
ADD a,#0x01
da a
MOV minutes_field_alarm,a
clr a
;reset to 0 if it hits 60, skip if minutes_field is not 60
MOV R4,minutes_field_alarm
CJNE R4,#0x60,no_sixty_minutes_here_boogaloo
MOV minutes_field_alarm,#0x00
no_sixty_minutes_here_boogaloo:
do_not_incriment_alarm_minutes:
;look for button press to transition to set am/pm mode
jb SET_TIME_MODE,keep_setting_alarm_minutes
;debounce delay
Wait_Milli_Seconds(#50)
jb SET_TIME_MODE,keep_setting_alarm_minutes
;wait for button release
chlorpheniramine: jnb SET_TIME_MODE, chlorpheniramine
ljmp SET_ALARM_TIME_AMPM
sjmp keep_setting_alarm_minutes
ret
ret
;---------------------------------;
; AM/PM of alarm ;
;---------------------------------;
SET_ALARM_TIME_AMPM:
keep_setting_alarm_ampm:
;let user know they are setting AM/PM
Set_Cursor(2,1)
Send_Constant_String(#ampm_string)
;show the time
lcall update_time
lcall display_time
lcall display_alarm_time
;LOOK FOR BUTTON PRESS TO CHANGE AM TO PM AND PM TO AM
jb INCRIMENT_BUTTON,dont_change_alarm_ampm
;debounce delay
Wait_Milli_Seconds(#50)
jb INCRIMENT_BUTTON,dont_change_alarm_ampm
;wait for button release
doxepin: jnb INCRIMENT_BUTTON, doxepin
;CHANGE ALARM AM/PM FLAG HERE
MOV R4,AMPM_flag_alarm
cjne R4,#0b0, SWITCH_TO_AM_ALARM
mov AMPM_flag_alarm,#0b1
sjmp DONT_SWITCH_TO_AM_ALARM
SWITCH_TO_AM_ALARM:
MOV AMPM_flag_alarm,#0b0
DONT_SWITCH_TO_AM_ALARM:
dont_change_alarm_ampm:
;look for button press to return to main loop
jb SET_TIME_MODE,dont_return_to_loop
;debounce delay
Wait_Milli_Seconds(#50)
jb SET_TIME_MODE,dont_return_to_loop
;wait for button release
dicyclomine: jnb SET_TIME_MODE, dicyclomine
ljmp loop
dont_return_to_loop:
sjmp keep_setting_alarm_ampm
ret
;---------------------------------;
; Alarm active loop ;
;---------------------------------;
alarm_active:
;gotta display the time while the alarm is active
lcall update_time
lcall display_time
Set_cursor(2,11)
Send_Constant_String(#on)
;TOGGLE ALARM ON/OFF INPUT READING
;alarm off sends us back to main loop
jb INCRIMENT_BUTTON,DONT_TOGGLE_ALARM_BOOGALOO
;debounce delay
Wait_Milli_Seconds(#50)
jb INCRIMENT_BUTTON,DONT_TOGGLE_ALARM_BOOGALOO
;wait for button release
flavoxate: jnb INCRIMENT_BUTTON, flavoxate
ljmp loop
DONT_TOGGLE_ALARM_BOOGALOO:
;compare hours minutes and AM/PM to see if alarm should ring
clr c
MOV a,minutes_field
subb a,minutes_field_alarm
jnz dont_ring
clr c
MOV a,hours_field
subb a,hours_field_alarm
jnz dont_ring
clr c
MOV a,AMPM_flag
subb a,AMPM_flag_alarm
jnz dont_ring
;now make it ring
ljmp alarm_ringing
dont_ring:
ljmp alarm_active
ret
;---------------------------------;
; Alarm ringing loop ;
;---------------------------------;
alarm_ringing:
setb speaker_on_flag ;activate the speaker beeping
lcall update_time
lcall display_time
Set_cursor(2,1)
Send_constant_string(#wake_up)
;looking for alarm toggle button to turn ringing off
jb INCRIMENT_BUTTON,DONT_TOGGLE_ALARM_BOOGALOO2
;debounce delay
Wait_Milli_Seconds(#50)
jb INCRIMENT_BUTTON,DONT_TOGGLE_ALARM_BOOGALOO2
;wait for button release
glycopyrrolate: jnb INCRIMENT_BUTTON, glycopyrrolate
ljmp loop
DONT_TOGGLE_ALARM_BOOGALOO2:
ljmp alarm_ringing
ret
;---------------------------------;
; Timer routines ;
;---------------------------------;
SET_TIMER_HOURS:
;keep displaying normal time
lcall update_time
lcall display_time
;display the initial timer values
lcall display_timer_time
Set_cursor(2,1)
Send_constant_string(#TIMER)
;let user know they are setting hours
Set_cursor(2,6)
Display_char(#'h')
Set_cursor(2,7)
Display_char(#'r')
;clear the m from am/pm
Set_cursor(2,16)
Display_char(#' ')
;clear the first colon
Set_cursor(2,8)
Display_char(#' ')
;display first colon
Set_cursor(2,10)
Display_char(#':')
;display second colon
Set_cursor(2,13)
Display_char(#':')
;CHECKING FOR INCRIMENT BUTTON TO INCRIMENT TIMER HOURS
jb INCRIMENT_BUTTON,do_not_incriment_timer_hours
;debounce delay
Wait_Milli_Seconds(#50)
jb INCRIMENT_BUTTON,do_not_incriment_timer_hours
;wait for button release
orphenadrine: jnb INCRIMENT_BUTTON, orphenadrine
;button was pressed, time to incriment
MOV a,hours_field_timer
ADD a,#0x01
da a
MOV hours_field_timer,a
clr a
do_not_incriment_timer_hours:
;LOOKING FOR TIMER TOGGLE TO SWITCH TO SETTING MINUTES
jb TIMER_TOGGLE,DONT_SET_TIMER_MINUTES
;debounce delay
Wait_Milli_Seconds(#50)
jb TIMER_TOGGLE,DONT_SET_TIMER_MINUTES
;wait for button release
oxitropium: jnb TIMER_TOGGLE, oxitropium
ljmp SET_TIMER_MINUTES
DONT_SET_TIMER_MINUTES:
ljmp SET_TIMER_HOURS
ret