📄 sci_com.h
字号:
/***************************************************************************
FUNCTION: static void Execute_Command_SCI0(const char *cmd)
PURPOSE: 串口0对接收到的字符串,执行命令
****************************************************************************/
static void Execute_Command_SCI0(const char *cmd)
{
}
//串口0中断
interrupt void SCI0_ISR(void)
{
static char command[20]; /* enough to hold "stop" or a single digit number */
static unsigned char i=0; /* index into command */
unsigned char rc;
ulong error_count = 0;
rc = SCI0SR1; /* dummy read to clear flags */
rc = SCI0DRL; /* data read */
if (i >= sizeof(command)-1 || rc == '!')
{
command[i] = '\0';
i = 0;
Execute_Command_SCI0(command);
}
else
{
command[i] = rc;
i++;
}
// SCI0DRL = rc;
}
//串口1中断
interrupt void SCI1_ISR(void)
{
uchar rc = 0;
rc = SCI1SR1; /* dummy read to clear flags */
rc = SCI1DRL; /* data read */
}
static void Write_To_SCI0(const char *text)//输出字符串
{
ulong error_count = 0;
while (*text != '\0')
{
SCI0DRL = *text++;
while (!(SCI0SR1 & 0x80)) // wait for output buffer empty
{
error_count++;
if(error_count >= TIME_OUT)//操作超时
break;
}
error_count = 0;
}
SCI0DRL = '\0';
while (!(SCI0SR1 & 0x80)) // wait for output buffer empty
{
error_count++;
if(error_count >= TIME_OUT)//操作超时
break;
}
error_count = 0;
}
void Write_To_SCI0_DATA(uint data)//把数字转化为数字字符
{
ulong error_count = 0;
char i,temp = 0;
for(i=12;i>=0;i = i-4)
{
temp = (data>>i)&0x000F;
SCI0DRL = (temp<10 ? temp+48 : temp+55);
while (!(SCI0SR1 & 0x80)) // wait for output buffer empty
{
error_count++;
if(error_count >= TIME_OUT)//操作超时
break;
}
error_count = 0;
}
}
void Write_To_SCI0_DATA_ASCII(uint data)//发送数字!!!先发送高8位
{
ulong error_count = 0;
SCI0DRL = data>>8;
while (!(SCI0SR1 & 0x80)) // wait for output buffer empty
{
error_count++;
if(error_count >= TIME_OUT)//操作超时
break;
}
error_count = 0;
SCI0DRL = data;
while (!(SCI0SR1 & 0x80)) // wait for output buffer empty
{
error_count++;
if(error_count >= TIME_OUT)//操作超时
break;
}
error_count = 0;
}
static void Write_To_SCI1(const char *text)//输出字符串
{
ulong error_count = 0;
while (*text != '\0')
{
SCI1DRL = *text++;
while (!(SCI1SR1 & 0x80)) // wait for output buffer empty
{
error_count++;
if(error_count >= TIME_OUT)//操作超时
break;
}
error_count = 0;
}
SCI1DRL = '\n';
while (!(SCI1SR1 & 0x80)) // wait for output buffer empty
{
error_count++;
if(error_count >= TIME_OUT)//操作超时
break;
}
error_count = 0;
}
void Write_To_SCI1_DATA(uint data)//把数字转化为数字字符
{
ulong error_count = 0;
char i,temp = 0;
for(i=12;i>=0;i = i-4)
{
temp = (data>>i)&0x000F;
SCI1DRL = (temp<10 ? temp+48 : temp+55);
while (!(SCI1SR1 & 0x80)) // wait for output buffer empty
{
error_count++;
if(error_count >= TIME_OUT)//操作超时
break;
}
error_count = 0;
}
}
void Write_To_SCI1_DATA_ASCII(uint data)//发送数字!!!先发送高8位
{
ulong error_count = 0;
/* SCI1DRL = data>>8;
while (!(SCI1SR1 & 0x80)) // wait for output buffer empty
{
error_count++;
if(error_count >= TIME_OUT)//操作超时
break;
}
error_count = 0;*/
SCI1DRL = data;
while (!(SCI1SR1 & 0x80)) // wait for output buffer empty
{
error_count++;
if(error_count >= TIME_OUT)//操作超时
break;
}
error_count = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -