1 #include "reg52.h" 2 #include "ultrasonic.h" 3 #include "serialcommunication.h" 4 5 char begin[] = {" 开始测试(超声波开始)!!!! "}; 6 void main(){ 7 UsartInit(); 8 InitTimer(); 9 sendString(begin); 10 working(); 11 }
1 #include "SerialCommunication.h" 2 3 unsigned int flag = 0; 4 void UsartInit() 5 { 6 SCON |= 0X50; //设置为工作方式1 7 TMOD |= 0X20; //设置计数器工作方式2 8 PCON |= 0X80; //波特率加倍 9 TH1 = 0XF3; //计数器初始值设置,注意波特率是4800的 10 TL1 = 0XF3; 11 ES = 1; //打开接收中断 12 EA = 1; //打开总中断 13 TR1 = 1; //打开计数器 14 } 15 /* 16 发送单个数据 17 */ 18 void sendChar(unsigned char value){ 19 SBUF = value; 20 flag = 1; 21 while(flag); 22 } 23 /* 24 发送字符串 25 */ 26 void sendString(unsigned char *value){ 27 while( (*value)!= '