|
GPS改進(jìn)后的程序,時(shí)差補(bǔ)償,搜索到衛(wèi)星報(bào)警
- #include "12864.h"
- #include"main.h"
- sbit reset=P1^5;
- sbit bell=P1^7;
- unsigned char numb=0; /*解包算法變量*/
- unsigned char wr_tab_start=0; /*這個(gè)變量尤其重要,當(dāng)他=0時(shí)是截獲GPS中的GPSMC包=1是截獲成功開(kāi)始把數(shù)據(jù)寫(xiě)入內(nèi)存,=2是數(shù)據(jù)接收完畢可以進(jìn)行其他操作*/
- unsigned char counter=0; /*counter是數(shù)據(jù)計(jì)數(shù)器*/
- unsigned char tab[59];/*GPSMC數(shù)據(jù)包有效長(zhǎng)度*/
- void InitUART(void)
- {
- TMOD = 0x20;
- SCON = 0x50;
- TH1 = 0xFA;
- TL1 = TH1;
- PCON = 0x00;
- EA = 1;
- ES = 1;
- TR1 = 1;
- }
- void UARTInterrupt(void) interrupt 4
- {
-
- if(RI)
- {
- RI = 0;
- if(wr_tab_start==0)
- {
- switch (numb){
-
- case 0:if(SBUF==0x24){numb=1;P0=0;}else {numb=0;};break;
- case 1:if(SBUF==0x47){numb=2;P0=2;}else {numb=0;}break;
- case 2:if(SBUF==0x50){numb=3;P0=4;}else {numb=0;}break;
- case 3:if(SBUF==0x52){numb=4;P0=8;}else {numb=0;}break;
- case 4:if(SBUF==0x4D){numb=5;P0=0x20;}else {numb=0;}break;
- case 5:if(SBUF==0x43){numb=6;P0=0x40;}else {numb=0;}break;
- case 6:if(SBUF==0x2C){ counter=0;wr_tab_start=1;numb=0;P0=0x80;}break;
- }
- }
- else if(wr_tab_start==1)
- {
- P0=counter;
-
- tab[counter]=SBUF;
- counter++;
-
-
- if(counter==60)
- {
- wr_tab_start=2;
- }
- }
- else
- TI = 0;
- }
- }
- void SendOneByte(unsigned char c)
- {
- SBUF = c;
- while(!TI);
- TI = 0;
- }
- void main(void)
- {
-
- unsigned char hour1,hour2,hour;
- reset=0;
- delay();
- reset=1; //復(fù)位12864
- delay40ms();
- init12864set();//進(jìn)行初始化液晶屏的固定的圖標(biāo)符號(hào)
-
- ////////////////////以上是液晶設(shè)置,以下是顯示地址設(shè)置
- InitUART();
-
- while(1)
- {
- if(wr_tab_start==2)
- {
-
- /*此處可以進(jìn)行包處理,解包和數(shù)據(jù)的顯示
- 令wr_tab_start=0;表示接收下一個(gè)包
-
- */
-
-
- EA=0;//開(kāi)中斷
- _data_mode();//在液晶上顯示數(shù)據(jù)狀態(tài),A有效,V無(wú)效
-
- switch (tab[1]){
- /*各位把字符數(shù)據(jù)轉(zhuǎn)換10進(jìn)制*/
- case 0x30:hour1=0;break;
- case 0x31:hour1=1;break;
- case 0x32:hour1=2;break;
- case 0x33:hour1=3;break;
- case 0x34:hour1=4;break;
- case 0x35:hour1=5;break;
- case 0x36:hour1=6;break;
- case 0x37:hour1=7;break;
- case 0x38:hour1=8;break;
- case 0x39:hour1=9;break;
- }
- switch (tab[0]){
- /*十位把字符數(shù)據(jù)轉(zhuǎn)換10進(jìn)制*/
- case 0x30:hour2=0;break;
- case 0x31:hour2=1;break;
- case 0x32:hour2=2;break;
- }
- hour2=hour2*10;
- hour=hour2+hour1;
- switch (hour){
- /*查表得出小時(shí)數(shù)*/
- case 0 :tab[0]=0x30;tab[1]=0x38;break;
- case 1 :tab[0]=0x30;tab[1]=0x39;break;
- case 2 :tab[0]=0x31;tab[1]=0x30;break;
- case 3 :tab[0]=0x31;tab[1]=0x31;break;
- case 4 :tab[0]=0x31;tab[1]=0x32;break;
- case 5 :tab[0]=0x31;tab[1]=0x33;break;
- case 6 :tab[0]=0x31;tab[1]=0x34;break;
- case 7 :tab[0]=0x31;tab[1]=0x35;break;
- case 8 :tab[0]=0x31;tab[1]=0x36;break;
- case 9 :tab[0]=0x31;tab[1]=0x37;break;
- case 10:tab[0]=0x31;tab[1]=0x38;break;
- case 11:tab[0]=0x31;tab[1]=0x39;break;
- case 12:tab[0]=0x32;tab[1]=0x30;break;
- case 13:tab[0]=0x32;tab[1]=0x31;break;
- case 14:tab[0]=0x32;tab[1]=0x32;break;
- case 15:tab[0]=0x32;tab[1]=0x33;break;
- case 16:tab[0]=0x30;tab[1]=0x30;break;
- case 17:tab[0]=0x30;tab[1]=0x31;break;
- case 18:tab[0]=0x30;tab[1]=0x32;break;
- case 19:tab[0]=0x30;tab[1]=0x33;break;
- case 20:tab[0]=0x30;tab[1]=0x34;break;
- case 21:tab[0]=0x30;tab[1]=0x35;break;
- case 22:tab[0]=0x30;tab[1]=0x36;break;
- case 23:tab[0]=0x30;tab[1]=0x37;break;
- }
- writectrl((0x9A));///寫(xiě)地址
- delay4_6ms();
-
- writedate(tab[0]); //數(shù)據(jù)寫(xiě)入FFH
- //小時(shí)顯示
- writedate(tab[1]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- writectrl((0x9B));//寫(xiě)地址
- delay4_6ms();
-
-
- writedate(tab[2]); //數(shù)據(jù)寫(xiě)入FFH
- //分鐘顯示:
- writedate(tab[3]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- writectrl((0x9C));///寫(xiě)地址
- delay4_6ms();
-
-
- writedate(tab[4]); //數(shù)據(jù)寫(xiě)入FFH
- //秒顯示: ,
- writedate(tab[5]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- if(0x41==tab[11])//如果衛(wèi)星數(shù)據(jù)有效則進(jìn)行寫(xiě)液晶的經(jīng)緯度坐標(biāo)
- {
- //////////////////////////////////////////
- bell=0;
- delay40ms(); //蜂鳴器
- delay40ms();
- bell=1;
- longitude_display();//經(jīng)度顯示
-
- /*以上是經(jīng)度顯示行,以下是緯度顯示行*/
- latitude_display();//緯度顯示
- ////////////////////////////////////////////////////
- }
- EA=1;//開(kāi)中斷
- wr_tab_start=0;
- }
- }
- }
-
- void init12864set()
- {
-
- writectrl(0x01);//DDRAM的AC計(jì)數(shù)器清零
- delay4_6ms();
-
- writectrl(0x02);//AC清零,游標(biāo)到開(kāi)頭為之
-
- delay4_6ms();
- writectrl(0x0C);//整體顯示開(kāi)
-
- delay4_6ms();
- writectrl((0x80));//寫(xiě)漢字顯示地址 DDRAM說(shuō)白了就是那個(gè)你在那里顯示這個(gè)漢子從第一行到第四行80H-9FH,一共32個(gè)漢子
- delay4_6ms();
- writedate(0xA3); //數(shù)據(jù)寫(xiě)入FFH
- //顯示J經(jīng)度
- writedate(0xCA); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- writectrl((0x81));// //寫(xiě)地址
- delay4_6ms();
- writedate(0xA3); //數(shù)據(jù)寫(xiě)入FFH
- //顯示:
- writedate(0xBA); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
-
-
- writectrl((0x88));////寫(xiě)地址
- delay4_6ms();
-
-
- writedate(0xA3); //數(shù)據(jù)寫(xiě)入FFH
- writedate(0xD7); //數(shù)據(jù)寫(xiě)入FFH //顯示W(wǎng)
- delay4_6ms();
- writectrl((0x89));////寫(xiě)地址
- delay4_6ms();
-
-
- writedate(0xA3); //數(shù)據(jù)寫(xiě)入FFH
- //顯示:
- writedate(0xBA); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
-
- writectrl((0x90));////寫(xiě)地址
- delay4_6ms();
-
-
- writedate(0xA3); //數(shù)據(jù)寫(xiě)入FFH
- writedate(0xD3); //數(shù)據(jù)寫(xiě)入FFH //顯示S
- delay4_6ms();
- writectrl((0x91));////寫(xiě)地址
- delay4_6ms();
-
-
- writedate(0xA3); //數(shù)據(jù)寫(xiě)入FFH
- //顯示:
- writedate(0xBA); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
-
- writectrl((0x98));////寫(xiě)地址
- delay4_6ms();
-
-
- writedate(0xA3); //數(shù)據(jù)寫(xiě)入FFH
- writedate(0xD4); //數(shù)據(jù)寫(xiě)入FFH //顯示T
- delay4_6ms();
- writectrl((0x99));////寫(xiě)地址
- delay4_6ms();
-
-
- writedate(0xA3); //數(shù)據(jù)寫(xiě)入FFH
- //顯示:
- writedate(0xBA); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- /////////////////以上是固定不變的////////////////////////////////////////////////
- /////////////////以上是固定不變的////////////////////////////////////////////////
- }
- /*數(shù)據(jù)標(biāo)志位,A表示數(shù)據(jù)有效V表示數(shù)據(jù)無(wú)效*/
- void _data_mode()
- {
-
- //////////數(shù)據(jù)有效為/////////////////////////
- writectrl((0x92));///寫(xiě)地址
- delay4_6ms();
-
-
- writedate(tab[11]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- }
- /*經(jīng)度顯示*/
- void longitude_display()
- {
- writectrl((0x82));///寫(xiě)地址
- delay4_6ms();
-
-
- writedate(tab[25]); //數(shù)據(jù)寫(xiě)入FFH
-
- writedate(tab[26]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- writectrl((0x83));//寫(xiě)地址
- delay4_6ms();
- //j經(jīng)度
-
- writedate(tab[27]); //數(shù)據(jù)寫(xiě)入FFH
- //顯示:
- writedate(tab[28]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- writectrl((0x84));///寫(xiě)地址
- delay4_6ms();
-
-
- writedate(tab[29]); //數(shù)據(jù)寫(xiě)入FFH
- //顯示: ,
- writedate(tab[30]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- writectrl((0x85));///寫(xiě)地址
- delay4_6ms();
-
- writedate(tab[31]); //數(shù)據(jù)寫(xiě)入FFH
- //顯示: ,
- writedate(tab[32]); //數(shù)據(jù)寫(xiě)入FFH //經(jīng)度
- delay4_6ms();
- writectrl((0x86));///寫(xiě)地址
- delay4_6ms();
-
- writedate(tab[33]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms(); //顯示: ,
- writedate(tab[34]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- writectrl((0x87));///寫(xiě)地址
- delay4_6ms();
-
- writedate(tab[35]); //數(shù)據(jù)寫(xiě)入FFH
- writedate(tab[36]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- }
- /*緯度在液晶上的顯示*/
- void latitude_display()
- {
-
-
- writectrl((0x8A));//寫(xiě)地址
- delay4_6ms();
-
- writedate(tab[13]); //數(shù)據(jù)寫(xiě)入FFH
- //緯度的“度”
- writedate(tab[14]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms(); //緯度
- writectrl((0x8B));////寫(xiě)地址
- delay4_6ms();
- writedate(tab[15]); //數(shù)據(jù)寫(xiě)入FFH
- //緯度的“分”
- writedate(tab[16]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- writectrl((0x8C));////寫(xiě)地址
- delay4_6ms();
-
- writedate(tab[17]); //數(shù)據(jù)寫(xiě)入FFH //緯度的“秒”
- writedate(tab[18]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- writectrl((0x8D));////寫(xiě)地址
- delay4_6ms();
-
- writedate(tab[19]); //數(shù)據(jù)寫(xiě)入FFH
- //緯度的“分”
- writedate(tab[20]); //數(shù)據(jù)寫(xiě)入FFH
- delay4_6ms();
- writectrl((0x8E));////寫(xiě)地址
- delay4_6ms();
-
-
- writedate(tab[21]); //數(shù)據(jù)寫(xiě)入FFH
- //緯度的“秒” //緯度
- writedate(tab[22]); //數(shù)據(jù)寫(xiě)入FFH
-
- delay4_6ms();
- writectrl((0x8F));////寫(xiě)地址
- delay4_6ms();
-
- writedate(tab[23]); //數(shù)據(jù)寫(xiě)入FFH
- writedate(tab[24]); //數(shù)據(jù)寫(xiě)入FFH
-
- delay4_6ms();
- }
- 12864.c
- #include"12864.h"
- void delay40ms(void) //誤差 -0.000000000009us
- {
- unsigned char ad,bd,cd;
- for(cd=11;cd>0;cd--)
- for(bd=124;bd>0;bd--)
- for(ad=12;ad>0;ad--);
- }
- void delay4_6ms()//
- {
- unsigned char av,bv;
- for(bv=12;bv>0;bv--)
- for(av=175;av>0;av--);
- }
- void delay(void)
- {
- ;;;
- }
- void writedate(unsigned char a)//寫(xiě)數(shù)據(jù)
- {
-
-
-
- delay4_6ms();
- rs=1;
- delay();
- rw=0;
- delay();
- e=1;
- delay();
- P0=a;
-
-
-
- delay();
- e=0;
- delay();
-
-
- }
- void writectrl(unsigned char ds)//寫(xiě)指令
- {
- rs=0;
- delay();
- rw=0;
- delay();
- e=1;
- delay();
- P0=ds;
- delay();
- e=0;
- delay();
-
- }
復(fù)制代碼 |
|