/**
*时间:2014年3月15日 07:32:22
*作者:寒竹子
**/
#include
typedef unsigned int uint;
typedef unsigned char uchar;
bit cmdAddrived = 0;//收到下发命令的标志
uchar cmd = 0;//上位机下发的命令
uchar cnt;//发送字节的个数
uchar * sendStr = "";//单片机发送的数据指针
//预定义待发送的数据
uchar * pstr1 = "Welcome to MCU!
";
uchar * pstr2 = "www*Kingst*odg
";
uchar * pstr3 = "Welcome to STM-32!
";
uchar * pstr4 = "www*chuxue123*cdm
";
void UART_Config(uint baud);
void UART_sendByte(uchar dat);
void UART_sendString(uchar * pstr);
uchar UART_recieved();
void recievedByComputer();
void main()
{
UART_Config(9600);
while (1)
{
recievedByComputer();
}
}
//串口波特率配置
void UART_Config(uint baud)
{
SCON |= 0x50;
/*
SM0 = 0;
SM1 = 1;
REN = 1;
TI = 0;
RI = 0;
*/
TMOD &= 0x0F;//清零T1控制位
TMOD |= 0x20;//T1方式2,八位自动重装
TH1 = 256-(11059200/12/32/baud);
TL1 = TH1;
TR1 = 1;
}
//send Byte
void UART_sendByte(uchar dat)
{
SBUF = dat;
while (!TI);
TI = 0;
REN = 1;//允许接收
}
//send String
void UART_sendString(uchar * pstr)
{
while (*pstr != '