|
/*
名稱:?jiǎn)纹瑱C(jī)向主機(jī)發(fā)送字符串
說(shuō)明:?jiǎn)纹瑱C(jī)按一定時(shí)間間隔向主機(jī)發(fā)送字符串,發(fā)送內(nèi)容在虛擬終端顯示
并顯示在數(shù)碼管上
*/
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
//延時(shí)
void DelayMS(uint ms)
{
uchar i;
while(ms--)for(i=0;i<120;i++);
}
//向串口發(fā)送字符
void Putc_to_SerialPort(uchar c)
{
SBUF=c;
while(TI==0);
TI=0;
}
//向串口發(fā)送字符
void Puts_to_SerialPort(uchar *s)
{
while(*s!='\0')
{
Putc_to_SerialPort(*s);
s++;
DelayMS(5);
}
}
//主程序
void main()
{
uchar c=0;
SCON=0x40;//串口模式1
TMOD=0x20;//T1工作模式2
TH1=0xfd; //波特率9600
TL1=0xfd;
PCON=0x00;//波特率不倍增
TI=0;
TR1=1;
DelayMS(200);
//向主機(jī)發(fā)送數(shù)據(jù)
Puts_to_SerialPort("Receiving From 8051...\r\n");
Puts_to_SerialPort("-------------------------------\r\n");
DelayMS(50);
while(1)
{
Putc_to_SerialPort(c+'A');
DelayMS(100);
Putc_to_SerialPort(' ');
DelayMS(100);
if(c==25)//每輸出一遍后加橫線
{
Puts_to_SerialPort("\r\n-------------------------------\r\n");
DelayMS(100);
}
c=(c+1)%26;
if(c%10==0)
{
Puts_to_SerialPort("\r\n");
DelayMS(100);
}
}
}
單片機(jī)向主機(jī)發(fā)送字符串.zip
(22.87 KB, 下載次數(shù): 14)
2020-5-11 17:42 上傳
點(diǎn)擊文件名下載附件
|
|