/*无线通讯语言模块测试·PAST 2020 1 15 L142 CODE2257**/
#include <REG52.H>
#include <intrins.H>
#include "stdio.h"
#define uint unsigned int
#define uchar unsigned char
uchar s;
sbit OUT1=P3^2; /****输出***/
sbit OUT2=P3^4; /****输出***/
sbit MD0MD1=P5^4;
uchar DAT2=0;
bit Receive_Flag;
/*---------------延时子程序----------------*/
void delay1 (uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<200;j++)
;
}
/*------------初始化串口---------------------*/
void InitUart()
{
SCON=0X50; //8位数据,可变波特率
AUXR|=0x01; //串口1选择定时器2为波特率发生器
AUXR|=0X04; //定时器2时钟为Fosc,即1T
T2L=0XE0; //设置定时器处置 110592》9600
T2H=0XFE; //设置定时器处置 110592》9600
AUXR|=0X10; //启动定时器2
TI=1;
ES=1; //
EA=1;
}
void change(uchar DAT)
{
switch(DAT)
{
case 1:printf("1");break;
case 2:printf("2");break;
case 3:printf("3");break;
case 4:printf("4");break;
case 5:printf("5");break;
case 6:printf("6");break;
case 7:printf("7");break;
case 8:printf("8");break;
case 9:printf("9");break;
case 10:printf("十");break;
case 11:printf("十1");break;
case 12:printf("十2");break;
case 13:printf("十3");break;
case 14:printf("十4");break;
case 15:printf("十5");break;
case 16:printf("十6");break;
case 17:printf("十7");break;
case 18:printf("十8");break;
case 19:printf("十9");break;
case 20:printf("2十");break;
case 21:printf("2十1");break;
case 22:printf("2十2");break;
case 23:printf("2十3");break;
case 24:printf("2十4");break;
case 25:printf("2十5");break;
case 26:printf("2十6");break;
case 27:printf("2十7");break;
case 28:printf("2十8");break;
case 29:printf("2十9");break;
case 30:printf("3十");break;
case 31:printf("3十1");break;
case 32:printf("3十2");break;
case 33:printf("3十3");break;
case 34:printf("3十4");break;
case 35:printf("3十5");break;
case 36:printf("3十6");break;
case 37:printf("3十7");break;
case 38:printf("3十8");break;
case 39:printf("3十9");break;
case 40:printf("4十");break;
case 41:printf("4十1");break;
case 42:printf("4十2");break;
case 43:printf("4十3");break;
case 44:printf("4十4");break;
case 45:printf("4十5");break;
case 46:printf("4十6");break;
case 47:printf("4十7");break;
case 48:printf("4十8");break;
case 49:printf("4十9");break;
case 50:printf("5十");break;
default: break;
}
}
/*--------UART 中断服务程序----Buff=SBUF---------------*/
void Uart() interrupt 4 using 1
{
if(RI)
{
DAT2=SBUF; //数组下标位置的数据等于j
RI=0; //
Receive_Flag=1; //接收数据标志置一
}
}
/*------------------主循环程序----------------*/
void main( ) /*主程序开始*/
{ /**加一**/
AUXR=0X80; //STC系列的1T 设置
TMOD=0X01;
delay1(2000);
delay1(2000);
InitUart(); //初始化串口
MD0MD1=0; //
printf("<Z>6"); //音效
printf("<V>3"); //音量
printf("<S>3"); //语速
delay1(200);
OUT1=0;
OUT2=0;
delay1(2000);
OUT1=1;
OUT2=1;
P_SW1=0x40; //RXD_2/P3.6, TXD_2/P3.7
printf("系统启动中");
delay1(2000);
P_SW1=0x00; //RXD/P3.0, TXD/P3.1
delay1(2000);
Receive_Flag=0; //接收数据标志置零
while(1)
{
if(Receive_Flag==1)
{
OUT1=0;
OUT2=0;
P_SW1=0x40; //RXD_2/P3.6, TXD_2/P3.7
delay1(200);
change(DAT2);
printf("号机报警,请及时处理 ");
delay1(2000);
OUT1=1;
OUT2=1;
P_SW1=0x00; //RXD/P3.0, TXD/P3.1
Receive_Flag=0; //接收到数据标志置零
}
}
}