#include <stc12c5a60s2.h>
#define uint unsigned int
#define uchar unsigned char
#define S2RI 0x01 //S2CON.1
#define S2TI 0x02 //S2CON.2
#define S2RB8 0x04 //S2CON.3
#define S2TB8 0x08 //S2CON.4
uchar num[]="ATD110;\r\n";
/*========发送字符串================*/
void Com2_send_string(uchar *p)
{
while (*p != '\0')
{
S2BUF=*p;
while(!(S2CON&S2TI));
S2CON &= ~S2TI;
p++;
}
}
/*==========串口配置===============*/
void Uart2Init() //
{
AUXR &= 0xf7; //波特率不倍速 auxr=0x08
S2CON = 0x50; //8位数据,可变波特率 方式一
BRT = 0xfd; //设定独立波特率发生器重装值
AUXR |= 0x04; //独立波特率发生器时钟为Fosc/12,即12T BRTX12=1
AUXR |= 0x10; //启动独立波特率发生器 BRTR=1
IE2=0x01; //中断允许
EA=1;
}
/*==============串口中断===============*/
void Uart2() interrupt 8 using 1
{
if (S2CON & S2RI) //如果有数据到来
{
S2CON &= ~S2RI; //接收完毕标志清零
}
if(S2CON & S2TI); //如果发送完毕
{
S2CON &= ~S2TI; //发送完毕标志清零
}
}
//延时函数
void delay(uchar z)
{
uchar x, y;
for(x = 0; x<110; x++)
for(y = 0; y<z; y++);
}
void main()
{
Uart2Init();
while(1)
{
Com2_send_string(num);
delay(5);
}
} |