标题: 赛元单片机验证OK的串口收发程序 [打印本页]

作者: 打杂的    时间: 2024-5-18 11:23
标题: 赛元单片机验证OK的串口收发程序
他们芯片必须手动加载芯片H头文件,或者按照示范代码操作

#include <SC95F876x_C.H>
#define uchar unsigned char
#define uint unsigned int
        
void Uart1_send()
{
        P2CON = 0xfc;   //TX/RX设置为输入带上拉
        P2PH = 0xff;
        TXINX = 0X02;   //指向定时器2
        SCON|=0x50;        //串口模式1,允许接收
        TXCON |= 0X00;        //UART0时钟来源为定时器1
        TMCON |= 0x02;  //T1频率源自于fsys
        TH1=0X0D;        //波特率9600
        TL1=0x05;
        TR1=0;//开定时器1中断
        ET1=0;
        EA = 1;//开总中断
        EUART = 1;//开串口中断        
}
void Send_string(uchar byte1)
{
                SBUF=byte1;
                while(TI==0);
                TI=0;
}
void main()
{
        P0CON = 0xFF;  //设置P0为强推挽模式
        P0PH  = 0x00;
        Uart1_send();
        while(1)
{

  }

}
//串口接收中断函数
void Serial_INT() interrupt 4
{
                if(TI) //UART0发送中断
        {
                TI = 0;               
        }
        if(RI==1) //UART0接收中断
        {
                Send_string(SBUF);
                RI = 0;        
        }

}






欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1