📄 main.c
字号:
#include "LMX9820.c"
//#define Device_Max 3 //---Dinh nghia bang dia chi---
// struct addr_table{
// unsigned char bd_addr[6];
// unsigned char bd_ip[3];
// unsigned char RemotePort;
// };
//---Dinh nghia mang device toi da co 3 thiet bi---
//mang Device dung de luu dia chi Bluetooth Addr va Device Class (IP)
//struct addr_table Device[Device_Max];
//Mang DataToSend dung de luu du lieu can gui toi Remote device
int main(void)
{
unsigned char i;
//unsigned char local_port,remote_port;
unsigned char usb_bd_addr[6],save_bd_addr[6];
char DataToSend[4]={'T','e','s','t'};
DDRD|=0x8C; //set pin PD7(ALARM),PD2,PD3 as Output
PORTD=0x00;
PORTD|=0x0C; //set cac Pin PD2, PD3(RTS va CTS),tat ALARLM
//khai bao dia chi cua module bluetooth 1
usb_bd_addr[0]=0x23;
usb_bd_addr[1]=0x3B;
usb_bd_addr[2]=0x65;
usb_bd_addr[3]=0xE8;
usb_bd_addr[4]=0x00;
usb_bd_addr[5]=0x10;
UART_Init(23); //khoi tao UART:baud 9600
//----------------------------------------------------------------------------------------------------------------------------
/*Thuc hien Reset module va kiem tra xem module co hoat dong khong, neu ko thi bat den ALARM*/
//for( i=0; i<TIME_OUT;i++) /*---Truoc khi bat dau, Reset Module Blue---*/
// {
// _delay_ms(1000); //Tre 1s
Reset_Module(); //Reset
// if (Get_Data_From_Module()==TRUE) //Neu Reset thanh cong
// break;
// else{
// if(i==(TIME_OUT-1)) goto ALARM; //Neu ma sau 10 lan Reset ma van chua duoc thi set chan ALARM
// }
// }
/*-------------------------------------------------------------------------------------------------------------------------*/
/*Tim kiem cac thiet bi xung quanh*/
/*
_delay_ms(1000);
Search_Device();
i=0;
while((Get_Data_From_Module()==FALSE)&&(i<TIME_OUT)) //Neu chua nhan duoc du lieu thi khong thoat khoi vong lap
{
_delay_ms(1000);
if(i==TIME_OUT-1) goto ALARM;
i++;
}
i=0;
//Neu ma nhan duoc du lieu phan hoi tu Remote device
while(Get_Data_From_Module())
{
switch(Receive_Cmd[2])
{
case GAP_DEVICE_FOUND:
Get_Device_Found(Device[i].bd_addr, Device[i].bd_ip);
i++;
break;
case GAP_INQUIRY:
break;
default: break;
}
}
*/
//------------------------------------------------------------------------------
//Thiet lap ket noi toi cac Remote Bluetooth
/*for(int j=0;j<Device_Max;j++)*/
// {
/*Khai bao dia chi cua USB Bluetooth*/
//Create_SDAP_Connection(bd_addr); //tao ket noi SDAP
//Get_Data_From_Module();
//while(!SDAP_Confirm()); //doi den khi co Confirm
//SDAP_Service_Browse(); //Browse cac Service
//Get_Data_From_Module(); //Doi phan hoi tu Module
//while(!SDAP_Service_Confirm(&Device[j].RemotePort)); //luu trang thai cong cua Remote device de dung cho ket noi SPP Link
//Dong thoi doi Confirm cua lenh Service Browse
//SDAP_Disconnect(); //Ngat ket noi SDAP
//Get_Data_From_Module(); //Doi Confirm tu Module
//while(!SDAP_Disconnect_Confirm()); //Doi Confirm cua SDAP Disconnect
// KETNOI:
Create_SPP_Link(usb_bd_addr,0x01,0x01); //ket noi SPP voi usb Remote Device qua cong 1
// _delay_ms(1000);
// Get_Data_From_Module(); //Read Establish Link Confirm
// if(SPP_Link_Confirm(&local_port)==FALSE) goto KETNOI; //Doi confirm, bien local_port dung de luu Port cua Local Module
// Get_Data_From_Module(); //Read PORT Status Change Indication
// Get_Data_From_Module(); //Read Link Establish Indication
// if(SPP_Link_Indication(save_bd_addr,&local_port,&remote_port)==FALSE)goto KETNOI;
//-----------------------------------------------------------------------Send Data toi cac module----------------------------------------------------------------------
while(1)
{
Send_Data_To_Remote(1,4,DataToSend);
//Get_Data_From_Module();
//while(1)
// {
// Send:
//temp[0]=Receive_Byte_From_UART();
//Send_Byte_To_UART('!');
//if(Get_Data_From_Module()==FALSE)goto ALARM; //Exit neu nhan dung du lieu
//_delay_ms(1000);
}
// if(Get_Data_From_Module()==FALSE)goto Send; //send data confirm
// }
//ALARM:{} //do nothing
// PORTD|=0x80; //Turn OFF Alarm
// for(int j=0;j<=50;j++)
// {
// _delay_ms(1000);//
// PORTD&=0x7F; // bat den Alarm
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -