📄 serial.c
字号:
#include "my_89x51.h"
uint tcount;
bit timeout;
/*********************************************/
//串口初始化SERMODE=1(多机通讯模式)SERMODE=0(8位工作模式)
/*********************************************/
/*
void serial_init()
{
serial_baud_2400;
serial_uart_9;
SM2 = 1;
RI = 0;
serial_receive_enable;
}
*/
/*********************************************/
//串行接受:返回0-正确,返回1-超时
/*********************************************/
bit s_in(uchar data *pbuf)
{
tcount = 0;
timeout = 0;
timer0_run;
while(1){
if (RI){
*pbuf = SBUF;
RI = 0;
break;
}
else{
if (timeout)
break;
}
}
timer0_stop;
return timeout;
}
/*********************************************/
//串行接受:返回0-正确,1-错误
/*********************************************/
/*
bit serial_in(uchar *pbuf)
{
uchar temp;
while(!s_in(&temp))
{
s_in(&temp);
*pbuf = temp;
pbuf ++;
}
return(1);
}
*/
/*********************************************/
//串行发送
/*********************************************/
void s_out(uchar ndata)
{
TI = 0;
tcount = 0;
timeout = 0;
timer0_run;
SBUF = ndata;
while(TI == 0){
if (timeout)
break;
}
timer0_stop;
}
/*********************************************/
//串行发送
/*********************************************/
//void serial_out(uchar data *pbuf, uchar nlen)
void serial_out(uchar *pbuf)
{
while(1)
{
if( *pbuf == '0')
break;
s_out(*pbuf);
pbuf ++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -