Created
March 16, 2012 10:49
-
-
Save inkrement/2049555 to your computer and use it in GitHub Desktop.
Mikrocontroller
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
; Christian Hotz-Behofsits 2012 | |
; logical functions in asm (atmega 1280) | |
; | |
; 1st PA4: (PA1 and PA2) or PA3 | |
; 2nd PA5: (PA1 or not PA2) and PA3 | |
; 3rd PA6: PA1 xor PA2 | |
; 3rd PA7: PA1 == PA2 | |
.NOLIST | |
.INCLUDE "m1280def.inc" | |
.LIST | |
.section .text | |
.org 0x0000 | |
Reset: | |
rjmp main | |
main: | |
; 1 output | |
; 0 input | |
;ldi R16, 0xff | |
;out DDRB, R16 | |
ldi R16, 0b11110000 | |
out DDRA, R16 | |
ldi R16, 0x00 | |
; first function | |
in R21, PINA | |
asr R21 | |
andi R21, 0x01 | |
in R22, PINA | |
asr R22 | |
asr R22 | |
andi R22, 0x01 | |
and R21, R22 | |
in R23, PINA | |
asr R23 | |
asr R23 | |
asr R23 | |
andi R23, 0x01 | |
or R21, R23 | |
; second function | |
in R20, PINA | |
asr R20 | |
andi R20, 0x01 | |
in R22, PINA | |
asr R22 | |
asr R22 | |
com R22 | |
in R23, PINA | |
asr R23 | |
asr R23 | |
asr R23 | |
or R20, R22 | |
and R20, R23 | |
lsl R20 | |
andi R20, 0x02 | |
; third function | |
in R22, PINA | |
asr R22 | |
andi R22, 0x01 | |
in R23, PINA | |
asr R23 | |
asr R23 | |
andi R23, 0x01 | |
eor R22, R23 | |
lsl R22 | |
lsl R22 | |
andi R22, 0x04 | |
; 4th function ... take 3rd and toggle (xor against true) | |
mov R23, R22 | |
ldi R25, 0x04 | |
eor R23, R25 | |
lsl R23 | |
or R16, R21 | |
or R16, R20 | |
or R16, R22 | |
or R16, R23 | |
;shift result to higher bit-region | |
bclr 0 | |
rol R16 | |
rol R16 | |
rol R16 | |
rol R16 | |
out PORTA, R16 | |
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
; Christian Hotz-Behofsits 2012 | |
; i/o example in asm (atmega 1280) | |
.NOLIST | |
.INCLUDE "m1280def.inc" | |
.LIST | |
.section .text | |
.org 0x0000 | |
Reset: | |
rjmp main | |
main: | |
; set PORTA as input | |
clr R16 | |
out DDRA, R16 | |
; set PORTB/PORTC as output | |
ser R16 | |
out DDRB, R16 | |
out DDRC, R16 | |
; print PORTA to PORTB | |
in R17, PORTA | |
out PORTB, R17 | |
; print PINA to PORTC | |
in R17, PINA | |
out PORTC, R17 | |
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
; Christian Hotz-Behofsits 2012 | |
; i/o example in asm (atmega 1280) | |
; set leds on button event | |
.NOLIST | |
.INCLUDE "m1280def.inc" | |
.LIST | |
.section .text | |
.org 0x0000 | |
Reset: | |
rjmp main | |
main: | |
ser R17 | |
;set output | |
clr R16 | |
out DDRA, R16 | |
out DDRB, R16 | |
out DDRC, R16 | |
out DDRD, R16 | |
out DDRE, R16 | |
out DDRF, R16 | |
out DDRG, R16 | |
STS 0x101, R16 | |
sts DDRJ, R16 | |
sts DDRK, R16 | |
sts DDRL, R16 | |
loop: | |
; PORTA | |
in R16, PINA | |
out DDRA, R16 | |
out PORTA, R16 | |
cpse R16, R17 | |
rjmp endA | |
clr R16 | |
out DDRA, R16 | |
out PORTA, R16 | |
clz | |
endA: | |
; PORTB | |
in R16, PINB | |
out DDRB, R16 | |
out PORTB, R16 | |
cpse R16, R17 | |
rjmp endB | |
clr R16 | |
out DDRB, R16 | |
out PORTB, R16 | |
clz | |
endB: | |
; PORTC | |
in R16, PINC | |
out DDRC, R16 | |
out PORTC, R16 | |
cpse R16, R17 | |
rjmp endC | |
clr R16 | |
out DDRC, R16 | |
out PORTC, R16 | |
clz | |
endC: | |
; PORTD | |
in R16, PIND | |
out DDRD, R16 | |
out PORTD, R16 | |
cpse R16, R17 | |
rjmp endD | |
clr R16 | |
out DDRD, R16 | |
out PORTD, R16 | |
clz | |
endD: | |
; PORTE | |
in R16, PINE | |
out DDRE, R16 | |
out PORTE, R16 | |
cpse R16, R17 | |
rjmp endE | |
clr R16 | |
out DDRE, R16 | |
out PORTE, R16 | |
clz | |
endE: | |
; PORTF | |
in R16, PINF | |
out DDRF, R16 | |
out PORTF, R16 | |
cpse R16, R17 | |
rjmp endF | |
clr R16 | |
out DDRF, R16 | |
out PORTF, R16 | |
clz | |
endF: | |
; PORTG | |
in R16, PING | |
out DDRG, R16 | |
out PORTG, R16 | |
cpse R16, R17 | |
rjmp endG | |
clr R16 | |
out DDRG, R16 | |
out PORTG, R16 | |
clz | |
endG: | |
; PORTH | |
lds R16, 0x100 | |
sts 0x101, R16 | |
sts 0x102, R16 | |
cpse R16, R17 | |
rjmp endH | |
clr R16 | |
sts DDRH, R16 | |
sts PORTH, R16 | |
clz | |
endH: | |
; PORTJ | |
lds R16, PINJ | |
sts DDRJ, R16 | |
sts PORTJ, R16 | |
cpse R16, R17 | |
rjmp endJ | |
clr R16 | |
sts DDRJ, R16 | |
sts PORTJ, R16 | |
clz | |
endJ: | |
; PORTK | |
lds R16, PINK | |
sts DDRK, R16 | |
sts PORTK, R16 | |
cpse R16, R17 | |
rjmp endK | |
clr R16 | |
sts DDRK, R16 | |
sts PORTK, R16 | |
clz | |
endK: | |
; PORTL | |
lds R16, PINL | |
sts DDRL, R16 | |
sts PORTL, R16 | |
cpse R16, R17 | |
rjmp endL | |
clr R16 | |
sts DDRL, R16 | |
sts PORTL, R16 | |
clz | |
endL: | |
rjmp loop | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment