uart.c

作者: 雪融4泪珠 | 来源:发表于2018-02-26 12:53 被阅读0次

#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

    }

}

相关文章

  • uart.c

    #includevoid uart_set() { SCON = 0x50; TMOD = 0x20; ...

网友评论

      本文标题:uart.c

      本文链接:https://www.haomeiwen.com/subject/dyfexftx.html