STC12C5A60S2的UART问题
用串口助手可以看到接收到39个字节,但是就是没显示出来,用16进制看的话,都是00,不知道原因,请教一下#include "STC12C5A60S2.h"#include "intrins.h"
#include <string.h>
typedef unsigned char uchar;
typedef unsigned int uint;
#define FOSC 16034000
#define BAUD 9600
//sbit bite9 = P1^1;
bit busy;
void UART_Send_Byte(unsigned char mydata);
void UART_Send_Enter();
void UART_Send_Str(char *s);
void UART_Put_Num(unsigned long dat);
void UART_Put_Inf(char *inf,unsigned long dat);
void u32tostr(unsigned long dat,char *str)
{
char temp;
unsigned char i=0,j=0;
i=0;
while(dat)
{
temp=dat%10+0x30;
i++;
dat/=10;
}
j=i;
for(i=0;i<j;i++)
{
str=temp;
}
if(!i) {str='0';}
str=0;
}
void main()
{
PCON &= 0x7F;
SCON = 0x50;
TMOD &= 0x0F; //清除定时器1模式位
TMOD |= 0x20; //设定定时器1为8位自动重装方式
TH1 = TL1 = (FOSC/12/32/BAUD);
TR1 = 1;
ES = 1;
EA = 1;
UART_Send_Str("STC12C5A60S2");
while(1)
{
}
}
void uart()interrupt 4 using 3
{
ES=0;
ES=1;
}
void UART_Send_Byte(unsigned char mydata)
{
ES=0;
TI=0;
SBUF=mydata;
while(!TI);
TI=0;
ES=1;
}
void UART_Send_Enter()
{
UART_Send_Byte(0x0d);
UART_Send_Byte(0x0a);
}
void UART_Send_Str(char *s)
{
int len=strlen(s)-1;
int i;
for(i=0;i<len;i++)
UART_Send_Byte(s);
if(s=='\n')
{
UART_Send_Enter();
}
else
{
UART_Send_Byte(s);
}
}
void UART_Put_Num(unsigned long dat)
{
char temp;
u32tostr(dat,temp);
UART_Send_Str(temp);
}
void UART_Put_Inf(char *inf,unsigned long dat)
{
UART_Send_Str(inf);
UART_Put_Num(dat);
UART_Send_Str("\n");
}
页:
[1]