Aktyw Forum
Zarejestruj się na forum.ep.com.pl i zgłoś swój akces do Aktywu Forum. Jeśli jesteś już zarejestrowany wystarczy, że się zalogujesz.
Sprawdź punkty Zarejestruj sięJaka literatura do nauki programowania AVR
Moderatorzy:Jacek Bogusz, procesorowiec, r-mik, Moderatorzy
Czy mógłby mnie ktoś poinformować o jakiejś dobrej literaturze do nauki programowania AVR w Asemblerze?? Muszę zaprogramować taki układ jak AT90S2313. Mile widziane przykładowe programiki napisane w Asemblerze na ten mikrokontroler
Można już ciągnąć, oto link: www.elektronika.qs.pl/arch.html#asm
Myślę, że i tak jest już dużo materiałów udostępnionych, zostawmy trochę do publikacji w postaci książkiPowiem krotko
Jestem zainteresowany dalszymi czesciami ksiazki
pomogla mi zrozumiec wiele rzeczy z asm a jestem poczatkujacy
Brakuje takiej pozycji na runku (to moje zdanie)
P.S.
Czy istnieje mozliwosc udostepnienia rozdzialu omawiajacego przerwania w AVR ? oraz przykladowy programik lub ki ???
Prosty programik do przerwań od timer 0
;
;*******************************************************
.include "8515def.inc"
;*******************************************************
.list
.listmac
;-----------------------------------------------------------------------------
.macro ldz
ldi zl,low(@0)
ldi zh,high(@0)
.endm
;-----------------------------------------------------------------------------
.macro pushz
push zl
push zh
.endm
;-----------------------------------------------------------------------------
.macro popz
pop zh
pop zl
.endm
;-----------------------------------------------------------------------------
.macro pushf
push acc
in acc,sreg
push acc
.endm
;-----------------------------------------------------------------------------
.macro popf
pop acc
out sreg,acc
pop acc
.endm
;-----------------------------------------------------------------------------
.def acc = r16
;-----------------------------------------------------------------------------
.equ StatusLED = 0
.equ TimerData = 0xC0
.equ DivideConst = 50
;-----------------------------------------------------------------------------
.equ Stand_GIMSK = 0b00000000
.equ Stand_TIMSK = 0b00000010
.equ Stand_MCUCR = 0b00000000
.equ Stand_TCCR0 = 0b00000001
.equ Stand_TCCR1A = 0b00000000
.equ Stand_TCCR1B = 0b00000000
.equ Stand_UCR = 0b00000000
.equ Stand_UBBR = 47
.equ Stand_PADir = 0b11111111
.equ Stand_PAData = 0b11111111
.equ Stand_PBDir = 0b00000000
.equ Stand_PBData = 0b11111111
.equ Stand_PCDir = 0b11111111
.equ Stand_PCData = 0b11111111
.equ Stand_PDDir = 0b11111111
.equ Stand_PDData = 0b11111111
;-----------------------------------------------------------------------------
.dseg
;*******************************************************
;*******************************************************
;** **
;** DATA SEGMENT **
;** **
;*******************************************************
;*******************************************************
TimeDivider : .byte 1 ; TimeDivider : BYTE ;
Status : .byte 1 ; Status : BYTE ;
;-----------------------------------------------------------------------------
.cseg
;*******************************************************
;*******************************************************
;** **
;** CODE SEGMENT **
;** **
;*******************************************************
;*******************************************************
.org 0
rjmp ResetProcessor ;
;-----------------------------------------------------------------------------
.org INT0addr ;External Interrupt0 Vector Address
reti ;
;-----------------------------------------------------------------------------
.org INT1addr ;External Interrupt1 Vector Address
reti ;
;-----------------------------------------------------------------------------
.org ICP1addr ;Input Capture1 Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org OC1Aaddr ;Output Compare1A Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org OC1Baddr ;Output Compare1B Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org OVF1addr ;Overflow1 Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org OVF0addr ;Overflow0 Interrupt Vector Address
rjmp TC0OvfInterrupt ;
;-----------------------------------------------------------------------------
.org SPIaddr ;SPI Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org URXCaddr ;UART Receive Complete Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org UDREaddr ;UART Data Register Empty Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org UTXCaddr ;UART Transmit Complete Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org ACIaddr ;Analog Comparator Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
HardwareInit : ;
;**************** ;
ldi acc,Stand_GIMSK ;
out GIMSK,acc ;
ldi acc,Stand_TIMSK ;
out TIMSK,acc ;
ldi acc,Stand_MCUCR ;
out MCUCR,acc ;
ldi acc,Stand_TCCR0 ;
out TCCR0,acc ;
ldi acc,Stand_TCCR1A ;
out TCCR1A,acc ;
ldi acc,Stand_TCCR1B ;
out TCCR1B,acc ;
ldi acc,Stand_UCR ;
out UCR,acc ;
ldi acc,Stand_UBBR ;
out UBRR,acc ;
ret ;
;-----------------------------------------------------------------------------
EnvirInit : ;
;**************** ;
ldi acc,Stand_PADir ;
out DDRA,Acc ;
ldi acc,Stand_PAData ;
out PORTA,acc ;
ldi acc,Stand_PBDir ;
out DDRB,Acc ;
ldi acc,Stand_PBData ;
out PORTB,acc ;
ldi acc,Stand_PCDir ;
out DDRC,Acc ;
ldi acc,Stand_PCData ;
out PORTC,acc ;
ldi acc,Stand_PDDir ;
out DDRD,Acc ;
ldi acc,Stand_PDData ;
out PORTD,acc ;
ret ;
;-----------------------------------------------------------------------------
SoftwareInit : ;
;**************** ;
ldi acc,0 ;
sts TimeDivider,acc ;
sts Status,acc ;
ret ;
;-----------------------------------------------------------------------------
TC0OvfInterrupt : ;
;**************** ;
pushf ;
pushz ;
ldz TimeDivider ;
ld acc,Z ;
inc acc ;
st Z,acc ;
cpi acc,DivideConst ;
brne TC0OV_0 ;
ldi acc,0 ;
st Z,acc ;
ldz Status ;
ld acc,Z ;
inc acc ;
st Z,acc ;
neg acc ;
out PORTB,acc ;
TC0OV_0 : ;
ldi acc,TimerData ;
out TCNT0,acc ;
popz ;
popf ;
reti ;
;-----------------------------------------------------------------------------
ClearRegs : ;
;**************** ;
clr R0 ;
ldz 0x1D ;
ClrR_0 : ;
st Z,R0 ;
dec Zl ;
brne ClrR_0 ;
ret ;
;-----------------------------------------------------------------------------
ClearRAM : ;
;*************** ;
ldz RAMEND-1 ;
clr acc ;
CleRA_0 : ;
st -Z,acc ;
;
cpi ZH,0 ;
brne CleRA_2 ;
cpi ZL,0x60 ;
brne CleRA_2 ;
rjmp CleRA_1 ;
CleRA_2 : ;
rjmp CleRA_0 ;
CleRA_1 : ;
ret ;
;-----------------------------------------------------------------------------
ResetProcessor : ;
cli ;
ldi acc,HIGH(RAMEND) ;
out SPH,acc ;
ldi acc,LOW(RAMEND) ;
out SPL,acc ;
;
rcall ClearRAM ;
rcall ClearRegs ;
rcall HardwareInit ;
rcall EnvirInit ;
rcall SoftwareInit ;
sei ;
Main_0 : ;
rjmp Main_0 ;
;
;-----------------------------------------------------------------------------
.exit
;
;*******************************************************
.include "8515def.inc"
;*******************************************************
.list
.listmac
;-----------------------------------------------------------------------------
.macro ldz
ldi zl,low(@0)
ldi zh,high(@0)
.endm
;-----------------------------------------------------------------------------
.macro pushz
push zl
push zh
.endm
;-----------------------------------------------------------------------------
.macro popz
pop zh
pop zl
.endm
;-----------------------------------------------------------------------------
.macro pushf
push acc
in acc,sreg
push acc
.endm
;-----------------------------------------------------------------------------
.macro popf
pop acc
out sreg,acc
pop acc
.endm
;-----------------------------------------------------------------------------
.def acc = r16
;-----------------------------------------------------------------------------
.equ StatusLED = 0
.equ TimerData = 0xC0
.equ DivideConst = 50
;-----------------------------------------------------------------------------
.equ Stand_GIMSK = 0b00000000
.equ Stand_TIMSK = 0b00000010
.equ Stand_MCUCR = 0b00000000
.equ Stand_TCCR0 = 0b00000001
.equ Stand_TCCR1A = 0b00000000
.equ Stand_TCCR1B = 0b00000000
.equ Stand_UCR = 0b00000000
.equ Stand_UBBR = 47
.equ Stand_PADir = 0b11111111
.equ Stand_PAData = 0b11111111
.equ Stand_PBDir = 0b00000000
.equ Stand_PBData = 0b11111111
.equ Stand_PCDir = 0b11111111
.equ Stand_PCData = 0b11111111
.equ Stand_PDDir = 0b11111111
.equ Stand_PDData = 0b11111111
;-----------------------------------------------------------------------------
.dseg
;*******************************************************
;*******************************************************
;** **
;** DATA SEGMENT **
;** **
;*******************************************************
;*******************************************************
TimeDivider : .byte 1 ; TimeDivider : BYTE ;
Status : .byte 1 ; Status : BYTE ;
;-----------------------------------------------------------------------------
.cseg
;*******************************************************
;*******************************************************
;** **
;** CODE SEGMENT **
;** **
;*******************************************************
;*******************************************************
.org 0
rjmp ResetProcessor ;
;-----------------------------------------------------------------------------
.org INT0addr ;External Interrupt0 Vector Address
reti ;
;-----------------------------------------------------------------------------
.org INT1addr ;External Interrupt1 Vector Address
reti ;
;-----------------------------------------------------------------------------
.org ICP1addr ;Input Capture1 Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org OC1Aaddr ;Output Compare1A Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org OC1Baddr ;Output Compare1B Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org OVF1addr ;Overflow1 Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org OVF0addr ;Overflow0 Interrupt Vector Address
rjmp TC0OvfInterrupt ;
;-----------------------------------------------------------------------------
.org SPIaddr ;SPI Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org URXCaddr ;UART Receive Complete Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org UDREaddr ;UART Data Register Empty Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org UTXCaddr ;UART Transmit Complete Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
.org ACIaddr ;Analog Comparator Interrupt Vector Address
reti ;
;-----------------------------------------------------------------------------
HardwareInit : ;
;**************** ;
ldi acc,Stand_GIMSK ;
out GIMSK,acc ;
ldi acc,Stand_TIMSK ;
out TIMSK,acc ;
ldi acc,Stand_MCUCR ;
out MCUCR,acc ;
ldi acc,Stand_TCCR0 ;
out TCCR0,acc ;
ldi acc,Stand_TCCR1A ;
out TCCR1A,acc ;
ldi acc,Stand_TCCR1B ;
out TCCR1B,acc ;
ldi acc,Stand_UCR ;
out UCR,acc ;
ldi acc,Stand_UBBR ;
out UBRR,acc ;
ret ;
;-----------------------------------------------------------------------------
EnvirInit : ;
;**************** ;
ldi acc,Stand_PADir ;
out DDRA,Acc ;
ldi acc,Stand_PAData ;
out PORTA,acc ;
ldi acc,Stand_PBDir ;
out DDRB,Acc ;
ldi acc,Stand_PBData ;
out PORTB,acc ;
ldi acc,Stand_PCDir ;
out DDRC,Acc ;
ldi acc,Stand_PCData ;
out PORTC,acc ;
ldi acc,Stand_PDDir ;
out DDRD,Acc ;
ldi acc,Stand_PDData ;
out PORTD,acc ;
ret ;
;-----------------------------------------------------------------------------
SoftwareInit : ;
;**************** ;
ldi acc,0 ;
sts TimeDivider,acc ;
sts Status,acc ;
ret ;
;-----------------------------------------------------------------------------
TC0OvfInterrupt : ;
;**************** ;
pushf ;
pushz ;
ldz TimeDivider ;
ld acc,Z ;
inc acc ;
st Z,acc ;
cpi acc,DivideConst ;
brne TC0OV_0 ;
ldi acc,0 ;
st Z,acc ;
ldz Status ;
ld acc,Z ;
inc acc ;
st Z,acc ;
neg acc ;
out PORTB,acc ;
TC0OV_0 : ;
ldi acc,TimerData ;
out TCNT0,acc ;
popz ;
popf ;
reti ;
;-----------------------------------------------------------------------------
ClearRegs : ;
;**************** ;
clr R0 ;
ldz 0x1D ;
ClrR_0 : ;
st Z,R0 ;
dec Zl ;
brne ClrR_0 ;
ret ;
;-----------------------------------------------------------------------------
ClearRAM : ;
;*************** ;
ldz RAMEND-1 ;
clr acc ;
CleRA_0 : ;
st -Z,acc ;
;
cpi ZH,0 ;
brne CleRA_2 ;
cpi ZL,0x60 ;
brne CleRA_2 ;
rjmp CleRA_1 ;
CleRA_2 : ;
rjmp CleRA_0 ;
CleRA_1 : ;
ret ;
;-----------------------------------------------------------------------------
ResetProcessor : ;
cli ;
ldi acc,HIGH(RAMEND) ;
out SPH,acc ;
ldi acc,LOW(RAMEND) ;
out SPL,acc ;
;
rcall ClearRAM ;
rcall ClearRegs ;
rcall HardwareInit ;
rcall EnvirInit ;
rcall SoftwareInit ;
sei ;
Main_0 : ;
rjmp Main_0 ;
;
;-----------------------------------------------------------------------------
.exit
Już udostępnione, można ściągać http://www.elektronika.qs.pl/arch.html#asmJak widać, formatowanie słabo działa i z tego mało widać. Może Wojtek to udostępni na swojej witrynie.
(...)
JacekR napisał:
Witam
BUUUUUUUUUUU ale to jest jeszcze czarna magia (niestety)
ja mam podstawy przerwan tylko z bascoma
Myslalem o krotkiej teori typu co z czym kiedy i dlaczego
ale nic sprobuje to rozgryzc
Właśnie nawyki z bascoma
Program pod bascomem obsługujący działanie sterownika:
DZIALAJ
PRZERWANIE
NIE_DZIALAJ
KONIEC
Oczywiście był to żart
Program tego typu w bascomie wyprodukować może przy dobrych wiatrach 1MB kodu i spowodować przepełnienie stosu.
Witam
BUUUUUUUUUUU ale to jest jeszcze czarna magia (niestety)
ja mam podstawy przerwan tylko z bascoma
Myslalem o krotkiej teori typu co z czym kiedy i dlaczego
ale nic sprobuje to rozgryzc
Właśnie nawyki z bascoma
Program pod bascomem obsługujący działanie sterownika:
DZIALAJ
PRZERWANIE
NIE_DZIALAJ
KONIEC
Oczywiście był to żart
Program tego typu w bascomie wyprodukować może przy dobrych wiatrach 1MB kodu i spowodować przepełnienie stosu.
Kto jest online
Użytkownicy przeglądający to forum: Obecnie na forum nie ma żadnego zarejestrowanego użytkownika i 11 gości