-
Notifications
You must be signed in to change notification settings - Fork 0
/
ledstrip.asm
1767 lines (1525 loc) · 41.7 KB
/
ledstrip.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
$NOLIST
$nomod51
$INCLUDE (c:/reg832.pdf)
$LIST
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; Main Program
;
; This Program will loop over the subsytems (see below)
; 1) Get the user input and save this
; 2) Check if we need to update the led's
; 3) Update the led's
;
; We use the subsystems: 'user' and 'led_api'
;
; SETTINGS:
;
; Pleas set the wright options for compiling
DIL_ADuC832 SET 1 ; Set this if we use the DIL variant of the ADuC832
; If DIL is set buzzer on port_map.2
; else Buzzer on buzzer jumper
;
LCD SET 0 ; Set this if we use LCD and Buttons for comunication
USB SET 1 ; Set this if we use USB for comunication
;
; YOU CAN CHANGE THE PORT IN OPTION port_map
;
;**********************************************************************************************
;**********************************************************************************************
; Memory map:
; Update input flag: Every second
; 000h
; Update LED flag; Every minute
; 001h
; Can we use the buzzer
; 002h
; Are we using the usb
; 003h
; Are we in the config menu of the usb
; 004h
; Examentime to go in min:
; 030h
; Value of how many times timer 1 has interupted
; 032h
; Value of how many times timer 0 has interupted
; 033h
; Seconds timer
; 034h
; Total examen time:
; 035h
; Total alarm time
; 036h
; Led data:
; 040h per led 4 registers * led count
; ex: led1: 040h(gl) 041h(b) 042h(g) 043h(r)
; ex: led2: 044h(gl) 045h(b) 046h(g) 047h(r)
;**********************************************************************************************
stack_init equ 0b9h ; LED data will go until 0b7 for 30 led's
led_count equ 030d ; Give the number of APA102 led's in the strip max 48 for this 8 bit driver
port_map equ p3 ; Give the port we need to map
dataport equ 1
clkport equ 2
buzzerport equ 0
;Defenition of the memory map:
input_flag bit 000h
LED_flag bit 001h
Buz_flag bit 002h
USB_flag bit 003h
USB_flag_config bit 004h
examen_time equ 030h
timer1_count equ 032h
timer0_count equ 033h
sec_timer equ 034h
total_examen_time equ 035h
total_alarm_time equ 036h
LED_data_offset equ 040h
org 0000h
ljmp main_init
org 000Bh ; Interupt timer 0
ljmp user_alarm_timer_intr
org 001Bh ; Interupt timer 1
ljmp buzzer_intr ; Buzzer music
if USB=1
org 023h ; user_input_USB_intr interupt
ljmp user_input_USB_intr
endif
; Init of the main program
main_init: mov sp,#stack_init
mov pllcon,#000h ; Clk on 16MH
lcall led_api_init ; Init the led's
lcall APA102_test_led_strip ; APA102_test programe of led's
lcall user_init ; Init the user interface
lcall buzzer_music_init ; Init the buzzer
lcall buzzer_music
sjmp main_loop ; Loop
; The main loop
main_loop:
lcall user_input ; Get the user input and save this
jnb LED_flag,main_loop ; Check if we need to update the led's
lcall user_alarm ; Calculates the led data and set the buzzer on and off if needed
lcall led_api_out ; Sends out the calculated data
clr LED_flag
sjmp main_loop
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; class: user
; User function gets the user input and calculates the wright values for led_api
;
; Necessary:
; CLK on 16 Mhz
;
; External functions:
; Doesn't break acc
; Interupts allowed
;
; user_init: Makes the user USB and LCD interface ready
; user_init_LCD: Makes the user LCD interface ready
; user_init_USB: Makes the user USB interface ready
; user_input: Stores the user input from USB and LCD
; user_input_LCD: Stores the user input from LCD
; user_input_USB: Stores the user input from USB
; user_input_USB_d_out: Print a decimal out to the terminal
; user_input_USB_intr: Gets the user input and stores this
; user_input_USB_INBYTE: Gets from the terminal a number in format xxx (000-255) and stores this in a
; user_alarm_init: Init of the user alarm
; user_alarm: Sends the alarm to the user
; user_alarm_timer_init: Decrease every minute the registers 030h and 031h. Makes use of timer 0
; user_alarm_timer_intr: The interupt routine for timer 0
;
; Internal functions:
;
; user_input:
; user_input_exit
;
; user_input_LCD:
; user_input_LCD_loop_1
; user_input_LCD_loop_2
; user_input_LCD_exit
; user_input_LCD_no_button
; user_input_LCD_d_out
; user_input_LCD_text_0
; user_input_LCD_text_1
; user_input_LCD_text_2
;
; user_input_USB:
; user_input_USB_exit
; user_input_USB_text_0
; user_input_USB_text_1
; user_input_USB_text_2
; user_input_USB_text_3
;
; user_input_USB_intr:
; user_input_USB_intr_e
; user_input_USB_intr_a
; user_input_USB_intr_exit
; user_input_USB_intr_text_0
; user_input_USB_intr_text_1
; user_input_USB_intr_text_2
; user_input_USB_intr_text_3
; user_input_USB_intr_text_4
;
; user_input_USB_INBYTE:
; user_input_USB_INBYTE_10
; user_input_USB_INBYTE_0
; user_input_USB_INBYTE_100
; user_input_USB_INBYTE_exit
;
; user_alarm:
; user_alarm_time_0
; user_alarm_time_exit
; user_alarm_text_0
; user_alarm_calc_led_n
; user_alarm_calc_led_a
; user_alarm_data
; user_alarm_data_loop
; user_alarm_data_mem
; user_alarm_data_clr
; user_alarm_data_clr_loop
;
; user_alarm_timer_intr:
; user_alarm_timer_intr_min
; user_alarm_timer_intr_min_2
; user_alarm_timer_intr_exit
; user_alarm_timer_intr_reload
;
;**********************************************************************************************
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; function: user_init
; Makes the user interface ready
;
; Input: none
;
; Output: clears the screen
;
;**********************************************************************************************
user_init:
if LCD = 1
lcall user_init_LCD
endif
if USB = 1
lcall user_init_USB
endif
mov examen_time,#099
mov total_examen_time,#099
mov total_alarm_time,#030
lcall user_alarm_init ; Init the alarms
ret
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; function: user_input
; Gets the user input and stores this
;
; Input: From buttons and DIP-switchs or from USB
; SEE SETTINGS
;
; Output: Text to screen
;
; Internal functions:
; user_input_exit
;**********************************************************************************************
user_input:
jnb input_flag,user_input_exit ; update only 1 time per sec
clr input_flag
if LCD = 1
lcall user_input_LCD
endif
if USB = 1
lcall user_input_USB
endif
user_input_exit:
ret
;***************
;* LCD SECTION *
;***************
if LCD = 1
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; function: user_init_LCD
; Makes the user LCD interface ready
;
; Input: none
;
; Output: clears the screen
;
;**********************************************************************************************
user_init_LCD:
push acc
setb Buz_flag ; Mute the buzzer
lcall initlcd ; lcd init
lcall lcdlighton ; lcdlight on
mov a,#00ch ; clear screen and cursor on posistion 00
lcall outcharlcd
mov a,#013h ; cursor off
lcall outcharlcd
clr Buz_flag
mov examen_time,#099
mov total_examen_time,#099
mov total_alarm_time,#030
pop acc
ret
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; function: user_input_LCD
; Gets the user input and stores this
;
; Input: From buttons and DIP-switchs
; SEE SETTINGS
;
; Output: Text to screen
;
; Internal functions:
; user_input_LCD_loop_1
; user_input_LCD_loop_2
; user_input_LCD_no_button
; user_input_LCD_d_out
; user_input_LCD_text_0
; user_input_LCD_text_1
; user_input_LCD_text_2
;
;**********************************************************************************************
user_input_LCD:
push acc
push psw
setb psw.3
setb Buz_flag ; Mute the buzzer
mov a,#00ch ; Clear screen and move cursor to 00
lcall outcharlcd
mov a,#013h ; Cursor off
lcall outcharlcd
mov dptr,#user_input_LCD_text_0 ; text_0 out to screen
lcall outmsgalcd
mov b,examen_time
lcall user_input_LCD_d_out
clr Buz_flag
mov a,p3 ; Get button (p3.7 - p3.4)
cpl a ; Inversion for active high
swap a ; Put data a in a.4 until aclkport
anl a,#001h ; Clear upper 7 bits
jz user_input_LCD_no_button ; button p3.4 not pressed so no user input
clr tr0 ; Stop the timer0
setb Buz_flag ; Mute the buzzer
mov a,#00ch ; Clear screen and move cursor to 00
lcall outcharlcd
mov a,#013h ; Cursor off
lcall outcharlcd
mov dptr,#user_input_LCD_text_1 ; text_1 out to screen
lcall outmsgalcd
user_input_LCD_loop_1:
mov b,p0
mov examen_time,b ; Get examen time
mov total_examen_time,b
lcall user_input_LCD_d_out
mov a,p3 ; Get button (p3.7 - p3.4)
cpl a ; Inversion for active high
swap a ; Put data a in a.4 until aclkport
anl a,#002h ; Clear upper 6 bits and bit 0
jz user_input_LCD_loop_1 ; button p3.5 not pressed so no user input
mov a,#00ch ; Clear screen and move cursor to 00
lcall outcharlcd
mov a,#013h ; Cursor off
lcall outcharlcd
mov dptr,#user_input_LCD_text_2 ; text_1 out to screen
lcall outmsgalcd
user_input_LCD_loop_2:
mov b,p0 ; Get alert time
mov total_alarm_time,b
lcall user_input_LCD_d_out
mov a,p3 ; Get button (p3.7 - p3.4)
cpl a ; Inversion for active high
swap a ; Put data a in a.4 until aclkport
anl a,#004h ; Clear upper 4 bits and lower 2 bits
jz user_input_LCD_loop_2 ; button p3.4 not pressed so no user input
clr tr0
mov tl0,#000h
mov th0,#000h
setb tr0
clr Buz_flag
setb LED_flag ; Update the led's
sjmp user_input_LCD_exit
; Exit the user_input_LCD function
user_input_LCD_exit:
pop psw
pop acc
ret
; No buttons pressed so stop
user_input_LCD_no_button:
sjmp user_input_LCD_exit
; Print a decimal out on second line of screen
; decimal is send trough by b
user_input_LCD_d_out:
push acc
mov a,#040h ; Cursor on second line first posistion
orl a,#80h
lcall outcharlcd
mov a,b ; Put value of p0 in acc
mov b,#100
div ab ; Divide a by 100
lcall outniblcd ; 100 out
mov a,#041h ; Cursor on second line second posistion
orl a,#80h
lcall outcharlcd
mov a,b ; Put value of p0 in acc
mov b,#10
div ab ; Divide a by 100
lcall outniblcd ; 10 out
mov a,#042h ; Cursor on second line third posistion
orl a,#80h
lcall outcharlcd
mov a,b
lcall outniblcd ; 1 out
pop acc
ret
user_input_LCD_text_0:
db 'Tijd te gaan:'
db 0C0h ; Next line
db ' min. Druk 1'
db 000h ; End
user_input_LCD_text_1:
db 'Geef examentijd:'
db 0C0h ; Next line
db ' min. Druk 2'
db 000h ; End
user_input_LCD_text_2:
db 'Geef alarmtijd:'
db 0C0h ; Next line
db ' min. Druk 3'
db 000h ; End
endif
;***************
;* USB Section *
;***************
if USB = 1
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; function: user_init_USB
; Makes the user USB interface ready
;
; Input: none
;
; Output: clears the screen
;
;**********************************************************************************************
user_init_USB:
lcall initsio ; Init of the user_input_USB_intr
clr USB_flag
clr USB_flag_config
setb es
setb ea
ret
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; function: user_input_USB
; Prints the time of to the terminal
;
; Input: From none
;
; Output: Text to screen
;
; Internal functions:
; user_input_USB_exit
; user_input_USB_text_0
; user_input_USB_text_1
; user_input_USB_text_2
; user_input_USB_text_3
;
;**********************************************************************************************
user_input_USB:
push acc
jb USB_flag,user_input_USB_exit
jb USB_flag_config,user_input_USB_exit
setb USB_flag
mov dptr,#user_input_USB_text_0
lcall outmsga
mov a,examen_time
lcall user_input_USB_d_out
mov dptr,#user_input_USB_text_1
lcall outmsga
mov a,total_examen_time
lcall user_input_USB_d_out
mov dptr,#user_input_USB_text_2
lcall outmsga
mov a,total_alarm_time
lcall user_input_USB_d_out
mov dptr,#user_input_USB_text_3
lcall outmsga
clr USB_flag
user_input_USB_exit:
pop acc
ret
user_input_USB_text_0:
db 00ah ; Clear terminal
db 'Druk op een toets om de tijd in te stellen.'
db 00dh ; Next line
db 'Nog: '
db 000h ; End
user_input_USB_text_1:
db ' minuten te gaan van de '
db 000h
user_input_USB_text_2:
db ' minuten. Alarm gaat af de laatste: '
db 000h
user_input_USB_text_3:
db ' minuten.'
db 000h
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; function: user_input_USB_d_out
; Print a decimal out to the terminal
;
; Input: a
;
; Output: decimal to screen
;
;**********************************************************************************************
user_input_USB_d_out:
push acc
mov b,#100
div ab ; Divide a by 100
lcall outnib ; 100 out
mov a,b ; Put value of p0 in acc
mov b,#10
div ab ; Divide a by 100
lcall outnib ; 10 out
mov a,b
lcall outnib ; 1 out
pop acc
ret
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; function: user_input_USB_intr
; Gets the user input and stores this
;
; Input: From terminal
;
; Output: Text to screen
;
; Internal functions:
; user_input_USB_intr_e
; user_input_USB_intr_a
; user_input_USB_intr_exit
; user_input_USB_intr_text_0
; user_input_USB_intr_text_1
; user_input_USB_intr_text_2
; user_input_USB_intr_text_3
; user_input_USB_intr_text_4
;
;**********************************************************************************************
user_input_USB_intr:
push acc
push psw
clr ti
clr ri
jb USB_flag,user_input_USB_intr_exit ; Check if we are transmiting, if yes we end the interupt routine
setb USB_flag_config
setb USB_flag
user_input_USB_intr_e:
clr c
mov dptr,#user_input_USB_intr_text_0
lcall outmsga
lcall user_input_USB_INBYTE
jc user_input_USB_intr_e ; Error restart
mov examen_time,a
mov total_examen_time,a
mov dptr,#user_input_USB_intr_text_1
lcall outmsga
lcall user_input_USB_d_out
mov dptr,#user_input_USB_intr_text_2
lcall outmsga
user_input_USB_intr_a:
clr c
mov dptr,#user_input_USB_intr_text_3
lcall outmsga
lcall user_input_USB_INBYTE
jc user_input_USB_intr_a ; Error restart
mov total_alarm_time,a
mov dptr,#user_input_USB_intr_text_1
lcall outmsga
lcall user_input_USB_d_out
mov dptr,#user_input_USB_intr_text_4
lcall outmsga
clr USB_flag
clr USB_flag_config
clr tr0
mov tl0,#000h
mov th0,#000h
setb tr0
user_input_USB_intr_exit:
pop psw
pop acc
reti
user_input_USB_intr_text_0:
db 00ah ; Clear terminal
db 'Welkom in het configuratie menu!'
db 00ah ; Next line
db 'Geef de duur van het examen in (max 255): '
db 00ah,000h ; End
user_input_USB_intr_text_1:
db 00ah
db 'We hebben '
db 000h
user_input_USB_intr_text_2:
db ' minuten ingesteld als de examen tijd.'
db 000h
user_input_USB_intr_text_3:
db 00ah
db 'Geef nu het alarm tijd (max 255): '
db 000h
user_input_USB_intr_text_4:
db ' minuten ingesteld als de alarm tijd.'
db 00ah
db 'Einde van configuratie menu.'
db 00dh,000h
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; function: user_input_USB_INBYTE
; Gets from the terminal a number in format xxx (000-255) and stores this in a
; binair number in a
;
; Input: text form terminal
;
; Output: cary if error
; the number a
;
; Internal functions:
; user_input_USB_INBYTE_10
; user_input_USB_INBYTE_0
; user_input_USB_INBYTE_100
; user_input_USB_INBYTE_exit
;
;**********************************************************************************************
user_input_USB_INBYTE:
push b
lcall INBUFA ; Wait on the user input
dec r0 ; Pointer to the first number
mov a,@r0 ; Put het 1 in the acc
lcall LOWUPTR ; Change to UPPERCASE
lcall ASCBINTRANS ; Change ascii to a binair number
jc user_input_USB_INBYTE_exit ;ERROR
mov b,a ; Save number in B
dec r0 ; Pointer to the second number
mov a,@r0 ; Put het 10 in the acc
lcall LOWUPTR ; Change to UPPERCASE
lcall ASCBINTRANS ; Change ascii to a binair number
jc user_input_USB_INBYTE_exit ;ERROR
jz user_input_USB_INBYTE_0 ; We don't need to add
mov r1,a
mov a,b
user_input_USB_INBYTE_10:
add a,#10
djnz r1,user_input_USB_INBYTE_10
mov b,a
user_input_USB_INBYTE_0:
dec r0
mov a,@r0 ; Put het 10 in the acc
lcall LOWUPTR ; Change to UPPERCASE
lcall ASCBINTRANS ; Change ascii to a binair number
jc user_input_USB_INBYTE_exit ;ERROR
jz user_input_USB_INBYTE_exit ; Check if zero
mov r1,a
mov a,b
user_input_USB_INBYTE_100:
add a,#100
djnz r1,user_input_USB_INBYTE_100
mov b,a
user_input_USB_INBYTE_exit:
mov a,b
pop b
ret
endif
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; function: user_alarm_init
; Initialisation of the user alarm
;
; Input: none
;
; Output: none
;
; Necessary:
; Makes use of timer 0
;
;**********************************************************************************************
user_alarm_init:
lcall user_alarm_timer_init
ret
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; function: user_alarm
; Set the right data in memory for the led driver
; Set the sound alarm
; Show screen that we are updating the screen
;
; Input: none
;
; Output: Text to screen
;
; Internal functions:
; user_alarm_time_0
; user_alarm_exit
; user_alarm_text_0
; user_alarm_calc_led_n
; user_alarm_calc_led_a
; user_alarm_calc_led_a_1
; user_alarm_calc_led_a_2
; user_alarm_data
; user_alarm_data_loop
; user_alarm_data_exit
; user_alarm_data_no_led
; user_alarm_data_mem
; user_alarm_data_clr
; user_alarm_data_clr_loop
;
;**********************************************************************************************
user_alarm:
push acc
push psw
setb Buz_flag ; Mute the buzzer
mov a,#00ch ; Clear screen and move cursor to 00
lcall outcharlcd
mov a,#013h ; Cursor off
lcall outcharlcd
mov dptr,#user_alarm_text_0 ; text_0 out to screen
lcall outmsgalcd
clr Buz_flag
mov a,examen_time ; Get examen time
subb a,total_alarm_time ; Subtract alarm time
jc user_alarm_time_0 ; If zero show alarm
lcall user_alarm_calc_led_n
mov r3,#01Fh ; Put the led's in green
mov r4,#00fh
mov r5,#0FFh
mov r6,#00fh
lcall user_alarm_data
sjmp user_alarm_exit
user_alarm_time_0:
lcall user_alarm_calc_led_a
mov r3,#01Fh ; Put the led's in red
mov r4,#000h
mov r5,#00fh
mov r6,#0FFh
lcall user_alarm_data
lcall buzzer_music
sjmp user_alarm_exit
user_alarm_exit:
pop psw
pop acc
ret
user_alarm_text_0:
db 'Led-strip aan het'
db 0C0h ; Next line
db 'updaten.'
db 000h
; This function calaculates the number of led's that still need to shine
; For in normal mode
user_alarm_calc_led_n:
mov a,total_examen_time ; Get the examen time
sjmp user_alarm_calc_led_a_1
; This function calaculates the number of led's that still need to shine
; For in alarm mode
user_alarm_calc_led_a:
mov a,total_alarm_time ; Get the alarm time
user_alarm_calc_led_a_1:
mov b,#led_count ; Get the ledocunt
div ab ; Divide
jnz user_alarm_calc_led_a_2 ; Allwas have a one in the acc
inc a ; round up
user_alarm_calc_led_a_2:
mov b,a ; Qoutiont load (min/led) this will be now the divider
mov a,examen_time ; Time to go
div ab ; in a the number of led's that need to light up
mov r7,a
subb a,#led_count
jc user_alarm_calc_led_a_3
mov r7,#led_count
user_alarm_calc_led_a_3:
mov a,r7
ret
; Fill the led's data with values in register until the upper led given by a
; a is the number of led's that need to shine
; r3-r6 is the color gl b g r
; r7 the number of led's that need to shine
; Makes use of r0,r1,r2
user_alarm_data:
push acc
push psw
lcall user_alarm_data_clr
mov a,r7
jz user_alarm_data_no_led ; Check if we need to do anything if not clear all the led's
user_alarm_data_loop:
mov r1,a ; Get the number of led's still needing commands
lcall user_alarm_data_mem ; Get the base memory location of the led
add a,#000h ; Add the offset
mov r0,a ; Move the value adress in r0
mov a,r3 ; Get the global value
mov @r0,a ; Put the value in mem
mov a,r2 ; Get the base memory location of the led
add a,#001h ; Add the offset
mov r0,a ; Move the value adress in r0
mov a,r4 ; Get the blue value
mov @r0,a ; Put the value in mem
mov a,r2 ; Get the base memory location of the led
add a,#002h ; Add the offset
mov r0,a ; Move the value adress in r0
mov a,r5 ; Get the green value
mov @r0,a ; Put the value in mem
mov a,r2 ; Get the base memory location of the led
add a,#003h ; Add the offset
mov r0,a ; Move the value adress in r0
mov a,r6 ; Get the red value
mov @r0,a ; Put the value in mem
mov a,r1 ; Led's that still need controll
djnz acc,user_alarm_data_loop; Decrement and loop again
user_alarm_data_exit:
pop psw
pop acc
ret
user_alarm_data_no_led:
mov r3,#000h
mov r4,#000h
mov r5,#000h
mov r6,#000h
mov r7,#led_count
mov a,#led_count
sjmp user_alarm_data_loop
; Gets the next memory location and put this in r5
user_alarm_data_mem:
mov a,#led_count ; Get the total number of led's
subb a,r1 ; Subbtract the number of led's still need to command
mov b,#004h ; The offeset multiplier
mul ab
add a,#LED_data_offset ; Add the base register
mov r2,a
ret
; Clears all the led data
user_alarm_data_clr:
mov a,#led_count ; Get the total number of led's
mov b,#004h ; The offeset multiplier
mul ab
add a,#LED_data_offset ; a = the max led register
user_alarm_data_clr_loop:
mov r0,a ; Move the value adress in r0ue
mov @r0,#000h ; Clear the cell
dec a
cjne a,#LED_data_offset - 1,user_alarm_data_clr_loop
ret
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; function: user_alarm_timer_init
; Initialization of timer 0
;
; Input: none
;
; Output: none
;
; Necessary:
; Makes use of timer 0
;
;**********************************************************************************************
user_alarm_timer_init:
mov tl0,#000h ; Clear
mov th0,#000h
mov a,tmod
orl a,#00000001b
mov tmod,a
setb TR0 ; Timer 1 on
setb et0
setb ea
ret
;**********************************************************************************************
; Stijn Goethals and Nele Annaert (C) 2016
; function: user_alarm_timer_intr
; The interupt routine for timer 0
; Will set every second and minute the right flags
;
; Input: none
;
; Output: none
;
; Necessary:
; CLK on 16 Mhz
; Makes use of timer 0
;
; Internal functions:
; user_alarm_timer_intr_min
; user_alarm_timer_intr_min_2
; user_alarm_timer_intr_exit
; user_alarm_timer_intr_reload
;
;**********************************************************************************************
user_alarm_timer_intr:
push acc
push psw
mov a,timer0_count ; Get the interupt count
cjne a,#21,user_alarm_timer_intr_reload ; Do we have got almost a second? (counted until 0.98304.. sec?)
; (16.777216Mhz/12)^-1=715,255737ns *2^16 = 0clkport46875s (per timer interupt)
;
clr tr0
mov tl0,#0AAh ; 2^16 - 21845.333 instructions = 43691 instructions
mov th0,#0ABh
setb TR0
mov timer0_count,#000h
; Check if we hava minute
user_alarm_timer_intr_min:
setb input_flag ; Update the lcd
inc sec_timer
mov a,sec_timer
cjne a,#060,user_alarm_timer_intr_exit
setb LED_flag ; Update the led's
mov a,examen_time