-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03_trafficlight-local.s
More file actions
74 lines (64 loc) · 1.46 KB
/
03_trafficlight-local.s
File metadata and controls
74 lines (64 loc) · 1.46 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
.include "m8def.inc"
.cseg
.org 0
rjmp setup
; Blink a traffic light sequence
; Outputs:
; PD0 - Red LED
; PD1 - Yellow LED
; PD2 - Green LED
setup:
; Set up the stack in order to be
; able to use rcall
ldi r16, low(RAMEND)
out SPL, r16
ldi r16, high(RAMEND)
out SPH, r16
; Set up the Data Direction Register (DDR)
; for Port D to have PD0/PD1/PD2 configured as outputs
ldi r16, 0b00000111
out DDRD, r16
lightseq:
rcall red ; Output a red light
rcall delay_long ; Waste a bit of time...
rcall yellowred ; Light to yellow/red combination
rcall delay ; Wait a shorter while
rcall green ; Change to green light
rcall delay_long ; Wait a longer time
rcall yellow ; Change to yellow light
rcall delay ; Wait a short time
rjmp lightseq ; Do it again
red:
ldi r16, 0b00000001 ; Set up the r16 so that the bit controlling the Red LED is set
out PORTD, r16 ; Output the register r16 to PORTD in order to change the Pin
ret ; Jump back to caller
yellow:
ldi r16, 0b00000010
out PORTD, r16
ret
green:
ldi r16, 0b00000100
out PORTD, r16
ret
yellowred:
ldi r16, 0b00000011
out PORTD, r16
ret
delay_long: ; Repeatedly wait a short time in order to waste some more time
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
rcall delay
ret
delay: ; Waste a short amount of time
ldi r16, 0xFF
delay_outer:
ldi r17, 0xFF
delay_inner:
dec r17
brne delay_inner
dec r16
brne delay_outer
ret