51 串口通信-发送

#include "reg52.h"		

typedef unsigned int u16;	  
typedef unsigned char u8;

sbit k3 = P3^2;

void UsartInit()
{
//串口通信配置
	SCON=0X50;			
	TMOD=0X20;			
	PCON=0X80;			
	TH1=0XF3;				
	TL1=0XF3;
					
	TR1=1;					
	 IT0=1;  
  //按钮按下去的中断
   EX0=1;  
   EA=1;  
}


void main()
{	
	UsartInit();  
	while(1);		
}

void delay(u16 i)  
{  
    while(i--);   
}  

void Int1() interrupt 0      
{  
    unsigned char i;  
    delay(1000);      
    if(k3==0)  
    {  
	unsigned char word[] = "hello world!"; 
	for(i=0; i<19; i++)  
        {  
            SBUF = word[i];   
            while(!TI);       
            TI=0;       //清除发送完成标志位     
        }  
    }  
} 



猜你喜欢

转载自blog.csdn.net/liunian17/article/details/80071380
今日推荐