sim800c+GPS芯片
一個練手的小設計,有點丑哈。附上程序和原理PcB圖。
第一次發帖,做的不好煩請原諒哈
按鍵功能一個按鍵報警,蜂鳴器響,另外一個按鍵發送短信到指定的手機上,手機號碼程序里面寫好就行了
單片機源程序如下:
- #include "common.h"
- #include "uart.h"
- #include "gps.h"
- #include "gsm.h"
- #include "lcd.h"
- #define GPS_STR_LEN 48
- uchar ess_inc;
- //char xdata GPS_SEND_STR[GPS_STR_LEN];
- sbit key = P1^3;
- sbit key1 = P1^4;
- sbit GPS_EN=P3^4;
- sbit led1 = P3^3;
- #define RMC_YES led1 = 0
- #define RMC_NO led1 = 1
- GPS_INFO GPS; //GPS信息結構體
- bit GPS_rx_flag = 0;
- bit GPS_Have_flag = 0;
- #define SEND_NUMBER "AT+CMGS=\"13420106297\"\r\n"
- char xdata send_data[37]="N: ',E: ',2000-00-00,00:00\r\n";
- unsigned char send_len= 0;
- bit dis_flag = 1;
- bit sendflag=0;
- /****************************************
- 顯示時間
- /****************************************/
- void GPS_DispTime(void)
- {
- uchar i = 0;
- uchar ch;
- char time[5];
- Int_To_Str(GPS.D.year,time);//年
- LCD1602_Set_AC(0, 1);
- i = 0;
- send_len = 18;
- while(time[i] != '\0')
- {
- ch = time[i++];
- LCD1602_write_data(ch);
- send_data[send_len++] = ch;
- }
- LCD1602_write_data('-');
-
- Int_To_Str(GPS.D.month,time);//月
- LCD1602_Set_AC(5, 1);
- i = 0;
- send_len = 23;
- while(time[i] != '\0')
- {
- ch = time[i++];
- LCD1602_write_data(ch);
- send_data[send_len++] = ch;
- }
- LCD1602_write_data('-');
-
- Int_To_Str(GPS.D.day,time);//日
- LCD1602_Set_AC(8, 1);
- i = 0;
- send_len = 26;
- while(time[i] != '\0')
- {
- ch = time[i++];
- LCD1602_write_data(ch);
- send_data[send_len++] = ch;
- }
- LCD1602_write_data(',');
-
- Int_To_Str(GPS.D.hour,time);//時
- LCD1602_Set_AC(11, 1);
- i = 0;
- send_len = 29;
- while(time[i] != '\0')
- {
- ch = time[i++];
- LCD1602_write_data(ch);
- send_data[send_len++] = ch;
- }
- LCD1602_write_data(':');
- Int_To_Str(GPS.D.minute,time);//分
- LCD1602_Set_AC(14, 1);
- i = 0;
- send_len = 32;
- while(time[i] != '\0')
- {
- ch = time[i++];
- LCD1602_write_data(ch);
- send_data[send_len++] = ch;
- }
- }
- void GPS_DisplayOne(void)
- {
- uchar len,ch, i;
- char info[10];
- ess_inc = 0;
- // memset(GPS_SEND_STR, 0, GPS_STR_LEN);
- if (GPS.NS == 'N') //判斷是北緯還是南緯
- {
- if(dis_flag)
- LCD1602_DisplayChar(0, 0, 'N');
- else
- LCD1602_DisplayChar(0, 0, ' ');
- // GPS_SEND_STR[ess_inc ++] = 'N';
- len = 0;
- Int_To_Str(GPS.latitude_Degree,info); //緯度
- LCD1602_Set_AC(1, 0);
- i = 0;
- send_len = 2;
- while(info[i] != '\0')
- {
- ch = info[i++];
- if(dis_flag)
- LCD1602_write_data(ch);
- else
- LCD1602_write_data(' ');
- send_data[send_len++] = ch;
- // GPS_SEND_STR[ess_inc ++] = ch;
- len ++;
- }
- send_data[send_len++] = 'd';
- if(dis_flag)
- LCD1602_write_data(0xDF);
- else
- LCD1602_write_data(' ');
- // GPS_SEND_STR[ess_inc ++] = 'd';
- len ++;
- Int_To_Str(GPS.latitude_Cent,info); //緯分
- i = 0;
- while(info[i] != '\0')
- {
- ch = info[i++];
- if(dis_flag)
- LCD1602_write_data(ch);
- else
- LCD1602_write_data(' ');
- send_data[send_len++] = ch;
- // GPS_SEND_STR[ess_inc ++] = ch;
- len ++;
- }
- if(dis_flag)
- LCD1602_write_data(0x27);
- else
- LCD1602_write_data(' ');
- // GPS_SEND_STR[ess_inc ++] = 'm';
- Int_To_Str(GPS.latitude_Second,info); //緯秒
- i = 0;
- while(info[i] != '\0')
- {
- ch = info[i++];
- // GPS_SEND_STR[ess_inc ++] = ch;
- }
- // GPS_SEND_STR[ess_inc ++] = 's';
- len ++;
- while(7 - len)
- {
- len ++;
- LCD1602_write_data(' ');
- }
- }
- // GPS_SEND_STR[ess_inc] = ',';
- ess_inc += 1;
- if (GPS.EW == 'E') //判斷是東經還是西經
- {
- if(dis_flag)
- LCD1602_DisplayChar(8, 0, 'E');
- else
- LCD1602_write_data(' ');
- // GPS_SEND_STR[ess_inc ++] = 'E';
- len = 0;
- Int_To_Str(GPS.longitude_Degree,info); //經度
- LCD1602_Set_AC(9, 0);
- i = 0;
- send_len = 11;
- while(info[i] != '\0')
- {
- ch = info[i++];
- if(dis_flag)
- LCD1602_write_data(ch);
- else
- LCD1602_write_data(' ');
- send_data[send_len++] = ch;
- // GPS_SEND_STR[ess_inc ++] = ch;
- len ++;
- }
- send_data[send_len++] = 'd';
- if(dis_flag)
- LCD1602_write_data(0xDF);
- else
- LCD1602_write_data(' ');
- // GPS_SEND_STR[ess_inc ++] = 'd';
- len ++;
- Int_To_Str(GPS.longitude_Cent,info); //經分
- i = 0;
- while(info[i] != '\0')
- {
- ch = info[i++];
- if(dis_flag)
- LCD1602_write_data(ch);
- else
- LCD1602_write_data(' ');
- send_data[send_len++] = ch;
- // GPS_SEND_STR[ess_inc ++] = ch;
- len ++;
- }
- if(dis_flag)
- LCD1602_write_data(0x27);
- else
- LCD1602_write_data(' ');
- // GPS_SEND_STR[ess_inc ++] = 'm';
- Int_To_Str(GPS.longitude_Second,info); //經秒
- i = 0;
- while(info[i] != '\0')
- {
- ch = info[i++];
- // GPS_SEND_STR[ess_inc ++] = ch;
- }
- // GPS_SEND_STR[ess_inc ++] = 's';
- len ++;
- while(7 - len)
- {
- len ++;
- LCD1602_write_data(' ');
- }
- }
- GPS_DispTime();
- // GPS_SEND_STR[ess_inc] = ' ';
- ess_inc += 1;
- if(sendflag==1)
- {
- sendflag = 0;
- gsm_send_englishmsg(SEND_NUMBER,send_data);//發送位置短信
- delay_ms(1000);
- delay_ms(1000);
- LCD1602_DisplayString(0,0," SEND OK ");
- delay_ms(1000);
- LCD1602_DisplayString(0,0," ");
- }
-
- // GPS_DispSpeed(GPS.speed, 10, 1);
- // if (GPS.D.second == 0)
- // {
- // if (GPS_Have_flag)
- // {
- // gsm_send_englishmsg(phonenum,GPS_SEND_STR);//發送位置短信
- // }
- // else
- // {
- // //gsm_send_englishmsg(phonenum,"GPS No Signal");//發送短信
- // }
- // }
- }
- void main(void)
- {
- uchar error_num = 0;
- uint count = 0;
- GPS_EN = 0;
- GPS_rx_flag = 0;
- LCD1602_Initialize();//LCD1602顯示屏初始化
- uart_init(UART_B9600);
- GPS_EN = 1;
- GPS_rx_flag = 1;
- BG = 0;
- LCD1602_DisplayString_Center(0,"GPS SCAN...");
- LCD1602_ClearLine(1);
- while(1)
- {
- if (rev_stop) //如果接收完一行
- {
- if (GPS_RMC_Parse(RX1_Buffer, &GPS)) //解析GPRMC
- {
- RMC_YES;
- GPS_DisplayOne(); //顯示GPS第一頁信息
- error_num = 0;
- gps_flag = 0;
- rev_stop = 0;
- GPS_Have_flag = 1;
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
14GPS GSM定位短信.zip
(636 KB, 下載次數: 521)
2019-10-24 19:46 上傳
點擊文件名下載附件
|