51單片機串口向計算機發(fā)送字符串C程序
通過串口調(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==看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();