新闻中心

EEPW首页>嵌入式系统>设计应用> 用AVR单片机模拟的串口程序

用AVR单片机模拟的串口程序

作者: 时间:2012-06-26 来源:网络 收藏

>>>>>>>>>>>>>>>>>>>>>>>>>>
;receivestart1bitdata8bitstop1bit
timer0_receive:
cpibit_cnt,1;ifbit_cnt=1thenstartbit
breqtimer0_receive_start
cpibit_cnt,10;ifbit_cnt=10thenstopbit
breqtimer0_receive_stop

rjmptimer0_receive_data
timer0_receive_start:
sbispind,rxd0
rjmptimer0_end

cbrstatus,(1rdr);startbitwrongthenrdr=0exit
rjmptimer0_complete
timer0_receive_data:
sec
sbispind,rxd0;getrxd0data
clc
rorsbuf0
rjmptimer0_end
timer0_receive_stop:
cbrstatus,(1fe0);ifstopbit=0thenfe0=0
sbispind,rxd0
rjmptimer0_complete
sbrstatus,(1fe0)
sbrstatus,(1rdr);rdr=1
;>>>>>>>>>>>>>>>>>>>>>>>>>>
timer0_complete:
intemp,timsk
cbrtemp,(1toie0)
outtimsk,temp;disabletimsk/toie0
;;;;;;;;;;;;;;;;;;;
intemp,gifr
sbrtemp,(1intf0)
outgifr,temp;clrint0flag

intemp,gimsk
sbrtemp,(1int0)
outgimsk,temp;enablegimsk/int0

cbrstatus,(1busy)|(1td);busy=0,td=0
timer0_end:
poptemp
outsreg,temp
poptemp

reti
;******************************************
int00:
pushtemp
intemp,sreg
pushtemp

lditemp,(256-N/2);skip0.5bit
outTCNT0,temp

ldistatus,(1busy);busy=1,rdr=0,td=0,fe0=0
clrbit_cnt

intemp,tifr
sbrtemp,(1tov0)
outtifr,temp;clrtifr/tov0

intemp,timsk
sbrtemp,(1toie0)
outtimsk,temp;enabletimsk/toie0

intemp,gimsk
cbrtemp,(1int0)
outgimsk,temp;disablegimsk/int0

poptemp
outsreg,temp
poptemp
reti
;**********************************************************

rxd0_data:
txd0_data:
ldistatus,(1busy)|(1td);busy=1,td=1,rdr=0

pushtemp
intemp,gimsk
cbrtemp,(1int0)
outgimsk,temp;disablegimsk/int0
poptemp

serbit_cnt;bit_cnt=0xff
movsbuf0,temp;senddata

lditemp,(256-N)
outTCNT0,temp;wait1bittimer0interrupt

intemp,tifr
sbrtemp,(1tov0)
outtifr,temp;clrtifr/tov0

intemp,timsk
sbrtemp,(1toie0)
outtimsk,temp;enabletimsk/toie0

cbiportb,txd0;uartstart

ret
;******************************************
rxd0_data:
sbrsstatus,fe0;iffe0=0thenexit
rjmprxd0_data_end
cbrstatus,(1rdr);rdr=0
movtemp,sbuf0
rxd0_data_end:
ret
;******************************************

;uartreceivedabytsfromuartandthenreturnitfromuart0:
;uartreceivedabytsfromuart0andthenreturnitfromuart:
main:
sbicusr,rxc
rjmpsend_115200

sbrsstatus,rdr
rjmpuart_end
send_19200:
rcallrxd0_data;getuartdatafrom19200bpsuart0

wait2:sbisusr,udrie
rjmpwait2
outudr,temp;senddatato115200bpsuart
rjmpuart_end

send_115200:
intemp,udr;getuartdatafrom115200bpsuart
sbicusr,fe
rjmpuart_end;iffeerrthenend

wait3:sbrcstatus,td;waitsendflag
rjmpwait3
rcalltxd0_data;senddatato19200bpsuart0
uart_end:
rjmpmain
;**********************************************************
.exit
;**********************************************************


上一页 1 2 下一页

评论


相关推荐

技术专区

关闭