-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain2.asm
More file actions
63 lines (51 loc) · 1.63 KB
/
Copy pathmain2.asm
File metadata and controls
63 lines (51 loc) · 1.63 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
.include "m328PBdef.inc" ;ATmega328P microcontroller definitions
;Init Stack Pointer
ldi r24, LOW(RAMEND)
out SPL, r24
ldi r24, HIGH(RAMEND)
out SPH, r24
; delay = (1000*F1+14) cycles (abougt DEL_mS in mSeconds)
.equ FOSC_MHZ=16 ;MHz
.equ DEL_mS=1000 ;mS
.equ F1=FOSC_MHZ*DEL_mS
ldi r24, low(F1) ;
ldi r25, high(F1) ;Set delay
.def cart = R17
.def temp = R16
;Set PORTD as output
ser temp
out DDRD, temp
right:
ldi cart, 0b10000000 ;Place cart at the left
loopr:
out PORTD,cart ;Show cart on screen
rcall delay_1s ;wait about 1 second
lsr cart ;move cart to the right
brcc loopr ;repeat until cart is out of screen (at C)
ldi cart, 0b00000001 ;Place it at the right edge
loopl:
out PORTD, cart ;Show it on screen
rcall delay_1s ;Wait 1 sec
lsl cart ;Move it to the left
brcc loopl ;repeat until cart is out of screen (at C)
jmp right ;Repeat from the beginning
;this routine is used to produce a delay 993 cycles
delay_inner:
ldi r23, 247 ; (1 cycle)
loop3:
dec r23 ; 1 cycle
nop ; 1 cycle
brne loop3 ; 1 or 2 cycles
nop ; 1 cycle
ret ; 4 cycles
;this routine is used to produce a delay of (1000*F1+14) cycles
delay_1s:
push r24 ; (2 cycles)
push r25 ; (2 cycles) Save r24:r25
loop4:
rcall delay_inner ; (3+993)=996 cycles
sbiw r24 ,1 ; 2 cycles
brne loop4 ; 1 or 2 cycles
pop r25 ; (2 cycles)
pop r24 ; (2 cycles) Restore r24:r25
ret ; 4 cycles