51單片機(jī)串口向計(jì)算機(jī)發(fā)送字符串C程序
通過(guò)串口調(diào)試助手可以看到發(fā)送字符信息。波特率為9600
#include
#include
//--------------------------------
char *name_month(int n);
void Delay(int x);
void put(char str);
void initUart(void);
void putString(unsigned char const *pstr);//const
//------------------------------
void put(char str)
{
SBUF=str;
while(!TI);
TI=0;
}
//------------------------------
void initUart(void)
{
TMOD=0x20;
SCON=0x50;
TH1=250;
TL1=250;
TR1=1;
EA = 1;
Delay(2);
putString("Uart init!n");
}
//--------------------------
void Delay(int dly)
{
int j,k;
for (j=0;j
}
//---------------------------------
char *name_month(int n)
{
static char *name[]=
{
"Illegal monthn",
"Januaryn",
"Februaryn",
"Marchn",
"Apriln",
"Mayn",
"Junen",
"Julyn",
"Augustn",
"Septembern",
"Octobern",
"Novembern",
"Decembern"
};
return((n<1||n>12) ? name[0]:name[n]);
}
//------------------------------------
void putString(unsigned char const *pstr)//const
{
while(1)
{
if(*pstr==