?? 串口通信.c
字號:
/***********************************************************************************/
/* 程序名:發(fā)送字符 */
/* */
/* 晶振:12.0 M CPU型號:AT89S52 */
/* */
/* */
/* 功能描述: */
/* */
/* */
/* 網(wǎng)址:http://www.mcu-arm.cn */
/* 郵箱:mcu-arm2007@163.com
/* QQ技術群:2056101 */
/* */
/* */
/* 創(chuàng)靈電子工作室 版權所有 */
/* 2007-12-20 */
/************************************************************************************/
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar Send_M[] = { 'W', 'l', 'c', 'o', 'm', 'e',' ','t','o',' ','c','h','a','n','g',' ','l',
'i','n','g','!',0x0d,0x0a,0x00};
/********************************************************************************************
* 函數(shù)名稱:Delay()
* 功 能:軟件延時
* 入口參數(shù):無符號的整型變量
* 出口參數(shù):無
*********************************************************************************************/
void Delay(uint t)
{
uchar i ;
while(t--)
{
for(i = 0;i <125;i++)
{;}
}
}
/********************************************************************************************
* 函數(shù)名稱:Timer0Init()
* 功 能:定時器初始化程序
* 入口參數(shù):無
* 出口參數(shù):無
*********************************************************************************************/
void Timer0Init(void) //初始化定時器0程序
{
TMOD = 0x20; //
TH1 = 0xfd; //給TH1,TL1賦初始值
TL1 = 0xfd;
TR1 = 1; //啟動定時器1
}
/********************************************************************************************
* 函數(shù)名稱:main()
* 功 能:主函數(shù)
* 入口參數(shù):無
* 出口參數(shù):無
*********************************************************************************************/
void main(void)
{
uchar i;
SCON = 0xd8;PCON = 0x00;
Timer0Init();
while(1)
{
i = 0;
while(Send_M[i] != 0x00)
{
SBUF = Send_M[i];
while(TI == 0);
TI = 0;
i++;
}
Delay(1000);
Delay(1000);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -