Created
November 26, 2019 09:12
-
-
Save Annon201/86efb35dca58aa234200e2ffbdf3d8d1 to your computer and use it in GitHub Desktop.
Read a switch and flash some LEDs - AVR8/atmega2560
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Created: 25/11/2019 9:45:37 AM | |
; Author : Annon | |
; defining some labels to make the code easier to read | |
.def LEDs = r20 | |
.def Switches = r21 | |
.def outer = r22 .def inner = r23 | |
.def inner1 = r24 | |
.org 0000 ; start the code at 0x0000 - we arent using interrupts so don't waste space on them | |
.db "Look ma, I'm on a chip!!" ; :P | |
Start: | |
clr r19 | |
OUT DDRC, r19 | |
ser r19 | |
OUT DDRA, r19 | |
OUT PORTC, r19 | |
Loop: | |
in Switches,PINC ; read switches | |
com Switches ; invert | |
cbr Switches, $7F ; mask out the lower 7 bits | |
cpi r21, $80 ; compare r21 with 0x80 | |
breq setLeds ; turn on leds | |
brne clrLeds ; make sure the leds turn off if not set | |
setLeds: | |
ser LEDs ; set all bits high | |
out PORTA, LEDs ; send them to the leds | |
rcall wait ; wait ~1s | |
clr LEDs ; set all bits low | |
out PORTA, LEDs ; send them to the leds | |
rcall wait ; wait ~1s | |
rjmp Loop ; jump back to main loop | |
clrLeds: | |
clr LEDs ; set all bits low | |
out PORTA, LEDs ; send them to the leds | |
rjmp Loop ; jump back to main loop | |
wait: ; 255 * 252 * 83 * 3 = 16000740/16mhz = 1.0004625s | |
ldi outer,0 | |
waitouter: | |
rcall waitinner | |
dec outer | |
brne waitouter | |
ret | |
waitinner: | |
ldi inner,253 | |
waitinner1: | |
rcall waitininner | |
dec inner | |
brne waitinner1 | |
ret | |
waitininner: | |
ldi inner1,84 | |
waitininner1: | |
dec inner1 | |
brne waitininner1 | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment