-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalarm8051.asm
1024 lines (661 loc) · 23.7 KB
/
alarm8051.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
org 0000H
;defining inputs
hbut equ p1.0;
mbut equ p1.1;
abut equ p1.2;
sbut equ p1.3;
;setting up clock registers
;starting from the first GPR
sec equ 30H
minL equ 32H
minH equ 33H
hrs12L equ 34H
hrs12H equ 35H
hrs24L equ 36H
hrs24H equ 37H
;setting up alarm registers
;will work for both 12hrs and 24hrs systems
amin1L equ 38H
amin1H equ 39H
ahrs1L equ 3AH
ahrs1H equ 3BH
amin2L equ 3CH
amin2H equ 3DH
ahrs2L equ 3EH
ahrs2H equ 3FH
alm1 equ 1AH;
alm2 equ 1BH;
;initial conditions
setb hbut; setting input to active low mode
setb mbut; setting input to active low mode
setb abut; setting input to active low mode
setb sbut; setting input to active low mode
clr alm1;
clr alm2;
mov hrs24H,#00H;
mov hrs24L,#00H;
mov hrs12H,#1H; initiate clock at 12:00
mov hrs12L,#2H;
mov minh,#00H;
mov minL,#00H;
mov amin1L, #11D; initialize alarm registers with impossible values : disable alarm
mov amin1H, #11D;
mov ahrs1L, #11D;
mov ahrs1H, #11D;
mov amin2L, #11D; initialize alarm registers with impossible values : disable alarm
mov amin2H, #11D;
mov ahrs2L, #11D;
mov ahrs2H, #11D;
mov p3,#00H;
mov R2,#00H;
clksetmod:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Josh's part
mov p1,#11111111B; initialize port0 waiting for input.
jnb sbut,clksetmod;
; give enough time to release set button , otherwise the clocksetmode will jump back to 24 hrs loop when brancehd into from mod12/24.
; give neough time for sbut to be released ad mbut to be pressed
jb mbut,addntn1; if not pressed to ground .. add ntn to mins , if bit is pressed "not set prceed to add 1 to mins
w8releasembut:
mov p1,#11111111B; initialize port0 waiting for input.
;noo need for a delay , wont commence unless unpressed
jnb mbut,w8releasembut;
inc minL; 1 min has passed
mov r3,minL;
cjne r3,#10D,display_clksetmod; w8 for 10 mins
mov minL,#00H;
;tenmin:
inc minH; 10 mins have passed
mov r3,minH;
cjne r3,#6D,display_clksetmod; w8 for 60 mins.
mov minH,#00H;
jmp display_clksetmod;
addntn1:
mov p1,#11111111B
;maybe need a delay here
jb hbut,addntn2; inc 24hrsL by 1
w8releasehbut:
mov p1,#11111111B; initialize port0 waiting for input.
;noo need for a delay , wont commence unless unpressed
jnb hbut,w8releasehbut;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;before you add a new hour , check this first
mov r3,hrs12H;
cjne r3,#1D,w8tenhrs_clksetmod; jump if it's not 1x:xx , if it is , check second digit.
mov r3,hrs12L
cjne r3,#2D, w8tenhrs_clksetmod; contiune to clear if its 12:xx other wise , add up to 2 hrs
mov hrs12L,#00H; if its the first hour to be added after 12:00 clear the hour digits first.
mov hrs12H,#00H;
w8tenhrs_clksetmod:
inc hrs12L; 1 hr has passed
;before you add a new hour to 24 registers
mov r3,hrs24H;
cjne r3,#2D,w8twentyhrs_clksetmod; if its 2x:xx check for second hours digit, otherwise , jump to normal
mov r3,hrs24L;
cjne r3,#3D,w8twentyhrs_clksetmod; if its 23:xx commence to clear 24 hrs bytes, otherwise, you can still add up to 3 hours.
mov hrs24L,#00H;
mov hrs24H,#00H;
jmp commence_clksetmod; after 23:59 should turn into 00:00 not 01:00
w8twentyhrs_clksetmod:
inc hrs24L; sync it with the 24h reg
mov r3,hrs24L;
cjne r3, #10D,commence_clksetmod;
mov hrs24L,#00H;
;ten hrs has passed in 24 mode
inc hrs24H; sync it with 24h (10:00) or (20:00)
commence_clksetmod:
mov R3,hrs12L;
CJNE R3,#10D,display_clksetmod;
mov hrs12L,#00H;
inc hrs12H; increase 12hrs high only when 10 hrs has passed (now the time is 10:00)
;jmp display12; finished 10 hrs w8ting for more
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
addntn2:
;dsiplay current 24 registers
display_clksetmod:
MOV DPTR, #seg7values ; load address of lookup table into DPTR
;MOV R0, #0 ; initialize R0 to 1st element in lookup table
MOV R1,#00000001B; set the display to first 7seg
MOV A, hrs24H ; point to appropriate binary code
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value of hrs24H
MOV p2, R1 ; choose appropriate display for that register (first one)
LCALL dispdelay;
MOV R1,#00000010B; set the display to second 7seg
MOV A, hrs24L ; load hrs24L to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value of hrs24L
MOV p2, R1 ; choose appropriate display for that register (second one)
LCALL dispdelay;
MOV R1,#00000100B; set the display to Third 7seg
MOV A, minh ; load minh to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value minH
MOV p2, R1 ; choose appropriate display for that register (third one)
LCALL dispdelay;
MOV R1,#00001000B; set the display to Fourth 7seg
MOV A, minL ; load minL to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value minL
MOV p2, R1 ; choose appropriate display for that register (fourth one)
LCALL dispdelay;
mov p2,#00H; unselect fourth 7seg
mov p1,#11111111B; initialize port0 waiting for input.
;maybe need a delay here
jnb abut,mod24 ; jump to main again if alarm button is pressed
jmp clksetmod; repeat clksetmod until all set
;other than the initial values , user can choose to set the starting time when he turns the clock on.
;uses same dsiplay function of the registers.
;registers are being jumped back to after each display cycle
;a check will be run on hbut and mbut , if any pressed , icreament relevant register by 1;
;jump back to display and check
;when all values are set , commence to main function : mod24:
;check what to do next
;finish clock edit mode by ret to main function
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mod24:
;make sure all buttons are unpressed
mov p1,#11111111B; initialize port0 waiting for input.
jnb hbut,mod24 ; jump back until button is released
jnb sbut,mod24;
jnb abut,mod24;
jnb mbut,mod24;
mov p3,#00000000B;
jnb alm1,troll1;
mov p3,#11111111B;
troll1:
jnb alm2,troll2;
mov p3,#11111111B;
troll2:
;set p3 if alarm sounding register 1 is set : sound alarm 1
;set p3 if alarm sounding register 2 is set : sound alarm 2
lcall delay;
mov p1,#11111111B; check if user wants to stop alarm for toaday
JB mbut,nodisable;
mov amin1L, #11D; initialize alarm registers with impossible values : disable alarm
mov amin1H, #11D;
mov ahrs1L, #11D;
mov ahrs1H, #11D;
mov amin2L, #11D; initialize alarm registers with impossible values : disable alarm
mov amin2H, #11D;
mov ahrs2L, #11D;
mov ahrs2H, #11D;
mov p3,#00000000B; mute the buzzer
nodisable:
clr alm1;
clr alm2;
;set p1
;jnb sbut,mode12;
cjne r2,#60D,disp_jmp1;
sjmp jumpover;
disp_jmp1:
jmp display24;
jumpover:
mov R2,#00H;
;clock: ; another code to set the value of the clock registers
;onesec:
setb P2.1 ; choose the second 7seg
;clr P0.7; blink the decimal point
MOV p0,#01111111B; decimal point blinking cure
lcall dispdelay;
inc sec;
clr p2.1; un-choose second 7seg
;setb P0.7; clear decimal point
mov r3,sec;
cjne r3, #60D,disp_jmp2; ; w8 for 60 secs
sjmp jumpover1;
disp_jmp2:
jmp display24
Jumpover1:
mov sec,#00H ;
;onemin:
inc minL; 1 min has passed
mov r3,minL;
cjne r3,#10D,display24; w8 for 10 mins
mov minL,#00H;
;tenmin:
inc minH; 10 mins have passed
mov r3,minH;
cjne r3,#6D,display24; w8 for 60 mins.
mov minH,#00H;
;hourly chime
mov p3,#11111111B;
;setb P3.1; turn buzzer on
lcall rmvfing; sound the buzz for 2 ms
;CLR P3.1; stop the hourly based buzz
mov P3,#00000000B
;before you add a new hour , check this first
mov r3,hrs12H;
cjne r3,#1D,w8tenhrs24; jump if it's not 1x:xx , if it is , check second digit.
mov r3,hrs12L
cjne r3,#2D, w8tenhrs24; contiune to clear if its 12:xx other wise , add up to 2 hrs
mov hrs12L,#00H; if its the first hour to be added after 12:00 clear the hour digits first.
mov hrs12H,#00H;
w8tenhrs24:
inc hrs12L; 1 hr has passed
;before you add a new hour to 24 registers
mov r3,hrs24H;
cjne r3,#2D,w8twentyhrs24; if its 2x:xx check for second hours digit, otherwise , jump to normal
mov r3,hrs24L;
cjne r3,#3D,w8twentyhrs24; if its 23:xx commence to clear 24 hrs bytes, otherwise, you can still add up to 3 hours.
mov hrs24L,#00H;
mov hrs24H,#00H;
jmp commence24; after 23:59 should turn into 00:00 not 01:00
w8twentyhrs24:
inc hrs24L; sync it with the 24h reg
mov r3,hrs24L;
cjne r3, #10D,commence24;
mov hrs24L,#00H;
;ten hrs has passed in 24 mode
inc hrs24H; sync it with 24h (10:00) or (20:00)
commence24:
mov R3,hrs12L;
CJNE R3,#10D,display24;
mov hrs12L,#00H;
inc hrs12H; increase 12hrs high only when 10 hrs has passed (now the time is 10:00)
jmp display24; finished 10 hrs w8ting for more
display24:
;compare alarm registers with clock registers :
Checkalm:
clr alm1; turn alarm off after 1 min
clr alm2;
MOV A ,amin1L
CJNE A,minL,NOALM1
MOV A ,amin1H
CJNE A,minH,NOALM1
MOV A, ahrs1L
CJNE A,hrs24L ,NOALM1
MOV A,ahrs1H
CJNE A,hrs24H,NOALM1
setb alm1; turn alarm 1 on if current time registers are equal to set alarm registers
;;;;;
NOALM1:
MOV A ,amin2L
CJNE A,minL,NOALM2
MOV A ,amin2H
CJNE A,minH,NOALM2
MOV A,ahrs2L
CJNE A,hrs24L ,NOALM2
MOV A,ahrs2H
CJNE A,hrs24H,NOALM2
setb alm2;
NOALM2:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOV DPTR, #seg7values ; load address of lookup table into DPTR
;MOV R0, #0 ; initialize R0 to 1st element in lookup table
MOV R1,#00000001B; set the display to first 7seg
MOV A, hrs24H ; point to appropriate binary code
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value of hrs24H
MOV p2, R1 ; choose appropriate display for that register (first one)
LCALL dispdelay;
MOV R1,#00000010B; set the display to second 7seg
MOV A, hrs24L ; load hrs24L to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value of hrs24L
MOV p2, R1 ; choose appropriate display for that register (second one)
LCALL dispdelay;
MOV R1,#00000100B; set the display to Third 7seg
MOV A, minh ; load minh to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value minH
MOV p2, R1 ; choose appropriate display for that register (third one)
LCALL dispdelay;
MOV R1,#00001000B; set the display to Fourth 7seg
MOV A, minL ; load minL to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value minL
MOV p2, R1 ; choose appropriate display for that register (fourth one)
LCALL dispdelay;
mov p2,#00H; unselect fourth 7seg
mov p1,#11111111B; initialize port0 waiting for input.
jnb hbut,mod12_jmp ; jump to 12hrs mode if hrs push button is pressed (if p1.0 is not set anymore)
jnb sbut,clksetmod_jmp24; jnb only got relative addressing, therfore we jump for another close instruciton that can perform absoulute jump
jnb abut,alrsetmod_jmp24;
jmp mod24 ; repeat mod24 loop
mod12_jmp:
jmp mod12;
clksetmod_jmp24:
jmp clksetmod;
alrsetmod_jmp24:
mov amin1L, #00H; load possible initial values for alarm registers first :enable alarm
mov amin1H, #00H;
mov ahrs1L, #00H;
mov ahrs1H, #00H;
mov amin2L, #00H;
mov amin2H, #00H;
mov ahrs2L, #00H;
mov ahrs2H, #00H;
jmp alrsetmod;
mod12:
;make sure all buttons are unpressed
mov p1,#11111111B; initialize port0 waiting for input.
jnb hbut,mod12 ; jump back until button is released
jnb sbut,mod12;
jnb abut,mod12;
jnb mbut,mod12;
lcall delay;
cjne r2,#100D,display12;
mov R2,#00H;
;clock ; another code to set the value of the clock registers
;onesec:
setb P2.1 ; choose the second 7seg
;clr P0.7; blink the decimal point
MOV p0,#01111111B; decimal point blinking cure
lcall dispdelay;
inc sec;
clr p2.1; un-choose second 7seg
;setb P0.7; clear decimal point
mov r3,sec;
cjne r3, #60D, display12 ; w8 for 60 secs
mov sec,#00H ;
;onemin:
inc minL; 1 min has passed
mov r3,minL;
cjne r3,#10D,display12; w8 for 10 mins
mov minL,#00H;
;tenmin:
inc minH; 10 mins have passed
mov r3,minH;
cjne r3,#6D,display12; w8 for 60 mins.
mov minH,#00H;
;hourly chime
mov p3,#11111111B;
;setb P3.1; turn buzzer on
lcall rmvfing; sound the buzz for 2 ms
;CLR P3.1; stop the hourly based buzz
mov p3,#00000000B;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;before you add a new hour , check this first
mov r3,hrs12H;
cjne r3,#1D,w8tenhrs12; jump if it's not 1x:xx , if it is , check second digit.
mov r3,hrs12L
cjne r3,#2D, w8tenhrs12; contiune to clear if its 12:xx other wise , add up to 2 hrs
mov hrs12L,#00H; if its the first hour to be added after 12:00 clear the hour digits first.
mov hrs12H,#00H;
w8tenhrs12:
inc hrs12L; 1 hr has passed
;before you add a new hour to 24 registers
mov r3,hrs24H;
cjne r3,#2D,w8twentyhrs12; if its 2x:xx check for second hours digit, otherwise , jump to normal
mov r3,hrs24L;
cjne r3,#3D,w8twentyhrs12; if its 23:xx commence to clear 24 hrs bytes, otherwise, you can still add up to 3 hours.
mov hrs24L,#00H;
mov hrs24H,#00H;
jmp commence12; after 23:59 should turn into 00:00 not 01:00
w8twentyhrs12:
inc hrs24L; sync it with the 24h reg
mov r3,hrs24L;
cjne r3, #10D,commence12;
mov hrs24L,#00H;
;ten hrs has passed in 24 mode
inc hrs24H; sync it with 24h (10:00) or (20:00)
commence12:
mov R3,hrs12L;
CJNE R3,#10D,display12;
mov hrs12L,#00H;
inc hrs12H; increase 12hrs high only when 10 hrs has passed (now the time is 10:00)
;jmp display12; finished 10 hrs w8ting for more
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
display12:
MOV DPTR, #seg7values ; load address of lookup table into DPTR
;MOV R0, #0 ; initialize R0 to 1st element in lookup table
MOV R1,#00000001B; set the display to first 7seg
MOV A, hrs12h ; point to appropriate binary code
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value of hrs24H
MOV p2, R1 ; choose appropriate display for that register (first one)
LCALL dispdelay;
MOV R1,#00000010B; set the display to second 7seg
MOV A, hrs12L ; load hrs12L to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value of hrs24L
MOV p2, R1 ; choose appropriate display for that register (second one)
LCALL dispdelay;
MOV R1,#00000100B; set the display to Third 7seg
MOV A, minh ; load minh to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value minH
MOV p2, R1 ; choose appropriate display for that register (third one)
LCALL dispdelay;
MOV R1,#00001000B; set the display to Fourth 7seg
MOV A, minL ; load minL to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value minL
MOV p2, R1 ; choose appropriate display for that register (fourth one)
LCALL dispdelay;
mov p2,#00H; unselect fourth 7seg
mov p1,#11111111B; initialize port0 waiting for input.
jnb hbut,mod24_jmp; jump to 24hrs mode if hrs push button is pressed (if p1.0 is not set anymore)
jnb sbut,clksetmod_jmp12; nb only got relative addressing, therfore we jump for another close instruciton that can perform absoulute jump
jnb abut,alrsetmod_jmp12;
jmp mod12 ; repeat mod12 loop
mod24_jmp:
jmp mod24;
clksetmod_jmp12:
jmp clksetmod;
alrsetmod_jmp12:
jmp alrsetmod;
; forget about 12 hours mode , we will develope the alarm with 24 mode only ;; once 24 loop is ready .. we copy it to 12 hrs.
;focus on interacting ONLY WITH 24MOD.
alrsetmod:
mov p1,#11111111B; initialize port0 waiting for input.
jnb abut,alrsetmod;
; give enough time to release set button , otherwise the clocksetmode will jump back to 24 hrs loop when brancehd into from mod12/24.
; give neough time for sbut to be released ad mbut to be pressed
jb mbut,addntn1_alr1set; if not pressed to ground .. add ntn to mins , if bit is pressed "not set prceed to add 1 to mins
w8releasembut_alr1set:
mov p1,#11111111B; initialize port0 waiting for input.
;noo need for a delay , wont commence unless unpressed
jnb mbut,w8releasembut_alr1set;
inc amin1L; 1 min has passed
mov r3,amin1L;
cjne r3,#10D,display_alr1set; w8 for 10 mins
mov amin1L,#00H;
;tenmin:
inc amin1H; 10 mins have passed
mov r3,amin1H;
cjne r3,#6D,display_alr1set; w8 for 60 mins.
mov amin1H,#00H;
jmp display_alr1set;
addntn1_alr1set:
mov p1,#11111111B
;maybe need a delay here
jb hbut,addntn2_alr1set; inc 24hrsL by 1
w8releasehbut_alr1set:
mov p1,#11111111B; initialize port0 waiting for input.
;noo need for a delay , wont commence unless unpressed
jnb hbut,w8releasehbut_alr1set;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;before you add a new hour to 24 registers
mov r3,ahrs1H;
cjne r3,#2D,w8twentyhrs_alr1set; if its 2x:xx check for second hours digit, otherwise , jump to normal
mov r3,ahrs1L;
cjne r3,#3D,w8twentyhrs_alr1set; if its 23:xx commence to clear 24 hrs bytes, otherwise, you can still add up to 3 hours.
mov ahrs1L,#00H;
mov ahrs1H,#00H;
jmp commence_alr1set; after 23:59 should turn into 00:00 not 01:00
w8twentyhrs_alr1set:
inc ahrs1L; sync it with the 24h reg
mov r3,ahrs1L;
cjne r3, #10D,commence_alr1set;
mov ahrs1L,#00H;
;ten hrs has passed in 24 mode
inc ahrs1H; sync it with 24h (10:00) or (20:00)
commence_alr1set:
;jmp display12; finished 10 hrs w8ting for more
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
addntn2_alr1set:
;dsiplay current 24 registers
display_alr1set:
MOV DPTR, #seg7values ; load address of lookup table into DPTR
;MOV R0, #0 ; initialize R0 to 1st element in lookup table
MOV R1,#00000001B; set the display to first 7seg
MOV A, ahrs1H ; point to appropriate binary code
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value of hrs24H
MOV p2, R1 ; choose appropriate display for that register (first one)
LCALL dispdelay;
MOV R1,#00000010B; set the display to second 7seg
MOV A, ahrs1L ; load hrs24L to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value of hrs24L
MOV p2, R1 ; choose appropriate display for that register (second one)
LCALL dispdelay;
MOV R1,#00000100B; set the display to Third 7seg
MOV A, amin1h ; load minh to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value minH
MOV p2, R1 ; choose appropriate display for that register (third one)
LCALL dispdelay;
MOV R1,#00001000B; set the display to Fourth 7seg
MOV A, amin1L ; load minL to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value minL
MOV p2, R1 ; choose appropriate display for that register (fourth one)
LCALL dispdelay;
mov p2,#00H; unselect fourth 7seg
mov p1,#11111111B; initialize port0 waiting for input.
;maybe need a delay here
jnb sbut,alrsetmod2 ; jump to main again if alarm button is pressed
jmp alrsetmod; repeat clksetmod until all set
;finish clock edit mode by ret to main function
alrsetmod2:
mov p1,#11111111B; initialize port0 waiting for input.
jnb sbut,alrsetmod2; w8 for set button to be released
; give enough time to release set button , otherwise the clocksetmode will jump back to 24 hrs loop when brancehd into from mod12/24.
; give neough time for sbut to be released ad mbut to be pressed
jb mbut,addntn1_alr2set; if not pressed to ground .. add ntn to mins , if bit is pressed "not set prceed to add 1 to mins
w8releasembut_alr2set:
mov p1,#11111111B; initialize port0 waiting for input.
;noo need for a delay , wont commence unless unpressed
jnb mbut,w8releasembut_alr2set;
inc amin2L; 1 min has passed
mov r3,amin2L;
cjne r3,#10D,display_alr2set; w8 for 10 mins
mov amin2L,#00H;
;tenmin:
inc amin2H; 10 mins have passed
mov r3,amin2H;
cjne r3,#6D,display_alr2set; w8 for 60 mins.
mov amin2H,#00H;
jmp display_alr2set;
addntn1_alr2set:
mov p1,#11111111B
;maybe need a delay here
jb hbut,addntn2_alr2set; inc 24hrsL by 1
w8releasehbut_alr2set:
mov p1,#11111111B; initialize port0 waiting for input.
;noo need for a delay , wont commence unless unpressed
jnb hbut,w8releasehbut_alr2set;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;before you add a new hour to 24 registers
mov r3,ahrs2H;
cjne r3,#2D,w8twentyhrs_alr2set; if its 2x:xx check for second hours digit, otherwise , jump to normal
mov r3,ahrs2L;
cjne r3,#3D,w8twentyhrs_alr2set; if its 23:xx commence to clear 24 hrs bytes, otherwise, you can still add up to 3 hours.
mov ahrs2L,#00H;
mov ahrs2H,#00H;
jmp commence_alr2set; after 23:59 should turn into 00:00 not 01:00
w8twentyhrs_alr2set:
inc ahrs2L; sync it with the 24h reg
mov r3,ahrs2L;
cjne r3, #10D,commence_alr2set;
mov ahrs2L,#00H;
;ten hrs has passed in 24 mode
inc ahrs2H; sync it with 24h (10:00) or (20:00)
commence_alr2set:
;jmp display12; finished 10 hrs w8ting for more
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
addntn2_alr2set:
;dsiplay current 24 registers
display_alr2set:
MOV DPTR, #seg7values ; load address of lookup table into DPTR
;MOV R0, #0 ; initialize R0 to 1st element in lookup table
MOV R1,#00000001B; set the display to first 7seg
MOV A, ahrs2H ; point to appropriate binary code
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value of hrs24H
MOV p2, R1 ; choose appropriate display for that register (first one)
LCALL dispdelay;
MOV R1,#00000010B; set the display to second 7seg
MOV A, ahrs2L ; load hrs24L to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value of hrs24L
MOV p2, R1 ; choose appropriate display for that register (second one)
LCALL dispdelay;
MOV R1,#00000100B; set the display to Third 7seg
MOV A, amin2h ; load minh to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value minH
MOV p2, R1 ; choose appropriate display for that register (third one)
LCALL dispdelay;
MOV R1,#00001000B; set the display to Fourth 7seg
MOV A, amin2L ; load minL to accumulator
MOVC A, @A+DPTR ; load current byte pointed by (A+DPTR) to Acc
MOV p0, A ; display value minL
MOV p2, R1 ; choose appropriate display for that register (fourth one)
LCALL dispdelay;
mov p2,#00H; unselect fourth 7seg
mov p1,#11111111B; initialize port0 waiting for input.
;maybe need a delay here
jnb abut,mod24_AJMP ; jump to main again if alarm button is pressed
jmp alrsetmod2; repeat clksetmod until all set
mod24_AJMP:
JMP mod24; finish alarm registers settings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; em+ain+faiz
;all buttons should be released;
;mov p1,#11111111B; initialize port0 waiting for input.
;jnb hbut,alrsetmod ; jump back until button is released
;jnb sbut,alrsetmod;
;jnb abut,alrsetmod;
;jnb mbut,alrsetmod;
;initial alarm registers will be set to IMPOSSIBLE values; means that the alarm will be disabled by default.
;will include same clock loop ,
;but display current alarm registers which can be manipulated using hbut, mbut.
;once all set, jump back to main function (ret)
;if "abut" is pressed again any time before setting all of the values for alarm , LOAD IMPOSSIBLE VALUE , to disable alarm and exit function.
;once this function is done , clock and alarm registers comparison should be implemented within main clock loops
;when values are met in main loop , alrtrigmod will be jumped into.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; alrtrigmod: em+ain+faiz
;turn beep on , turn vibrate on , return.
;auto stop after 1 min, manual stop, snooze will be implemented within the main function.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Delays
delay:
MOV TMOD, #01H ; timer 0, mode 1
MOV TL0, #44H ; TL0 = #ffH , to make timer flow each 1 us
MOV TH0, #0f8H ; TH0 = #ffH to make timer flow each 1 us
SETB TR0 ; start timer 0
JNB TF0, $ ; stay until timer rolls over
CLR TR0 ; stop timer 0
CLR TF0 ; clear timer flag 0
inc r2;
ret
dispdelay: ;6050 us
mov r4,#5
Repeat:
mov r5,#200
Again:
nop
nop
djnz r5,Again
djnz r4,Repeat
ret
rmvfing: ;521224 us