新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 51單片機(jī)串口向計(jì)算機(jī)發(fā)送字符串C程序

51單片機(jī)串口向計(jì)算機(jī)發(fā)送字符串C程序

作者: 時(shí)間:2016-11-17 來(lái)源:網(wǎng)絡(luò) 收藏
51單片機(jī)串口向計(jì)算機(jī)發(fā)送字符串C程序,本布衣實(shí)驗(yàn)過(guò)的,可以用,串口需有一個(gè)232-TTL電平轉(zhuǎn)換
通過(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 for(k=0;k<125;k++);
}
//---------------------------------
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==