握手程序:
//---------------接收蓝牙校验信息-------------------------------
void bluetooth_hand(){
uart1_RXirt_open(); //允许接收
while(!bus_start); //开始接收
while(bus_start); //等待接收完毕
uart1_RXirt_close(); //停止接收
}
校验程序:
//---------------验证蓝牙校验信息-------------------------------
int bluetooth_cmp(){
int a=0;
for(a=0;a<9;a++){
if(uart1_rec_temp[a]==a+49){ } //校验码123456789
else{
break;
}
}
if(a<9){
return 1; //校验错误
}else{
return 0; //校验正确
}
}
校验信息根据实际情况设定数组
主函数逻辑:
//....................
while(1){ //模式判断
if(mode==0){ //校验模式
while(1){
P2OUT=BIT7;
bluetooth_hand();
btcmp=bluetooth_cmp();
if(btcmp==0){
mode=1;
//Success();
P2OUT=BIT6;
//Sending();
break;
}else{
//Error();
mode=0;
}
}
}else if(mode==1){ //传送模式,连发2次数据后需要再次给出校验指令
//......................
}
}