浓毛老太交欧美老妇热爱乱,蜜臀性色av免费,妺妺窝人体色www看美女,久久久久久久久久久大尺度免费视频,麻豆人妻无码性色av专区

位置:51電子網(wǎng) » 技術(shù)資料 » 單 片 機(jī)

用AVR單片機(jī)模擬的串口程序

發(fā)布時(shí)間:2008/8/12 0:00:00 訪問(wèn)次數(shù):666

  在一些應(yīng)用中,經(jīng)常要用到雙串口,但是一般單片機(jī)只提供一個(gè)串口,其實(shí)完全可以用普通i/o口模擬一個(gè)串口。以下的程序是我編寫(xiě)的模擬串口程序,程序中使用了單片機(jī)的定時(shí)器0,和int0中斷。數(shù)據(jù)的發(fā)送和接收由中斷程序自動(dòng)進(jìn)行。程序已經(jīng)過(guò)avr仿真器仿真和實(shí)際燒片使用,證明可靠。有一點(diǎn)需要說(shuō)明的是,此模擬的串口為半雙工方式。


  主程序中,單片機(jī)將標(biāo)準(zhǔn)串口設(shè)置為115200bps,將模擬串口設(shè)置為19200bps。單片機(jī)將標(biāo)準(zhǔn)串口收到的數(shù)據(jù)從模擬串口發(fā)送出去,將模擬串口接收到的數(shù)據(jù)從標(biāo)準(zhǔn)串口發(fā)送回來(lái)。

txd0_data:
ldi status,(1<
push temp
in temp,gimsk
cbr temp,(1< out gimsk,temp ;disable gimsk/int0
pop temp

ser bit_cnt ;bit_cnt=0xff
mov sbuf0,temp ;send data

ldi temp,(256-n)
out tcnt0,temp ;wait 1 bit timer0 interrupt

in temp,tifr
sbr temp,(1< out tifr,temp ;clr tifr/tov0

in temp,timsk
sbr temp,(1< out timsk,temp ;enable timsk/toie0

cbi portb,txd0 ;uart start

ret
;******************************************
rxd0_data:
sbrs status,fe0 ;if fe0=0 then exit
rjmp rxd0_data_end
cbr status,(1< mov temp,sbuf0
rxd0_data_end:
ret
;******************************************

;uart received a byts from uart and then return it from uart0:
;uart received a byts from uart0 and then return it from uart :
main:
sbic usr,rxc
rjmp send_115200

sbrs status,rdr
rjmp uart_end
send_19200:
rcall rxd0_data ;get uart data from 19200bps uart0

wait2: sbis usr,udrie
rjmp wait2
out udr,temp ;send data to 115200bps uart
rjmp uart_end

send_115200:
in temp,udr ;get uart data from 115200bps uart
sbic usr,fe
rjmp uart_end ;if fe err then end

wait3: sbrc status,td ;wait send flag
rjmp wait3
rcall txd0_data ;send data to 19200bps uart0
uart_end:
rjmp main



  在一些應(yīng)用中,經(jīng)常要用到雙串口,但是一般單片機(jī)只提供一個(gè)串口,其實(shí)完全可以用普通i/o口模擬一個(gè)串口。以下的程序是我編寫(xiě)的模擬串口程序,程序中使用了單片機(jī)的定時(shí)器0,和int0中斷。數(shù)據(jù)的發(fā)送和接收由中斷程序自動(dòng)進(jìn)行。程序已經(jīng)過(guò)avr仿真器仿真和實(shí)際燒片使用,證明可靠。有一點(diǎn)需要說(shuō)明的是,此模擬的串口為半雙工方式。


  主程序中,單片機(jī)將標(biāo)準(zhǔn)串口設(shè)置為115200bps,將模擬串口設(shè)置為19200bps。單片機(jī)將標(biāo)準(zhǔn)串口收到的數(shù)據(jù)從模擬串口發(fā)送出去,將模擬串口接收到的數(shù)據(jù)從標(biāo)準(zhǔn)串口發(fā)送回來(lái)。

txd0_data:
ldi status,(1<
push temp
in temp,gimsk
cbr temp,(1< out gimsk,temp ;disable gimsk/int0
pop temp

ser bit_cnt ;bit_cnt=0xff
mov sbuf0,temp ;send data

ldi temp,(256-n)
out tcnt0,temp ;wait 1 bit timer0 interrupt

in temp,tifr
sbr temp,(1< out tifr,temp ;clr tifr/tov0

in temp,timsk
sbr temp,(1< out timsk,temp ;enable timsk/toie0

cbi portb,txd0 ;uart start

ret
;******************************************
rxd0_data:
sbrs status,fe0 ;if fe0=0 then exit
rjmp rxd0_data_end
cbr status,(1< mov temp,sbuf0
rxd0_data_end:
ret
;******************************************

;uart received a byts from uart and then return it from uart0:
;uart received a byts from uart0 and then return it from uart :
main:
sbic usr,rxc
rjmp send_115200

sbrs status,rdr
rjmp uart_end
send_19200:
rcall rxd0_data ;get uart data from 19200bps uart0

wait2: sbis usr,udrie
rjmp wait2
out udr,temp ;send data to 115200bps uart
rjmp uart_end

send_115200:
in temp,udr ;get uart data from 115200bps uart
sbic usr,fe
rjmp uart_end ;if fe err then end

wait3: sbrc status,td ;wait send flag
rjmp wait3
rcall txd0_data ;send data to 19200bps uart0
uart_end:
rjmp main



相關(guān)IC型號(hào)

熱門(mén)點(diǎn)擊

 

推薦技術(shù)資料

硬盤(pán)式MP3播放器終級(jí)改
    一次偶然的機(jī)會(huì)我結(jié)識(shí)了NE0 2511,那是一個(gè)遠(yuǎn)方的... [詳細(xì)]
版權(quán)所有:51dzw.COM
深圳服務(wù)熱線:13751165337  13692101218
粵ICP備09112631號(hào)-6(miitbeian.gov.cn)
公網(wǎng)安備44030402000607
深圳市碧威特網(wǎng)絡(luò)技術(shù)有限公司
付款方式


 復(fù)制成功!