-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.txt
More file actions
1464 lines (1179 loc) · 64.1 KB
/
code.txt
File metadata and controls
1464 lines (1179 loc) · 64.1 KB
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
;**************************************************************
;* Multiplying Two Unsigned 8-bit Numbers *
;**************************************************************
; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point
; Include derivative-specific definitions
INCLUDE 'derivative.inc'
;**************************************************************
;* Code Section *
;**************************************************************
ORG $3000 ; Following variables will be stored $3000 onwards
MULTIPLICAND FCB 01 ; First Number - preload 1 for test
MULTIPLIER FCB 02 ; Second Number - preload 2 for test
PRODUCT RMB 2 ; Result of multiplicatiom
;**************************************************************
;* Actual Program Starts Here *
;**************************************************************
ORG $4000
Entry:
_Startup:
LDAA MULTIPLICAND ; Get the MULTIPLICAND into Accumulator A
LDAB MULTIPLIER ; Get the MULTIPLIER into Accumulator B
MUL ; Unsigned multiplication
STD PRODUCT ; Assign the result into PRODUCT
SWI ; Break to the monitor
;**************************************************************
;* Interrupt Vectors *
;**************************************************************
ORG $FFFE
DC.W Entry ; Reset Vector
; —---------------------------------------------------------------------------------------------
;**************************************************************
;* Programming the I/O Devices - LED bar *
;**************************************************************
; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point
; Include derivative-specific definitions
INCLUDE 'derivative.inc'
;**************************************************************
;* Actual Program Starts Here *
;**************************************************************
ORG $4000
Entry:
_Startup:
LDAA #$FF ; ACCA = $FF
STAA DDRH ; Config. Port H for output
STAA PERT ; Enab. pull-up res. of Port T
Loop: LDAA PTT ; Read Port T
STAA PTH ; Display SW1 on LED1 connected to Port H
BRA Loop ; Loop
;**************************************************************
;* Interrupt Vectors *
;**************************************************************
ORG $FFFE
DC.W Entry ; Reset Vector
; —---------------------------------------------------------------------------------------------
;************************************************************************************
;* Programming the I/O Devices - Keypad controlling LED's light *
;************************************************************************************
; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point
; Include derivative-specific definitions
INCLUDE 'derivative.inc'
;**************************************************************
;* Actual Program Starts Here *
;**************************************************************
ORG $4000
Entry:
_Startup:
BSET DDRP,%11111111 ; Configure Port P for output (LED2 cntrl)
BSET DDRE,%00010000 ; Configure pin PE4 for output (enable bit)
BCLR PORTE,%00010000 ; Enable keypad
Loop: LDAA PTS ; Read a key code into AccA
LSRA ; Shift right AccA
LSRA ; -"-
LSRA ; -"-
LSRA ; -"-
STAA PTP ; Output AccA content to LED2
BRA Loop ; Loop
;**************************************************************
;* Interrupt Vectors *
;**************************************************************
ORG $FFFE
DC.W Entry ; Reset Vector
; —---------------------------------------------------------------------------------------------
;**************************************************************
;* Programming the I/O Devices - Buzzer *
;**************************************************************
; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point
; Include derivative-specific definitions
INCLUDE 'derivative.inc'
;**************************************************************
;* Actual Program Starts Here *
;**************************************************************
ORG $4000
Entry:
_Startup:
BSET DDRP,%11111111 ; Config. Port P for output
LDAA #%10000000 ; Prepare to drive PP7 high
MainLoop
STAA PTP ; Drive PP7
LDX #$1FFF ; Initialize the loop counter
Delay
DEX ; Decrement the loop counter
BNE Delay ; If not done, continue to loop
EORA #%10000000 ; Toggle the MSB of AccA
BRA MainLoop ; Go to MainLoop
;**************************************************************
;* Interrupt Vectors *
;**************************************************************
ORG $FFFE
DC.W Entry ; Reset Vector
; —---------------------------------------------------------------------------------------------
;*****************************************************************************************************************
;* Programming the I/O Devices - Display Message and Hex Value *
;*****************************************************************************************************************
; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point
; Include derivative-specific definitions
INCLUDE 'derivative.inc'
;*******************************************************************
;* Writing to the LCD
;*******************************************************************
; Definitions
LCD_DAT EQU PTS ; LCD data port S, pins PS7,PS6,PS5,PS4
LCD_CNTR EQU PORTE ; LCD control port E, pins PE7(RS),PE4(E)
LCD_E EQU $10 ; LCD enable signal, pin PE4
LCD_RS EQU $80 ; LCD reset signal, pin PE7
ORG $3000
FIRST_HEX FCB $F4
SECOND_HEX FCB $42
MEM1 RMB 01
MEM2 RMB 01
MEM3 RMB 01
MEM4 RMB 01
MEM5 RMB 01
; code section
ORG $4000
Entry:
_Startup:
LDS #$4000 ; initialize stack pointer
JSR initLCD ; initialize LCD
;*******************************************************************
;* Program starts here
;*******************************************************************
MainLoop:
JSR clrLCD ; clear LCD & home cursor
LDX #msg1 ; display msg1
JSR putsLCD ; -"
LDAA $3000 ; load contents at $3000 into A
JSR leftHLF ; convert left half of A into ASCII
STAA MEM1 ; store the ASCII byte into mem1
LDAA $3000 ; load contents at $3000 into A
JSR rightHLF ; convert right half of A into ASCII
STAA MEM2 ; store the ASCII byte into mem2
LDAA $3001 ; load contents at $3001 into A
JSR leftHLF ; convert left half of A into ASCII
STAA MEM3 ; store the ASCII byte into mem3
LDAA $3001 ; load contents at $3001 into A
JSR rightHLF ; convert right half of A into ASCII
STAA MEM4 ; store the ASCII byte into mem4
LDAA 0 ; load 0 into A
STAA MEM5 ; store string termination character 00 into mem5
LDX #MEM1 ; output the 4 ASCII characters
JSR putsLCD ; -"
LDY #20000 ; Delay = 1s
JSR del_50us
BRA MainLoop ; Loop
msg1 dc.b "Hi There! ",0
;*******************************************************************
;* Subroutine section
;*******************************************************************
;* Initialization of the LCD: 4-bit data width, 2-line display,
;* turn on display, cursor and blinking off. Shift cursor right.
;*******************************************************************
initLCD:
BSET DDRS,%11110000 ; configure pins PS7,PS6,PS5,PS4 for output
BSET DDRE,%10010000 ; configure pins PE7,PE4 for output
LDY #2000 ; wait for LCD to be ready
JSR del_50us ; -"
LDAA #$28 ; set 4-bit data, 2-line display
JSR cmd2LCD ; -"
LDAA #$0C ; display on, cursor off, blinking off
JSR cmd2LCD ; -"
LDAA #$06 ; move cursor right after entering a character
JSR cmd2LCD ; -"
RTS
;*******************************************************************
;* Clear display and home cursor
;*******************************************************************
clrLCD:
LDAA #$01 ; clear cursor and return to home position
JSR cmd2LCD ; -"
LDY #40 ; wait until "clear cursor" command is complete
JSR del_50us ; -"
RTS
;*******************************************************************
;* ([Y] x 50us) - delay subroutine. E-clk = 41.67ns.
;*******************************************************************
del_50us:
PSHX ; 2 E-clk
eloop: ;LDX #30 ; 2 E-clk
iloop: PSHA ; 2 E-clk
PULA ; 3 E-clk
PSHA ; 2 E-clk
PULA ; 3 E-clk
NOP ; 1 E-clk
NOP ; 1 E-clk
DBNE X,iloop ; 3 E-clk
LDX #30 ;reset x for next outer loop
DBNE Y,eloop ; 3 E-clk
PULX ; 3 E-clk
RTS ; 5 E-clk
;*******************************************************************
;* This function sends a command in accumulator A to the LCD
;*******************************************************************
cmd2LCD:
BCLR LCD_CNTR,LCD_RS ; select the LCD Instruction Register (IR)
JSR dataMov ; send data to IR
RTS
;*******************************************************************
;* This function outputs a NULL-terminated string pointed to by X
;*******************************************************************
putsLCD:
LDAA 1,X+ ; get one character from the string
BEQ donePS ; Keeps loading characters from A until it reaches Null
JSR putcLCD
BRA putsLCD
donePS:
RTS
;*******************************************************************
;* This function outputs the character in accumulator A to LCD
;*******************************************************************
putcLCD:
BSET LCD_CNTR,LCD_RS ; select the LCD Data register (DR)
JSR dataMov ; send data to DR
RTS
;*******************************************************************
;* This function sends data to the LCD IR or DR depending on RS
;*******************************************************************
dataMov:
BSET LCD_CNTR,LCD_E ; pull the LCD E-signal high
STAA LCD_DAT ; send the upper 4 bits of data to LCD
BCLR LCD_CNTR,LCD_E ; pull the LCD E-signal low to complete write
LSLA ; match the lower 4 bits with the LCD data pins
LSLA ; Moves up the lower nibble to prep it to send to LCD
LSLA
LSLA
BSET LCD_CNTR,LCD_E ; pull the LCD E signal high
STAA LCD_DAT ; send the lower 4 bits of data to LCD
BCLR LCD_CNTR,LCD_E ; pull the LCD E-signal low to complete write
LDY #1 ; adding this delay will complete the internal
JSR del_50us ; operation for most instructions
RTS
;*******************************************************************
;* Binary to ASCII
;*******************************************************************
leftHLF:
LSRA ; shift data to right
LSRA
LSRA
LSRA
rightHLF:
ANDA #$0F ; mask top half
ADDA #$30 ; convert to ASCII
CMPA #$39 ; jump if 0-9
BLE out
ADDA #$07 ; convert to hex A-F
out:
RTS
; —---------------------------------------------------------------------------------------------
;**************************************************************
;* Battery and Bumper Display for the Eebot *
;**************************************************************
; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point
; Include derivative-specific definitions
INCLUDE 'derivative.inc'
;*****************************************************************
;* Displaying battery voltage and bumper states (s19c32) *
;*****************************************************************
; Definitions
LCD_DAT EQU PORTB ;LCD data port, bits - PB7,...,PB0
LCD_CNTR EQU PTJ ;LCD control port, bits - PE7(RS),PE4(E)
LCD_E EQU $80 ;LCD E-signal pin
LCD_RS EQU $40 ;LCD RS-signal pin
; Variable/data section
ORG $3850
BCD_BUFFER EQU * ;The following registers are the BCD buffer area
TEN_THOUS RMB 1 ;10,000 digit
THOUSANDS RMB 1 ;1,000 digit
HUNDREDS RMB 1 ;100 digit
TENS RMB 1 ;10 digit
UNITS RMB 1 ;1 digit
BCD_SPARE RMB 10 ;Extra space for decimal point and string terminator
NO_BLANK RMB 1 ;Used in ’leading zero’ blanking by BCD2ASC
BUMPER_BOW RMB 1
BUMPER_STERN RMB 1
; Code section
ORG $4000
Entry:
_Startup:
LDS #$4000 ;initialize the stack pointer
JSR initAD ;initialize ATD converter
JSR initLCD ;initialize LCD
JSR clrLCD ;clear LCD & home cursor
LDX #msg1 ;display msg1
JSR putsLCD ;"
LDAA #$C0 ;move LCD cursor to the 2nd row
JSR cmd2LCD
LDX #msg2 ;display msg2
JSR putsLCD ;"
lbl MOVB #$90,ATDCTL5 ;r.just., unsign., sing.conv., mult., ch0, start conv.
BRCLR ATDSTAT0,$80,* ;wait until the conversion sequence is complete
LDAA ATDDR4L ;load the ch4 result into AccA
LDAB #39 ;AccB = 39
MUL ;AccD = 1st result x 39
ADDD #600 ;AccD = 1st result x 39 + 600
JSR INT2BCD
JSR BCD2ASC
LDAA #$8D ;move LCD cursor to the 1st row, end of msg1
JSR cmd2LCD ;"
LDAA TEN_THOUS ;output the TEN_THOUS ASCII character
JSR putcLCD ;"
LDAA THOUSANDS ;same for THOUSANDS, ’.’ and HUNDREDS
JSR putcLCD ;"
LDAA #'.'
JSR putcLCD
LDAA HUNDREDS
JSR putcLCD
LDAA #'V'
JSR putcLCD
LDAA #$CA ;move LCD cursor to the 2nd row, end of msg2
JSR cmd2LCD ;"
BRCLR PORTAD0,$04,bowON
LDAA #$31 ;output ’1’ if bow sw OFF
BRA bowOFF
bowON LDAA #'0' ;#$30 output ’0’ if bow sw ON
bowOFF JSR putcLCD
LDAA #' ' ;output a space character in ASCII
JSR putcLCD ;"
BRCLR PORTAD0,$08,sternON
LDAA #$31 ;output ’1’ if stern sw OFF
BRA sternOFF
sternON LDAA #$30 ;output ’0’ if stern sw ON
sternOFF JSR putcLCD
JMP lbl
msg1 dc.b "Battery volt ",0
msg2 dc.b "Sw status ",0
; Subroutine section
initLCD BSET DDRB,%11110000 ; configure pins PS7,PS6,PS5,PS4 for output
BSET DDRJ,%11000000 ; configure pins PE7,PE4 for output
LDY #$2000 ; wait for LCD to be ready
JSR del_50us ; -"-
LDAA #$28 ; set 4-bit data, 2-line display
JSR cmd2LCD ; -"-
LDAA #$0C ; display on, cursor off, blinking off
JSR cmd2LCD ; -"-
LDAA #$06 ; move cursor right after entering a character
JSR cmd2LCD ; -"-
RTS
clrLCD LDAA #$01 ; clear cursor and return to home position
JSR cmd2LCD ; -"-
LDY #$40 ; wait until "clear cursor" command is complete
JSR del_50us ; -"-
RTS
del_50us: PSHX ;2 E-clk
eloop: LDX #$30 ;2 E-clk -
iloop: PSHA ;2 E-clk |
PULA ;3 E-clk |
PSHA ;2 E-clk | 50us
PULA ;3 E-clk |
PSHA
PULA
PSHA
PULA
PSHA
PULA
PSHA
PULA
PSHA
PULA
NOP ;1 E-clk |
NOP ;1 E-clk |
DBNE X,iloop ;3 E-clk -
DBNE Y,eloop ;3 E-clk
PULX ;3 E-clk
RTS ;5 E-clk
cmd2LCD: BCLR LCD_CNTR,LCD_RS ; select the LCD Instruction Register (IR)
JSR dataMov ; send data to IR
RTS
putsLCD LDAA 1,X+ ; get one character from the string
BEQ donePS ; reach NULL character?
JSR putcLCD
BRA putsLCD
donePS RTS
putcLCD BSET LCD_CNTR,LCD_RS ; select the LCD Data register (DR)
JSR dataMov ; send data to DR
RTS
dataMov BSET LCD_CNTR,LCD_E ; pull the LCD E-sigal high
STAA LCD_DAT ; send the upper 4 bits of data to LCD
BCLR LCD_CNTR,LCD_E ; pull the LCD E-signal low to complete the write oper.
LSLA ; match the lower 4 bits with the LCD data pins
LSLA ; -"-
LSLA ; -"-
LSLA ; -"-
BSET LCD_CNTR,LCD_E ; pull the LCD E signal high
STAA LCD_DAT ; send the lower 4 bits of data to LCD
BCLR LCD_CNTR,LCD_E ; pull the LCD E-signal low to complete the write oper.
LDY #$01 ; adding this delay will complete the internal
JSR del_50us ; operation for most instructions
RTS
INT2BCD XGDX ;Save the binary number into .X
LDAA #$0 ;Clear the BCD_BUFFER
STAA TEN_THOUS
STAA THOUSANDS
STAA HUNDREDS
STAA TENS
STAA UNITS
STAA BCD_SPARE
STAA BCD_SPARE+1
CPX #0 ;Check for a zero input
BEQ CON_EXIT ;and if so, exit
XGDX ;Not zero, get the binary number back to .D as dividend
LDX #10 ;Setup 10 (Decimal!) as the divisor
IDIV ;Divide: Quotient is now in .X, remainder in .D
STAB UNITS ;Store remainder
CPX #$0 ;If quotient is zero,
BEQ CON_EXIT ;then exit
XGDX ;else swap first quotient back into .D
LDX #10 ;and setup for another divide by 10
IDIV
STAB TENS
CPX #$0
BEQ CON_EXIT
XGDX ;Swap quotient back into .D
LDX #10 ;and setup for another divide by 10
IDIV
STAB HUNDREDS
CPX #0
BEQ CON_EXIT
XGDX ;Swap quotient back into .D
LDX #10 ;and setup for another divide by 10
IDIV
STAB THOUSANDS
CPX #0
BEQ CON_EXIT
XGDX ;Swap quotient back into .D
LDX #10 ;and setup for another divide by 10
IDIV
STAB TEN_THOUS
CON_EXIT RTS ;We’re done the conversion
BCD2ASC LDAA #0 ;Initialize the blanking flag
STAA NO_BLANK
C_TTHOU LDAA TEN_THOUS ;Check the ’ten_thousands’ digit
ORAA NO_BLANK
BNE NOT_BLANK1
ISBLANK1 LDAA #' ' ;It’s blank
STAA TEN_THOUS ;so store a space
BRA C_THOU ;and check the ’thousands’ digit
NOT_BLANK1 LDAA TEN_THOUS ;Get the ’ten_thousands’ digit
ORAA #$30 ;Convert to ascii
STAA TEN_THOUS
LDAA #$1 ;Signal that we have seen a ’non-blank’ digit
STAA NO_BLANK
C_THOU LDAA THOUSANDS ;Check the thousands digit for blankness
ORAA NO_BLANK ;If it’s blank and ’no-blank’ is still zero
BNE NOT_BLANK2
ISBLANK2 LDAA #' ' ;Thousands digit is blank
STAA THOUSANDS ;so store a space
BRA C_HUNS ;and check the hundreds digit
NOT_BLANK2 LDAA THOUSANDS ;(similar to ’ten_thousands’ case)
ORAA #$30
STAA THOUSANDS
LDAA #$1
STAA NO_BLANK
C_HUNS LDAA HUNDREDS ;Check the hundreds digit for blankness
ORAA NO_BLANK ;If it’s blank and ’no-blank’ is still zero
BNE NOT_BLANK3
ISBLANK3 LDAA #' ' ;Hundreds digit is blank
STAA HUNDREDS ;so store a space
BRA C_TENS ;and check the tens digit
NOT_BLANK3 LDAA HUNDREDS ;(similar to ’ten_thousands’ case)
ORAA #$30
STAA HUNDREDS
LDAA #$1
STAA NO_BLANK
C_TENS LDAA TENS ;Check the tens digit for blankness
ORAA NO_BLANK ;If it’s blank and ’no-blank’ is still zero
BNE NOT_BLANK4
ISBLANK4 LDAA #' ' ;Tens digit is blank
STAA TENS ;so store a space
BRA C_UNITS ;and check the units digit
NOT_BLANK4 LDAA TENS ;(similar to ’ten_thousands’ case)
ORAA #$30
STAA TENS
C_UNITS LDAA UNITS ;No blank check necessary, convert to ascii.
ORAA #$30
STAA UNITS
RTS ;We’re done
initAD MOVB #$C0,ATDCTL2 ;power up AD, select fast flag clear\
LDY #$01
JSR del_50us ;wait for 50 us
MOVB #$00,ATDCTL3 ;8 conversions in a sequence
MOVB #$85,ATDCTL4 ;res=8, conv-clks=2, prescal=12
BSET ATDDIEN,$0C ;configure pins AN03,AN02 as digital inputs
RTS
;**************************************************************
;* Interrupt Vectors *
;**************************************************************
ORG $FFFE
DC.W Entry ; Reset Vector
; —---------------------------------------------------------------------------------------------
;**************************************************************
;* Motor Control Routines *
;**************************************************************
; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point
; Include derivative-specific definitions
INCLUDE 'derivative.inc'
ROMStart EQU $4000 ; absolute address to place my code/constant data
;*****************************************************************
;* Displaying battery voltage and bumper states (s19c32) *
;*****************************************************************
; Definitions
; Variable/data section
ORG RAMStart
; Code section
ORG ROMStart
Entry:
_Startup:
;************************************************************
;* Motor Control *
;************************************************************
BSET DDRA,%00000011
BSET DDRT,%00110000
JSR STARON
JSR PORTON
JSR STARFWD
JSR PORTFWD
JSR STARREV
JSR PORTREV
JSR STAROFF
JSR PORTOFF
BRA *
STARON LDAA PTT
ORAA #%00100000
STAA PTT
RTS
STAROFF LDAA PTT
ANDA #%11011111
STAA PTT
RTS
PORTON LDAA PTT
ORAA #%00010000
STAA PTT
RTS
PORTOFF LDAA PTT
ANDA #%11101111
STAA PTT
RTS
STARFWD LDAA PORTA
ANDA #%11111101
STAA PORTA
RTS
STARREV LDAA PORTA
ORAA #%00000010
STAA PORTA
RTS
PORTFWD LDAA PORTA
ANDA #%11111110
STAA PORTA
RTS
PORTREV LDAA PORTA
ORAA #%00000001
STAA PORTA
RTS
;**************************************************************
;* Interrupt Vectors *
;**************************************************************
ORG $FFFE
DC.W Entry ; Reset Vector
; —---------------------------------------------------------------------------------------------
;**************************************************************
;* Timer Overflow - 5 Second Delay *
;**************************************************************
; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point
; Include derivative-specific definitions
INCLUDE 'derivative.inc'
ROMStart EQU $4000 ; absolute address to place my code/constant data
; Insert here your data definition.
;************************************************************
;* 5 Second Delay *
;************************************************************
DT_DEMO EQU 115 ; 5 second delay
ORG $3850
TOF_COUNTER RMB 1
AT_DEMO RMB 1
ORG $4000
Entry:
_Startup:
LDS #$4000
JSR ENABLE_TOF ; Jump to TOF init
CLI
LDAA TOF_COUNTER
ADDA #DT_DEMO
STAA AT_DEMO
CHK_DELAY LDAA TOF_COUNTER
CMPA AT_DEMO
BEQ STOP_HERE
NOP ; Do something during the display
BRA CHK_DELAY ; and check the alarm again
STOP_HERE SWI
;************************************************************
ENABLE_TOF LDAA #%10000000
STAA TSCR1 ; Enable TCNT
STAA TFLG2 ; Clear TOF
LDAA #%10000100 ; Enable TOI and select prescale factor equal to 16
STAA TSCR2
RTS
;************************************************************
TOF_ISR INC TOF_COUNTER
LDAA #%10000000 ; Clear
STAA TFLG2 ; TOF
RTI
;************************************************************
DISABLE_TOF LDAA #%00000100 ; Disable TOI and leave prescale factor at 16
STAA TSCR2
RTS
;************************************************************
;* Interrupt Vectors *
;************************************************************
ORG $FFFE
DC.W Entry ; Reset Vector
ORG $FFDE
DC.W TOF_ISR ; Timer Overflow Interrupt Vector
; —---------------------------------------------------------------------------------------------
;**************************************************************
;* Battery and Bumper Display for the Eebot *
;**************************************************************
; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point
; Include derivative-specific definitions
INCLUDE 'derivative.inc'
;************************************************************
;* Timer Alams *
;************************************************************
;definitions
OneSec EQU 23 ; 1 second delay (at 23Hz)
TwoSec EQU 46 ; 2 second delay (at 23Hz)
LCD_DAT EQU PORTB ; LCD data port, bits - PB7,...,PB0
LCD_CNTR EQU PTJ ; LCD control port, bits - PJ7(E),PJ6(RS)
LCD_E EQU $80 ; LCD E-signal pin
LCD_RS EQU $40 ; LCD RS-signal pin
;variable/data section
ORG $3850 ; Where our TOF counter register lives
TOF_COUNTER RMB 1 ; The timer, incremented at 23Hz
AT_DEMO RMB 1 ; The alarm time for this demo
;code section
ORG $4000 ; Where the code starts
Entry:
_Startup:
LDS #$4000 ; initialize the stack pointer
JSR initLCD ; initialize the LCD
JSR clrLCD ; clear LCD & home cursor
JSR ENABLE_TOF ; Jump to TOF initialization
CLI ; Enable global interrupt
LDAA #'A' ;play A (for 1 sec)
JSR putcLCD ; --"--
LDAA TOF_COUNTER ; Initialize the alarm time
ADDA #OneSec ; by adding on the 1 sec delay
STAA AT_DEMO ; and save it in the alarm
CHK_DELAY_1 LDAA TOF_COUNTER ; If the current time
CMPA AT_DEMO ; equals the alarm time
BEQ A1 ; then display B
BRA CHK_DELAY_1 ; and check the alarm again
A1 LDAA #'B' ;Display B (for 2 sec)
JSR putcLCD ; --"--
LDAA AT_DEMO ; Initialize the alarm time
ADDA #TwoSec ; by adding on the 2 sec delay
STAA AT_DEMO ; and save it in the alarm
CHK_DELAY_2 LDAA TOF_COUNTER ; If the current time
CMPA AT_DEMO ; equals the alarm time
BEQ A2 ; then display C
BRA CHK_DELAY_2 ; and check the alarm again
A2 LDAA #'C' ; Display C (forever)
JSR putcLCD ; --"--
SWI
;subroutine section
;************************************************************
initLCD BSET DDRB,%11110000 ; configure pins PS7,PS6,PS5,PS4 for output
BSET DDRJ,%11000000 ; configure pins PE7,PE4 for output
LDY #$2000 ; wait for LCD to be ready
JSR del_50us ; -"-
LDAA #$28 ; set 4-bit data, 2-line display
JSR cmd2LCD ; -"-
LDAA #$0C ; display on, cursor off, blinking off
JSR cmd2LCD ; -"-
LDAA #$06 ; move cursor right after entering a character
JSR cmd2LCD ; -"-
RTS
clrLCD LDAA #$01 ; clear cursor and return to home position
JSR cmd2LCD ; -"-
LDY #$40 ; wait until "clear cursor" command is complete
JSR del_50us ; -"-
RTS
del_50us: PSHX ;2 E-clk
eloop: LDX #$30 ;2 E-clk -
iloop: PSHA ;2 E-clk |
PULA ;3 E-clk |
PSHA ;2 E-clk | 50us
PULA ;3 E-clk |
PSHA
PULA
PSHA
PULA
PSHA
PULA
PSHA
PULA
PSHA
PULA
NOP ;1 E-clk |
NOP ;1 E-clk |
DBNE X,iloop ;3 E-clk -
DBNE Y,eloop ;3 E-clk
PULX ;3 E-clk
RTS ;5 E-clk
cmd2LCD: BCLR LCD_CNTR,LCD_RS ; select the LCD Instruction Register (IR)
JSR dataMov ; send data to IR
RTS
putcLCD BSET LCD_CNTR,LCD_RS ; select the LCD Data register (DR)
JSR dataMov ; send data to DR
RTS
dataMov BSET LCD_CNTR,LCD_E ; pull the LCD E-sigal high
STAA LCD_DAT ; send the upper 4 bits of data to LCD
BCLR LCD_CNTR,LCD_E ; pull the LCD E-signal low to complete the write oper.
LSLA ; match the lower 4 bits with the LCD data pins
LSLA ; -"-
LSLA ; -"-
LSLA ; -"-
BSET LCD_CNTR,LCD_E ; pull the LCD E signal high
STAA LCD_DAT ; send the lower 4 bits of data to LCD
BCLR LCD_CNTR,LCD_E ; pull the LCD E-signal low to complete the write oper.
LDY #$01 ; adding this delay will complete the internal
JSR del_50us ; operation for most instructions
RTS
ENABLE_TOF LDAA #%10000000
STAA TSCR1 ; Enable TCNT
STAA TFLG2 ; Clear TOF
LDAA #%10000100 ; Enable TOI and select prescale factor equal to 16
STAA TSCR2
RTS
TOF_ISR INC TOF_COUNTER
LDAA #%10000000 ; Clear
STAA TFLG2 ; TOF
RTI
;**************************************************************
;* Interrupt Vectors *
;**************************************************************
ORG $FFFE
DC.W Entry ; Reset Vector
ORG $FFDE
DC.W TOF_ISR ; Timer Overflow Interrupt Vector
; —---------------------------------------------------------------------------------------------
;**************************************************************
;* Robot Roaming Program for the Eebot *
;**************************************************************
; export symbols
XDEF Entry, _Startup ; export 'Entry' symbol
ABSENTRY Entry ; for absolute assembly: mark this as application entry point
; Include derivative-specific definitions