void SendStr(unsigned char *s);
void SendByte(unsigned char dat);
/*------------------------------------------------
串口初始化
------------------------------------------------*/
void InitUART (void)
{
SCON = 0x50; // SCON: 模式 1, 8-bit UART, 使能接收
TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit 重装
TH1 = 0xF4; // TH1: 重装值2400波特率 晶振 11.0592MHz
TR1 = 1; // TR1: timer 1 打开
EA = 1; //打开总中断
//ES = 1; //打开串口中断
}
void InitEINT(void)
{
EA=1; //全局中断开
EX0=1; //外部中断0开
IT0=1; //边沿触发
EX1=1; //外部中断0开
IT1=1; //边沿触发
}
/*------------------------------------------------
发送一个字节
------------------------------------------------*/
void SendByte1(unsigned char dat)
{
SBUF = dat;
while(!TI);
TI = 0;
}
/*------------------------------------------------
发送一个字符串
------------------------------------------------*/
void SendStr(unsigned char *s)
{
while(*s!='\0'){
SendByte1(*s);
s++;
}
}
/*------------------------------------------------
外部中断程序
------------------------------------------------*/
void ISR_Key0(void) interrupt 0 using 1
{
char s[4];
char a=(char)tt/10;
char b=(char)tt%10;
s[0]=a;
s[1]=b;
s[2]='c';
s[3]='\0';
SendStr(s);
}
|