Created
November 27, 2019 08:09
-
-
Save urish/2dc632baf32598943972a6ed6a927bc4 to your computer and use it in GitHub Desktop.
Blink LEDs according to Switch state on AVR8/atmega2560 - GCC version
This file contains 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 | |
LEDs = 20 | |
Switches = 21 | |
outer = 22 | |
inner = 23 | |
inner1 = 24 | |
; GPIO registers (according to datasheet) | |
DDRA = 0x1 | |
PORTA = 0x2 | |
PINC = 0x6 | |
DDRC = 0x7 | |
PORTC = 0x8 | |
.text | |
.section .rodata | |
.string "Look ma, I'm on a chip!!" ; :P | |
.text | |
.org 0000 ; start the code at 0x0000 - we arent using interrupts so don't waste space on them | |
.global Start | |
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, 0x7F ; mask out the lower 7 bits | |
cpi r21, 0x80 ; 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