51单片机与蓝牙模块的串口通信
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include <>
#include <>
#include<>
#include ""
#include ""
#define uint unsigned int
#define uchar unsigned char
#define Nop() _nop_()
sbit P10 = P1^0; /*定义独立对地按键端口*/
sbit P11 = P1^1; /*定义独立对地按键端口*/
sbit P12 = P1^2; /*定义独立对地按键端口*/
sbit P13 = P1^3; /*定义独立对地按键端口*/ 592MHz TL1=0XFD ;
TH0=0;
TL0=0;
TR1 = 1; // timer 1 run
SCON = 0x50; //UART为模式1,8位数据,允许接收 PCON |= 0x80 ; //SMOD=1; Baud加倍
IE |= 0x90 ; //Enable Serial Interrupt
TR1 = 1 ; // timer 1 run
EA=1;
ET0=1;
}
void send(uchar cc)
{
SBUF=cc;
while(TI==0);
TI=0;
}
void send_f(uchar ccc)
{
send(' ');
send('<');
send('F');
send(ccc);
send('>');
}
void call_out()
{
uchar i;
send('(');
for(i=0;i { send(CallOut_Num[i]); } send(')'); m=0; } void interrupt_pro() { string_write(0,1,reci_buff); lcd_char_write(14,1,mun_to_char[temp/10]); //for test lcd_char_write(15,1,mun_to_char[temp%10]); //for test if(temp==')') CallIn_flag=1;//|temp=='$' |temp=='%' else if(temp=='$'){ lcd_delay(5);//if(temp=='$') string_write(0,0,clr); string_write(0,0,reci_buff);} else switch(temp) { case 'X':string_write(0,0,clr);string_write(0,0,"Disconnet");break; case 'P':string_write(0,0,clr);string_write(0,0,"Pairing"); break; case 'S':string_write(0,0,clr);string_write(0,0,"Linking"); break; case 'O':string_write(0,0,clr);string_write(0,0,"Connect"); break; case 'R':string_write(0,0,clr);string_write(0,0,"Ring"); //string_write(5,0,CallIn_Num); break; case 'D':string_write(0,0,clr);string_write(0,0,"Ding"); // string_write(5,0,CallIn_Num); break; case 'I':string_write(0,0,clr);string_write(0,0,"Talking"); break; case 'L':string_write(0,0,clr);string_write(0,0,"Call failed"); break; case 'A':string_write(0,0,clr);string_write(0,0,"MP3 playing"); break; case 'E':string_write(0,0,clr);string_write(0,0,"Call release "); break; case 'H':string_write(0,0,clr);string_write(0,0,"A2DP connected ");break; case 'V':string_write(0,0,clr);string_write(0,0,"A2DP disconnected");break; // case ')':x=0; break; //for(i=0;i<16;i++) lcd_char_write(i,1,lcd_table[i]); /*显示标题*/ default:break; } //temp='?'; //for test } void key_pro() { uchar i,key_value_buff; key_value_buff = key_scan(); if(key_value_buff != 0) //有按键动作 { switch(key_value_buff) /*显示按键*/ { case 0x18: //0 if(call_flag) {CallOut_Num[m]='0';lcd_char_write(m+2,0,'0');m++;} else if(!shift_flag) { send(' ');send('A'); //Answer lcd_char_write(3,1,'0'); //可以不显示出来 lcd_char_write(8,1,'A'); lcd_char_write(9,1,' '); } else { send_f('P'); lcd_char_write(3,1,'0'); lcd_char_write(8,1,'F'); lcd_char_write(9,1,'P'); } break; case 0x28://1 if(call_flag) {CallOut_Num[m]='1';lcd_char_write(m+2,0,'1');m++;} else if(!shift_flag) { send(' ');send('H'); //Hang up lcd_char_write(3,1,'1'); lcd_char_write(8,1,'H'); lcd_char_write(9,1,' '); } else { send_f('L');