日本高清不卡中文字幕-一起草草视频在线观看-亚洲精品一区二区三区色-国产亚洲精品免费视频

你好!歡迎來到深圳市穎特新科技有限公司!
語言
當前位置:首頁 >> 技術(shù)中心 >> 單片機入門 >> 89C52單片機串行通信編程兩則

89C52單片機串行通信編程兩則

關(guān)鍵字:89C52 單片機 串行通信 編程 作者:admin 來源:不詳 發(fā)布時間:2018-05-18  瀏覽:13

1.當89C52串行口按工作方式1進行串行數(shù)據(jù)通信時,假定波特率為1 200b/s,以中斷方式傳送數(shù)據(jù),請編寫全雙工通信程序。

#include <at89x52.h>

unsigned char data txbuf;

unsigned char data rebuf;

 

void main()

{

unsigned char temp;

SCON=0x50;

TMOD=0x20;

TH1=0xE8;

TL1=0xE8;

TR1=1;

ES=1;

EA=1;

}

 

void comre()

{

    rebuf=SBUF;

}  

 

void comtx()

{

    SBUF=txbuf;

}   

 

void serial_server() interrupt 4              

{

       if(TI)                    

           TI=0;

       else                      

       {

           RI=0;

           comre();                      

       }

}

 

2.當89C52串行口按工作方式3進行串行數(shù)據(jù)通信時,假定波特率為1 200b/s,第9位數(shù)據(jù)作奇偶校驗位,以中斷方式傳送數(shù)據(jù),請編寫通信程序。

#include <at89x52.h>

unsigned char data txbuf;

unsigned char data rebuf;

 

void main()

{

unsigned char temp;

SCON=0xd0;

TMOD=0x20;

TH1=0xE8;

TL1=0xE8;

TR1=1;

ES=1;

EA=1;

}

 

void comre()

{

    ACC=SBUF;

    if(RB8==P)

        rebuf=ACC;

    else

        error();

}  

 

void comtx()

{

    ACC=txbuf;

SBUF=ACC;

    TB8=P;

}   

 

void serial_server() interrupt 4              

{

       if(TI)                    

           TI=0;

       else                      

       {

           RI=0;

           comre();                      

       }

}

 

void error()

{

    F0=1;

}


編輯:admin  最后修改時間:2018-05-18

聯(lián)系方式

0755-82591179

傳真:0755-82591176

郵箱:vicky@yingtexin.net

地址:深圳市龍華區(qū)民治街道民治大道973萬眾潤豐創(chuàng)業(yè)園A棟2樓A08

Copyright © 2014-2023 穎特新科技有限公司 All Rights Reserved.  粵ICP備14043402號-4