có bác nào lập trình cho AVR bằng hợp ngữ ko vậy,cho t hỏi tí chút
các bác kt cho t đoạn code này nha:
.EQU slave=0x01
.EQU chot_kenh=7
.EQU chot_sdv=6
.EQU chot_dv=7
.EQU chot_chuc=6
.EQU chot_tram=5
.EQU chot_ngin=4
.EQU hsb_doi=0x21
.EQU so_chia=0x0A
.EQU enable_TX=4
.EQU led_error=7
.EQU led_auto=4
.EQU rx_error=0xfe
;register
.DEF tam =r16
.DEF tam1 =r17
.DEF auto =r18
.DEF so_du =r4
.DEF kenh_do =r5
.DEF hs_nhan=r6
.NOLIST
.INCLUDE "C:\Documents and Settings\XUAN LAM\Desktop\thu\AVR studio\m16def.inc"
.INCLUDE iodefs.asm
.LIST
.CSEG
.org 0x00
jmp RESET
jmp USART_RX
RESET:
ldi tam, HIGHT(RAMEND) ;
out SPH, tam ;
out ZH, tam
ldi tam, LOW(RAMEND) ;
out SPL, tam ;
out ZL, tam
inc ZL
st Z+, tam ;chua dia chi slave
ldi tam, hsb_doi
mov hs_nhan, tam
;khoi tao cong
;PB0-3 la cac cong vao 3 trang thai
;PB4-7 la cac cong ra so o muc high
ldi tam, (1<<DDB4)|(1<<DDB5)|(1<<DDB6)|(1<<DDB7)
out DDRB, tam
ldi tam, (1<<PB4)|(1<<PB5)|(1<<PB6)|(1<<PB7)
out PORTB, tam
;PD4_7 LA CAC DAU RA SO O MUC HIGH
ldi tam, (1<<DDD4)|(1<<DDD5)|(1<<DDD6)|(1<<DDD7)
out DDRD, tam
ldi tam, (1<<PD4)|(1<<PD5)|(1<<PD6)|(1<<PD7)
out PORTD, tam
;PC LA CAC DAU RA SO;
;PC4_7=1
ser tam
out DDRC, tam
ldi tam, (1<<PC4)|(1<<PC5)|(1<<PC6)|(1<<PC7)
out PORTC, tam
;khoi tao USART nhan voi:
;tu pc truyen 8bit,parity le,1bit stop,khi pc truyen di chi thi bit thu7=1
;du lieu kenh =0, truyen lien tiep 2 byte ma ASSCI
;pc nhan : 8bit du lieu, p le, 1bit stop, nhan lien tuc 7 byte dang ma ASCCI]
;VDK nhan : khoi tao nhan 7bit , p le, 2bit stop, su dung che do da xu ly: MPCM=1
;VDK truyen: khoi tao truyen 8bit du lieu, p le, 1bit stop, bit thu7=0
; truyen7 byte lien tiep: 1byte dia chi slave, 1byte kenh do, 5byte du lieu do.
; tat ca duoi dang ma ASCCI
;khai bao toc do truyen 9600, dat che do da xu ly
ldi tam, 0x33 ;
out UBRRL, tam ;toc do 9600 o tan so thach anh 8MHz
ldi tam, (1<<MCPM) ;
out UCSRA, tam ;dat che do da xu ly
rcall setup_RXn ;goi ctc khoi tao USART_TX
sei
main:
cpi auto, 0x09
brsh automatic
rcall setup_TX
sbic PORTB, led_error
rjmp start_TX
ldi tam, slave
sbi tam, 0b00110000
lsl tam
out UDR, tam
loop1:
sbis UCSRA, UDRE
rjmp loop1
ldi tam, rx_error
out UDR, tam
rjmp exit
start_RX:
cbi PORTB, led_auto
ldi tam1, 7
loop2: ld tam,-Z
sbi tam, 0b00110000
lsl tam
out UDR
loop3: sbrs UCSRA, UDREN
rjmp loop3
dec tam1
brne loop2
exit:
sbi PORTB, led_error
cbi PORTD, enable_TX
rcall setup_RX
rjmp main
automatic:
sbi PORTB, led_auto
rjmp main
;ctc khoi tao bo nhan satup_RX
setup_RX:
push tam
ldi tam, (1<<MPCM)
out UCSRA, tam
ldi tam, (1<<RXCIE)|(1<<RXEN)
out UCSRB, tam
ldi tam, (1<<URSEL)|(1<<UPM1)|(1<<UPM0)|(1<<USBS)|(1<<UCSZ1 )
out UCSRC, tam
pop tam
ret
;ctc khoi tao bo truyen setup_TX
setup_TX:
push tam
ldi tam, (1<<TXEN)
out UCSRB, tam
ldi tam, (1<<URSEL)|(1<<UPM1)|(1<<UPM0)|(1<<USBS)|(3<<UCSZ0 )
out UCSRC, tam
pop tam
ret
;trinh phuc vu ngat USART,RXC
USART_RX:
push tam1
push tam
in SREG, tam
push tam
in tam1, UCSRA
in tam, UDR
sbis UCSRA, MPCM
rjmp data_RX
andi tam1, (1<<FE)|(1<<DOR)|(1<<PE)
breq no_error
exit_RX:
pop tam
out SREG, tam
pop tam
pop tam1
reti
no_error:
cbi tam, 0b00110000
cpi tam, slave
breq sdata_RX
rjmp exit_RX
sdata_RX:
in tam, UCSRA
cbi tam, 0b00000001
out UCSRA, tam
in tam, ADCSRA
cbi tam, 0b110010000 ;ghi cac bi ADN=0,ADSC=0,ADIF=0
out ADCSRA, tam
in tam, GIFR
cbi tam, 0b01000000
out GIFR, tam ;ghi cac bit INT0=0,INTF0=0
out GICR, tam
rjmp exit_RX
data_RX:
andi tam1, (1<<FE)|(1<<DOR)|(1<<PE)
breq data_no_error
cbi PORTB, led_error
sbi PORTD, enable_TX
rjmp exit_RX
data_no_error:
cbi tam, 0b00110000
mov auto, tam
cpi tam, 0x09
brsh exit_RX
mov kenh_do, tam
sbi PORTD, enable_TX
rjmp exit_RX
sao nó cứ báo lỗi hoài vậy. báo lỗi là 'string expected'
các bác kt ho nha, t chẳng tìm thấy lỗi chỗ nào
các bác kt cho t đoạn code này nha:
.EQU slave=0x01
.EQU chot_kenh=7
.EQU chot_sdv=6
.EQU chot_dv=7
.EQU chot_chuc=6
.EQU chot_tram=5
.EQU chot_ngin=4
.EQU hsb_doi=0x21
.EQU so_chia=0x0A
.EQU enable_TX=4
.EQU led_error=7
.EQU led_auto=4
.EQU rx_error=0xfe
;register
.DEF tam =r16
.DEF tam1 =r17
.DEF auto =r18
.DEF so_du =r4
.DEF kenh_do =r5
.DEF hs_nhan=r6
.NOLIST
.INCLUDE "C:\Documents and Settings\XUAN LAM\Desktop\thu\AVR studio\m16def.inc"
.INCLUDE iodefs.asm
.LIST
.CSEG
.org 0x00
jmp RESET
jmp USART_RX
RESET:
ldi tam, HIGHT(RAMEND) ;
out SPH, tam ;
out ZH, tam
ldi tam, LOW(RAMEND) ;
out SPL, tam ;
out ZL, tam
inc ZL
st Z+, tam ;chua dia chi slave
ldi tam, hsb_doi
mov hs_nhan, tam
;khoi tao cong
;PB0-3 la cac cong vao 3 trang thai
;PB4-7 la cac cong ra so o muc high
ldi tam, (1<<DDB4)|(1<<DDB5)|(1<<DDB6)|(1<<DDB7)
out DDRB, tam
ldi tam, (1<<PB4)|(1<<PB5)|(1<<PB6)|(1<<PB7)
out PORTB, tam
;PD4_7 LA CAC DAU RA SO O MUC HIGH
ldi tam, (1<<DDD4)|(1<<DDD5)|(1<<DDD6)|(1<<DDD7)
out DDRD, tam
ldi tam, (1<<PD4)|(1<<PD5)|(1<<PD6)|(1<<PD7)
out PORTD, tam
;PC LA CAC DAU RA SO;
;PC4_7=1
ser tam
out DDRC, tam
ldi tam, (1<<PC4)|(1<<PC5)|(1<<PC6)|(1<<PC7)
out PORTC, tam
;khoi tao USART nhan voi:
;tu pc truyen 8bit,parity le,1bit stop,khi pc truyen di chi thi bit thu7=1
;du lieu kenh =0, truyen lien tiep 2 byte ma ASSCI
;pc nhan : 8bit du lieu, p le, 1bit stop, nhan lien tuc 7 byte dang ma ASCCI]
;VDK nhan : khoi tao nhan 7bit , p le, 2bit stop, su dung che do da xu ly: MPCM=1
;VDK truyen: khoi tao truyen 8bit du lieu, p le, 1bit stop, bit thu7=0
; truyen7 byte lien tiep: 1byte dia chi slave, 1byte kenh do, 5byte du lieu do.
; tat ca duoi dang ma ASCCI
;khai bao toc do truyen 9600, dat che do da xu ly
ldi tam, 0x33 ;
out UBRRL, tam ;toc do 9600 o tan so thach anh 8MHz
ldi tam, (1<<MCPM) ;
out UCSRA, tam ;dat che do da xu ly
rcall setup_RXn ;goi ctc khoi tao USART_TX
sei
main:
cpi auto, 0x09
brsh automatic
rcall setup_TX
sbic PORTB, led_error
rjmp start_TX
ldi tam, slave
sbi tam, 0b00110000
lsl tam
out UDR, tam
loop1:
sbis UCSRA, UDRE
rjmp loop1
ldi tam, rx_error
out UDR, tam
rjmp exit
start_RX:
cbi PORTB, led_auto
ldi tam1, 7
loop2: ld tam,-Z
sbi tam, 0b00110000
lsl tam
out UDR
loop3: sbrs UCSRA, UDREN
rjmp loop3
dec tam1
brne loop2
exit:
sbi PORTB, led_error
cbi PORTD, enable_TX
rcall setup_RX
rjmp main
automatic:
sbi PORTB, led_auto
rjmp main
;ctc khoi tao bo nhan satup_RX
setup_RX:
push tam
ldi tam, (1<<MPCM)
out UCSRA, tam
ldi tam, (1<<RXCIE)|(1<<RXEN)
out UCSRB, tam
ldi tam, (1<<URSEL)|(1<<UPM1)|(1<<UPM0)|(1<<USBS)|(1<<UCSZ1 )
out UCSRC, tam
pop tam
ret
;ctc khoi tao bo truyen setup_TX
setup_TX:
push tam
ldi tam, (1<<TXEN)
out UCSRB, tam
ldi tam, (1<<URSEL)|(1<<UPM1)|(1<<UPM0)|(1<<USBS)|(3<<UCSZ0 )
out UCSRC, tam
pop tam
ret
;trinh phuc vu ngat USART,RXC
USART_RX:
push tam1
push tam
in SREG, tam
push tam
in tam1, UCSRA
in tam, UDR
sbis UCSRA, MPCM
rjmp data_RX
andi tam1, (1<<FE)|(1<<DOR)|(1<<PE)
breq no_error
exit_RX:
pop tam
out SREG, tam
pop tam
pop tam1
reti
no_error:
cbi tam, 0b00110000
cpi tam, slave
breq sdata_RX
rjmp exit_RX
sdata_RX:
in tam, UCSRA
cbi tam, 0b00000001
out UCSRA, tam
in tam, ADCSRA
cbi tam, 0b110010000 ;ghi cac bi ADN=0,ADSC=0,ADIF=0
out ADCSRA, tam
in tam, GIFR
cbi tam, 0b01000000
out GIFR, tam ;ghi cac bit INT0=0,INTF0=0
out GICR, tam
rjmp exit_RX
data_RX:
andi tam1, (1<<FE)|(1<<DOR)|(1<<PE)
breq data_no_error
cbi PORTB, led_error
sbi PORTD, enable_TX
rjmp exit_RX
data_no_error:
cbi tam, 0b00110000
mov auto, tam
cpi tam, 0x09
brsh exit_RX
mov kenh_do, tam
sbi PORTD, enable_TX
rjmp exit_RX
sao nó cứ báo lỗi hoài vậy. báo lỗi là 'string expected'
các bác kt ho nha, t chẳng tìm thấy lỗi chỗ nào
Comment