发一个SIM900A+GPS单片机源程序
单片机源程序如下:
- /**************************************************************************
- * *
- * GPS+GPRS方式实现GPS地理位置信息通过GPRS无线上网方式传给上位机实例程序 *
- * *
- * 功能:GPS地理坐标、卫星时间等信息通过GPRS方式传到上位机 *
- * 板上提供Nokia5110液晶屏接口,GPS信息可以通过液晶实时显示 *
- * 版本: V1.0 (08/24) *
- *【声明】此程序仅用于学习与参考,引用请注明版权和作者信息! *
- * *
- *************************************************************************/
- #include <SIM300.h>
- #include <reg51.h>
- #include <string.h>
- #include <gps.h>
- void dis_time()
- {
- unsigned char hh;
- unsigned char i,temp_buff[10];
- hh=(gps_time[0]-'0')*10+(gps_time[1]-'0');
- hh+=8; //将格林威治时间校正成北京时间
- if(hh>=24)
- hh-=24; //校正小时
- temp_buff[0]=hh/10+'0';
- temp_buff[1]=hh%10+'0';
- temp_buff[2]=':';
- temp_buff[3]=gps_time[2];
- temp_buff[4]=gps_time[3];
- temp_buff[5]=':';
- temp_buff[6]=gps_time[4];
- temp_buff[7]=gps_time[5];
- for(i=0;i<8;i++)
- gps_time[i]=temp_buff[i];
- LCD_write_english_string(0,0,"TIME");
- LCD_set_XY(36,0);
- for(i=0;i<8;i++)
- {
- LCD_write_char(gps_time[i]);
- }
- }
- void dis_jwdu()
- {
- unsigned i;
- LCD_set_XY(0,1);LCD_write_char(gps_latitude_dir);
- LCD_set_XY(24,1);
- for(i=0;i<10;i++)
- {
- LCD_write_char(gps_latitude[i]);
- }
- LCD_set_XY(0,2);LCD_write_char(gps_longitude_dir);
- LCD_set_XY(30,2);
- for(i=0;i<9;i++)
- {
- LCD_write_char(gps_longitude[i]);
- }
- }
- void dis_high()
- {
- unsigned i;
- LCD_write_english_string(0,5,"HIGH");
- LCD_set_XY(42,5);
- for(i=0;i<7;i++)
- {
- LCD_write_char(gps_height[i]);
- }
- }
- /*gprs_data()
- {
- unsigned char buff[40];
- unsigned i;
-
- }*/
- //声明GPS驱动部分的全局变量
- void delay_time(unsigned char t)
- {
- unsigned int i,n;
- for(n=0;n<t;n++)
- for(i=0;i<10000;i++);
- }
- void main(void)
- {
- LCD_init(); //LCD初始化
- LCD_write_english_string(0,0,"System Starting and Initializing......");
- Delay_ms(5000);
- sys_init(); //UART1初始化
- Init_GPS_module(); //GPS初始化
- Start_GSM(); //开启模块
- GSM_init(); //GSM初始化
- BELL_UP(); //BEEP
- clear_SystemBuf(); //清除串口1缓冲区数据
- while(strsearch("Call Ready",SystemBuf)==0);//等待模块准备好
- BELL_UP();
- do
- {
- LCD_clear();
- clear_SystemBuf();
- sendstring(AT_COPS);
- LCD_write_english_string( 4,2,"searching>");
- Delay_ms(3000);
- LCD_write_english_string( 4,2,"searching->");
- Delay_ms(3000);
- LCD_write_english_string( 4,2,"searching-->");
- Delay_ms(3000);
- LCD_write_english_string( 4,2,"searching--->");
- Delay_ms(3000);
- }while((strsearch("CHINA UN",SystemBuf)==0)&&(strsearch("CHINA MOBILE",SystemBuf)==0));//检测服务商信息
- BELL_UP();
- LCD_clear();
- LCD_write_english_string(0,0,"KinCony");
- //GPRS初始化 */
- ES=0;
- Delay_ms(10000);
- Delay_ms(10000);
- sendstring(AT_CIPMUX);
- Delay_ms(10000);
- sendstring(AT_CIPSTART);
- //while(strsearch("CONNECT OK",SystemBuf)!=0);
- BELL_UP();
- LCD_clear(); //清屏幕
- ET0=1; //开中断
- while(1)
- {
- if(gps_data_ok_flag) //查询GPS数据是否OK
- {
- IE2=0x00; //如果OK就关中断处理数据并显示数据
- dis_time();
- dis_jwdu();
- dis_high();
- gps_data_ok_flag=0;
- IE2=0x01;
- }
- }
- }
- /********************************************************************************************************
- ** 函数名称 Int_Timer0()
- ** 函数功能 定时器中断位,是整个程序的心跳,如果停止,程序会死机
- *********************************************************************************************************/
- void Int_Timer0(void) interrupt 1 using 3
- {
- unsigned char i;
- TH0 = 0xB8;
- TL0 = 0x00; //20ms的时钟基准
- timer_1S_cnt++;
- timercount++;
- EA=0;
- if(timer_1S_cnt==50) //20×50=1000M
- {
- timer_10S_cnt++;
- timer_1S_cnt=0;
- timer_S_cnt++;
- } //1秒=1000毫秒
- if(timer_10S_cnt==10) //10S
- {
- timer_10S_cnt=0;
- BELL_UP();
- sendstring(AT_CIPSEND);
- Delay_ms(5000);
- Delay_ms(5000);
- for(i=0;i<8;i++)
- {
- sendchar(gps_time[i]);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
SIM900 GPRS GPS单片机源程序_带NOKIA5110显示.zip
(77.26 KB, 下载次数: 69)
|