求一个51单片机程序,通过串口发送“hello,I'm STC89C52!”一行字符,通过电脑接收
其实很简单的帮你写一个参考程序:晶振:11.0592 波特率9600
/*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**/
#include "REG52.H"
/*
* 按键定义
*/
//
unsigned char TABLE[] = "hello,I'm STC89C52";
unsigned char UARTByte;
//
void UART_Send_Byte(unsigned char Byte);
//延时
void Delay_1ms(unsigned int time)
{
unsigned int a, b;
for(a=time; a>0; a--)
for(b=110; b>0; b--);
}
/*
* 主函数
*/
int main(void)
{
unsigned char i;
PCON&= 0x7F;
TCON = 0x00;
SCON = 0x50;
//
TMOD = 0x20;
TH1 = 0xFD;
TL1 = 0xFD;
TR1 = 1;
ES = 1;
EA = 1;
//
while(1)
{
for(i = 0; i < 17; i++)
{
UART_Send_Byte(TABLE[i]);
}
UART_Send_Byte('\n');
Delay_1ms(1000);
}
}
// 向串口发送一个字节数据
void UART_Send_Byte(unsigned char Byte)
{
ES = 0;
TI = 0;
SBUF = Byte;
while(!TI);
TI = 0;
ES = 1;
}
谢谢!