功能
(1)通過(guò)LCD12864顯示GPS模塊的經(jīng)緯度數(shù)據(jù);
(2)可設(shè)定當(dāng)前的定位位置,自動(dòng)計(jì)算與設(shè)定位置的距離,當(dāng)檢測(cè)到位置超過(guò)設(shè)定位置200M時(shí),通過(guò)GPRS模塊發(fā)送報(bào)警信息;
(3)報(bào)警時(shí)通過(guò)通過(guò)蜂鳴器發(fā)出警報(bào);
(4)根據(jù)位置自動(dòng)計(jì)算定位的距離,當(dāng)找到兒童時(shí),成人可主動(dòng)關(guān)閉警報(bào)器;
(5)可實(shí)現(xiàn)“一一鍵報(bào)警”功能,當(dāng)按下按鍵時(shí),主動(dòng)發(fā)送當(dāng)前的位置給設(shè)定的手機(jī)號(hào);
(6)當(dāng)找到兒童時(shí),可手動(dòng)取消報(bào)警。
系統(tǒng)框圖
原理圖
程序源代碼
#include "project.h" unsigned char ucMode = 0; unsigned char xdata Longitude[13] = "E:"; //保存經(jīng)度數(shù)據(jù) unsigned char xdata Latitude[13] = "N:";//保存緯度數(shù)據(jù) bit PosSuc = 0; //定位成功的標(biāo)志,為1時(shí)表示定位成功,為0表示定位不成功 double fLongitude = 0.0; //保存浮點(diǎn)型數(shù)據(jù),經(jīng)度 double fLatitude = 0.0; //保存浮點(diǎn)型數(shù)據(jù), 緯度 double fLongitudeLoa = 0.0; //當(dāng)前所在地的經(jīng)度 double fLatitudeLoa = 0.0; //當(dāng)前所在地的緯度 double Dis = 0.0; #define PI 3.1415926 #define EARTH_RADIUS 6378.004 //地球近似半徑 // 求弧度 double radian(double d) { return d * PI / 180.0; //角度1? = π / 180 } //計(jì)算距離 double get_distance(double lat1, double lng1, double lat2, double lng2) { xdata double radLat1 = radian(lat1); xdata double radLat2 = radian(lat2); xdata double a = radLat1 - radLat2; xdata double b = radian(lng1) - radian(lng2); xdata double dst = 2 * asin((sqrt(pow(sin(a / 2), 2) + cos(radLat1) * cos(radLat2) * pow(sin(b / 2), 2) ))); dst = dst * EARTH_RADIUS; //dst= round(dst * 10000) / 10000; return dst; } /********************************************************************************************************* ** 函數(shù)名稱: ProcRxBuf ** 函數(shù)描述: 處理GPS接收的數(shù)據(jù) ** 輸入參數(shù): NONE ** 輸出參數(shù): NONE ** 返回值: NONE *********************************************************************************************************/ void ProcRxBuf(void) { if(RxFlag == 1) //數(shù)據(jù)接收完畢 { EA = 0; RxFlag = 0; if(RxBuf[17] == 'A') { ucMode = 1; if(PosSuc == 0) //初次定位成功 { fLongitudeLoa = fLongitude; //當(dāng)前所在地的經(jīng)度 fLatitudeLoa = fLatitude; //當(dāng)前所在地的緯度 fLongitudeLoa = fLongitude; //當(dāng)前所在地的經(jīng)度 fLatitudeLoa = fLatitude; //當(dāng)前所在地的緯度 PosSuc = 1; } LCD_Location(1,0); LCD_Display(" GPS 定位成功 "); PosSuc = 1; //定位成功標(biāo)志置1 Latitude[0] = 'N'; Latitude[1] = ':'; fLatitude = (double)atof(&RxBuf[21]) / (double)60.0 + (RxBuf[19] - 0x30)*10 + (RxBuf[20]- 0x30); Latitude[12] = 0; Latitude[2] = (unsigned long)fLatitude %100 / 10 + 0x30; Latitude[3] = (unsigned long)fLatitude % 10+ 0x30; Latitude[4] = '.'; Latitude[5] = (unsigned long)(fLatitude * 10) % 10+ 0x30; Latitude[6] = (unsigned long)(fLatitude * 100) % 10+ 0x30; Latitude[7] = (unsigned long)(fLatitude * 1000) % 10+ 0x30; Latitude[8] = (unsigned long)(fLatitude * 10000) % 10+ 0x30; Latitude[9] = (unsigned long)(fLatitude * 100000) % 10+ 0x30; Latitude[10] = (unsigned long)(fLatitude * 1000000) % 10+ 0x30; Latitude[11] = (unsigned long)(fLatitude * 10000000) % 10+ 0x30; Latitude[12] = 0; Longitude[0] = 'E'; Longitude[1] = ':'; fLongitude = (double)atof(&RxBuf[34]) / (double)60.0 + (RxBuf[31] - 0x30)*100 + (RxBuf[32]- 0x30) * 10 + (RxBuf[33]- 0x30); Longitude[2] = (unsigned long)fLongitude / 100 + 0x30; Longitude[3] = (unsigned long)fLongitude %100 / 10 + 0x30; Longitude[4] = (unsigned long)fLongitude % 10+ 0x30; Longitude[5] = '.'; Longitude[6] = (unsigned long)(fLongitude * 10) % 10+ 0x30; Longitude[7] = (unsigned long)(fLongitude * 100) % 10+ 0x30; Longitude[8] = (unsigned long)(fLongitude * 1000) % 10+ 0x30; Longitude[9] = (unsigned long)(fLongitude * 10000) % 10+ 0x30; Longitude[10] = (unsigned long)(fLongitude * 100000) % 10+ 0x30; Longitude[11] = (unsigned long)(fLongitude * 1000000) % 10+ 0x30; Longitude[12] = 0; } else { PosSuc = 0; //定位成功標(biāo)志清零 } memset(RxBuf,0,80); RxWP = 0; EA = 1; } } bit Key1Up = 1; //按鍵松開標(biāo)志,為1時(shí)表示按鍵已經(jīng)松開,為0時(shí),表示按鍵未松開 sbit KEY1 = P3^4; //按鍵,按下按鍵時(shí)發(fā)送定位信息到手機(jī) sbit KEY2 = P3^5; //按鍵,按下按鍵時(shí)存儲(chǔ)正確的定位信息 /********************************************************************************************************* ** 函數(shù)名稱: SendHelp ** 函數(shù)描述: 發(fā)送求救信息 ** 輸入?yún)?shù): NONE ** 輸出參數(shù): NONE ** 返回值: NONE *********************************************************************************************************/ void SendHelp(double Dis) { unsigned char i = 0; xdata unsigned char ucTemp[45] = {0}; for(i = 0; i < 13;i++) { ucTemp[i] = Latitude[i]; } for(i = 0; i < 13; i++) { ucTemp[i+12] = Longitude[i]; } strcat(ucTemp,"distance="); ucTemp[33] = ((unsigned long)Dis % 100 / 10 + 0x30); ucTemp[34] = ((unsigned long)Dis %10 + 0x30); ucTemp[35] = ('.'); ucTemp[36] = ((unsigned long)(Dis * 10) % 10 + 0x30); ucTemp[37] = ((unsigned long)(Dis * 100) % 10 + 0x30); ucTemp[38] = ((unsigned long)(Dis * 1000) % 10 + 0x30); ucTemp[39] = 'k'; ucTemp[40] = 'm'; SendSMS(ucTemp,41); //發(fā)送手機(jī)短信 DelayMs(1000); UART1_ClearRxBuf(); } /********************************************************************************************************* ** 函數(shù)名稱: ProcKey ** 函數(shù)描述: 處理按鍵函數(shù),按鍵按下時(shí)發(fā)送定位信息到手機(jī) ** 輸入?yún)?shù): NONE ** 輸出參數(shù): NONE ** 返回值: NONE *********************************************************************************************************/ void ProcKey1(void) { if( (Key1Up == 1) && (KEY1 == 0)) //按鍵處于松開狀態(tài)時(shí),按鍵按下,定位完成才判斷按鍵 { DelayMs(20); //防抖動(dòng)延時(shí) if(KEY1 == 0) { Key1Up = 0; if(PosSuc == 1) { SendHelp(Dis); } else if(PosSuc == 0) { LCD_Location(3,0); LCD_Display("請(qǐng)等定位成功 "); DelayMs(2000); LCD_Location(3,0); LCD_Display(" "); } } } else if(KEY1 == 1) { Key1Up = 1; } }
-
單片機(jī)
+關(guān)注
關(guān)注
6030文章
44489瀏覽量
631974 -
gps
+關(guān)注
關(guān)注
22文章
2880瀏覽量
165925 -
GPRS
+關(guān)注
關(guān)注
21文章
983瀏覽量
129300 -
程序
+關(guān)注
關(guān)注
116文章
3756瀏覽量
80751
原文標(biāo)題:【011】基于51單片機(jī)、GPS、GPRS的兒童防丟失系統(tǒng)(源代碼、原理圖、參考論文、演示視頻等)
文章出處:【微信號(hào):精通單片機(jī)與嵌入式,微信公眾號(hào):精通單片機(jī)與嵌入式】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論