uart.c

#includevoid uart_set()

{

SCON = 0x50;

TMOD = 0x20;            //Set Timer1 as 8-bit auto reload mode

    TH1 = TL1 = -(FOSC/12/32/BAUD); //Set auto-reload vaule

    TR1 = 1;                //Timer1 start run

    ES = 1;                //Enable UART interrupt

    EA = 1;                //Open master interrupt switch

}

void SendData(BYTE dat)

{

    while (busy);          //Wait for the completion of the previous data is sent

    ACC = dat;              //Calculate the even parity bit P (PSW.0)

    busy = 1;

    SBUF = ACC;            //Send data to UART buffer

}

void SendString(char *s)

{

    while (*s)              //Check the end of the string

    {

        SendData(*s++);    //Send current char and increment string ptr

    }

}

void Uart_Isr() interrupt 4 using 1

{

    if (RI)

    {

        RI = 0;            //Clear receive interrupt flag

        rec = SBUF;          //P0 show UART data

//SBUF=rec+0x01;

//P2.2 show parity bit

    }

    if (TI)

    {

        TI = 0;            //Clear transmit interrupt flag

        busy = 0;          //Clear transmit busy flag

    }

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,419评论 0 10
  • 正上
    杨炫宇阅读 252评论 0 0
  • 走路与不走路的人,隔一天看,没有任何区别;隔一个月看差异甚微;隔一年看,差距明显;隔五年看的时侯,就是身体和精神状...
    虚怀若谷8阅读 374评论 0 0
  • 上周回老家,急着去深圳北站赶高铁,滴滴打车来不及了,便叫了路边的一辆的士。司机说不打表,收费25元,你去就去,不去...
    原野花开阅读 2,936评论 7 11