串口助手下發(fā)命令~單片機(jī)回傳不同的數(shù)據(jù)
/**
*時(shí)間:2014年3月15日 07:32:22
*作者:寒竹子
**/
#include
typedef unsigned int uint;
typedef unsigned char uchar;
bit cmdAddrived = 0;//收到下發(fā)命令的標(biāo)志
uchar cmd = 0;//上位機(jī)下發(fā)的命令
uchar cnt;//發(fā)送字節(jié)的個(gè)數(shù)
uchar * sendStr = "";//單片機(jī)發(fā)送的數(shù)據(jù)指針
//預(yù)定義待發(fā)送的數(shù)據(jù)
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,八位自動(dòng)重裝
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 !=