新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 用AVR單片機模擬的串口程序

        用AVR單片機模擬的串口程序

        作者: 時間:2012-06-26 來源:網(wǎng)絡(luò) 收藏

        >>>>>>>>>>>>>>>>>>>>>>>>>>
        ;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 下一頁

        關(guān)鍵詞: AVR單片機 串口程序 模擬

        評論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 大悟县| 萍乡市| 正镶白旗| 永昌县| 吉林市| 涿州市| 仙桃市| 湾仔区| 鄯善县| 广宗县| 瑞昌市| 图们市| 乳山市| 泽库县| 北辰区| 龙泉市| 大石桥市| 浙江省| 南丰县| 泗洪县| 安泽县| 新乐市| 任丘市| 甘谷县| 重庆市| 阿勒泰市| 怀集县| 武冈市| 壶关县| 禄劝| 夏津县| 大连市| 大理市| 巴彦县| 余庆县| 曲沃县| 巧家县| 南和县| 同江市| 刚察县| 顺平县|