|
用stm32f103c8t6單片機(jī)和hc-08藍(lán)牙模塊實(shí)現(xiàn)一個(gè)雛形物聯(lián)網(wǎng)功能新手剛接觸,程序?qū)懙牟缓玫牡胤秸?qǐng)指教,勿噴,謝謝
手機(jī)連接是hc-08藍(lán)牙模塊后,輸入初始密碼,正確后單片機(jī)通過串口給手機(jī)發(fā)一個(gè)密碼正確,然后你可以在手機(jī)上發(fā)送開燈,單片機(jī)上的LED燈亮,手機(jī)顯示LED亮...也可以在手機(jī)上,輸入更改密碼,單片機(jī)發(fā)送先輸入初始密碼,正確后輸入新密碼,然后密碼修改成功。
因?yàn)檫@個(gè)中文顯示亂碼,我不知道怎么解決,所以放2張截屏圖片。
藍(lán)牙控?zé)?rar
(313.54 KB, 下載次數(shù): 131)
2019-3-15 14:43 上傳
點(diǎn)擊文件名下載附件
- //////////////////////////////////////////////////////////////////////////////////
- //本程序只供學(xué)習(xí)使用,未經(jīng)作者許可,不得用于其它任何用途
- //版權(quán)所有,盜版必究。
- //
- //
- //////////////////////////////////////////////////////////////////////////////////
- #include "stm32f10x.h"
- //#include "led.h"
- //#include "key.h"
- //#include "usart.h"
- //#include "timer.h"
- #include "bluetooth.h"
- int main(void)
- {
- //char ch;
- /*獲取數(shù)據(jù)*/
- LED_Init();
- // USART1_Initialise(9600);
- USART_Config1();
- TIM3_Int_Init(999,71);
- printf("請(qǐng)輸入密碼\r\n如果修改密碼請(qǐng)輸入 更改密碼\r\n");
- //USART1_SendStr( USART1,"這是一個(gè)哈哈哈實(shí)驗(yàn)\n");
- while(1)
- {
- pd();
- jg();
- quit();
- }
- }
復(fù)制代碼
- #include "bluetooth.h"
- //////////////////////////////////////////////////////////////////////////////////
- //本程序只供學(xué)習(xí)使用,未經(jīng)作者許可,不得用于其它任何用途
- //修改日期:2019.1.1
- //版權(quán)所有,盜版必究。
- //
- //
- //////////////////////////////////////////////////////////////////////////////////
- uint16_t j;
- u8 BackData[255];
- char hh[]="哈哈";
- u8 count;
- u8 TIME3_ON;
- u8 i,passwordPIN_flag=0,ok=0,correct_flag1=0;
- char dengl[]="開燈";
- char dengm[]="關(guān)燈";
- char baoj[]="報(bào)警";
- char guanb[]="關(guān)閉";
- char out[]="退出";
- u8 out_flag=0;
- char mima[]="更改密碼";
- char old_mima[6]="888888";
- char* read_data;
- void clean_rebuff(void)
- {
- while(i)
- BackData[--i] = 0;
- }
- void Change_password()
- {
- if(strstr(read_data,mima) != 0)
- {
- passwordPIN_flag=1;
- printf("請(qǐng)輸入舊密碼\r\n");
- ok=0;
- }
- if(passwordPIN_flag==1)
- {
- if(ok==1)
- {
- if((BackData[0]==old_mima[0])&&(BackData[1]==old_mima[1])&&(BackData[2]==old_mima[2])&&(BackData[3]==old_mima[3])&&(BackData[4]==old_mima[4])&&(BackData[5]==old_mima[5]))
- {
- printf("請(qǐng)輸入新密碼\r\n");
- passwordPIN_flag = 2;
- clean_rebuff();
- ok=0;
- }
- else
- {
- passwordPIN_flag=1;
- printf("密碼錯(cuò)誤 \r\n");
- }
- }
- }
- if(passwordPIN_flag==2)
- {
- if(ok==1)
- {
- old_mima[0]=BackData[0];
- old_mima[1]=BackData[1];
- old_mima[2]=BackData[3];
- old_mima[3]=BackData[3];
- old_mima[4]=BackData[5];
- old_mima[5]=BackData[5];
- printf("密碼修改成功\r\n");
- printf("新密碼為%s\r\n ", old_mima);
- printf("請(qǐng)輸入密碼 \r\n");
- ok=0;
- passwordPIN_flag=0;
- }
- }
- }
- void Input_password()
- {
- if(passwordPIN_flag==0)
- {
- if(ok==1)
- {
- if((BackData[0]==old_mima[0])&&(BackData[1]==old_mima[1])&&(BackData[2]==old_mima[2])&&(BackData[3]==old_mima[3])&&(BackData[4]==old_mima[4])&&(BackData[5]==old_mima[5]))
- {
- correct_flag1 =1;
- printf("密碼正確 \r\n可輸入 開燈 關(guān)燈 報(bào)警 關(guān)閉報(bào)警\r\n或者退出\r\n ");
- ok=0;
- passwordPIN_flag=3;
- }
- else
- {
- passwordPIN_flag=0;
- printf("密碼錯(cuò)誤 \r\n");
- out_flag=0;
- }
-
- }
- }
- }
- void quit()
- {
- if(strstr(read_data,out) != 0)
- {
- correct_flag1=0;
- out_flag=1;
- passwordPIN_flag=0;
- printf("您已成功退出 \r\n");
- printf("請(qǐng)輸入密碼 \r\n");
- ok=0;
- Input_password();
- }
- }
- void pd()
- {
- if(count > 5)
- {
- Change_password();
- Input_password();
- count = 0;
- TIME3_ON = 0;
- clean_rebuff();
- }
- }
- void choice()
- {
- //u8 sum;
- if(correct_flag1 == 1)
- {
- if(strstr(read_data,dengl) != 0)
- {
- LED0=0;
- printf("led亮 \r\n");
- }
- if(strstr(read_data,dengm) != 0)
- {
- LED0=1;
- printf("led滅 \r\n");
- }
- if(strstr(read_data,baoj) != 0)
- {
-
- bee=1;
- //GPIO_SetBits(GPIOB,GPIO_Pin_9);
- printf("以報(bào)警 \r\n");
- }
- if(strstr(read_data,guanb) != 0)
- {
- bee=0;
- printf("以關(guān)閉報(bào)警 \r\n");
- }
- }
- }
- void jg()
- {
- if(correct_flag1==1)
- {
- choice();
- }
- }
- void USART2_IRQHandler(void)
- {
- if(USART_GetITStatus(DEBUG_USARTx2, USART_IT_RXNE) != RESET)//判斷讀寄存器是否非空
- {
- TIME3_ON = 1;
- ok=1;
- BackData[i] = USART_ReceiveData(DEBUG_USARTx2);
- i++;
- read_data = (char *) & BackData;
- count = 0;
- }
- }
復(fù)制代碼
|
-
-
評(píng)分
-
查看全部評(píng)分
|