版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、這其中包括1602驅(qū)動(dòng)頭文件,和解析主程序,使用時(shí)分開(kāi)粘貼到對(duì)應(yīng)的 文件中/*LCD1602驅(qū)動(dòng),兼容LCD2402*/sbit LCD_DB0= P00;sbit LCD_DB1= P01;sbit LCD_DB2= P02;sbit LCD_DB3= P03;sbit LCD_DB4= P04;sbit LCD_DB5= P05;sbit LCD_DB6= P06;sbit LCD_DB7= P07;sbit LCD1602_RS=P24;sbit LCD1602_RW=P25; sbit LCD1602_EN=P26;void LCD_write_char( unsigned x,uns
2、igned char y,unsigned char dat);/在指定位置顯示字符void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);/在指定位置顯示字符串void LCD_cls(void);/清屏void LCD_en_command(unsigned char command);void LCD_en_dat(unsigned char temp);void LCD_set_xy( unsigned char x, unsigned char y );void LCD_init(unsigned
3、 char bw);void SET_LCD(unsigned char IO_temp);void delayms(unsigned char ms);void lcddelay(void);unsigned char LCDIO; unsigned char BitWidth;void LCD_cls(void)LCD_en_command(0x01);/0x01 清屏 delayms(2);void LCD_en_command(unsigned char command)LCD1602_RS=0; LCD1602_RW=0;LCD1602_EN=0;switch(BitWidth) c
4、ase 4:LCDIO=(command & 0xf0); /取高4位break; case 8:LCDIO=command; break;SET_LCD(LCDIO);LCD1602_EN=1;lcddelay();LCD1602_EN=0;if (BitWidth=4)LCDIO=(command & 0x0f)<<4;/取低4位SET_LCD(LCDIO);LCD1602_EN=1;lcddelay();LCD1602_EN=0;void SET_LCD(unsigned char IO_temp) /高4位LCD_DB7=IO_temp&0x80;L
5、CD_DB6=IO_temp&0x40;LCD_DB5=IO_temp&0x20;LCD_DB4=IO_temp&0x10;/低4位if (BitWidth=8)LCD_DB3=IO_temp&0x08;LCD_DB2=IO_temp&0x04;LCD_DB1=IO_temp&0x02;LCD_DB0=IO_temp&0x01;void LCD_en_dat(unsigned char dat)LCD1602_RS=1;LCD1602_RW=0;LCD1602_EN=0;switch(BitWidth) case 4:LCDIO=(dat
6、 & 0xf0); /取高4位break; case 8:LCDIO=dat;break;SET_LCD(LCDIO);LCD1602_EN=1;lcddelay();LCD1602_EN=0;if (BitWidth=4)LCDIO=(dat & 0x0f)<<4; /取低4位SET_LCD(LCDIO);LCD1602_EN=1;lcddelay();LCD1602_EN=0;/*=*1602* 輸入?yún)?shù):x、y : 顯示字符串的坐標(biāo),X:0-15,Y:0-1*LCD第一行顯示寄存器地址:0X80-0X8F*LCD第二行顯示寄存器地址:0XC0-0XCF *24
7、04*LCD第1行顯示地址:120(0x800x93) *LCD第2行顯示地址:120(0xc00xd3) *LCD第3行顯示地址:120(0x940xa7) *LCD第4行顯示地址:120(0xd40xe7) =*/ void LCD_set_xy( unsigned char x, unsigned char y )unsigned char address;if (y =0) address = 0x80 + x;else if(y=1) address = 0xC0 + x; else if(y=2) address = 0x94 + x;else if(y=3) address =
8、0xD4 + x;LCD_en_command(address); void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)LCD_set_xy( x, y ); LCD_en_dat(dat);void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s) LCD_set_xy( X, Y ); /set address while (*s) / write character LCDIO=*s;SET_LCD(LCDIO);LCD_en
9、_dat(*s); s +; void LCD_init(unsigned char bw)BitWidth=bw;switch(BitWidth) case 4:LCD_en_command(0x33);/delayms(20);LCD_en_command(0x32);/delayms(20);break; case 8:LCD_en_command(0x38);/delayms(20);LCD_en_command(0x38);/delayms(20);break;LCD_en_command(0x08);/0x08 令顯示器off delayms(5);LCD_en_command(0
10、x01);/0x01 清屏清屏指令delayms(5);LCD_en_command(0x06);/0x06 光標(biāo)模式設(shè)置進(jìn)入模式設(shè)置指令 寫(xiě)入數(shù)據(jù)后光標(biāo)右移delayms(5);LCD_en_command(0x0c);/0x0c 顯示開(kāi) 令光標(biāo),0x0c=不顯示,0x0d=顯示閃動(dòng)delayms(5);void delayms(unsigned char ms)unsigned char i;while(ms-)for(i = 0; i < 115; i+);void lcddelay(void)unsigned char i;for(i = 0; i < 2; i+);/*G
11、PS解碼顯示程序,*/#include<reg52.h>#include "1602.h"/#include"math.h"/#include <stdlib.h>sbit GPS_SPD=P32;/GPS模塊速率設(shè)置sbit KEY1=P33;/顯示內(nèi)容分屏切換,(T0,T1引腳 的第二功能為計(jì)數(shù)器。)char code TIME_AREA= 8;/時(shí)區(qū)/* 這是做的部分更改*/unsigned long maxspeed,b;unsigned int count=0;unsigned int a5;unsigned char
12、hspeed5;unsigned int dot_count;/小數(shù)點(diǎn)計(jì)數(shù)器/unsigned char x;/GPS數(shù)據(jù)存儲(chǔ)數(shù)組unsigned char JD10;/經(jīng)度unsigned char JD_a;/經(jīng)度方向unsigned char WD9;/緯度unsigned char WD_a;/緯度方向unsigned char date6;/日期unsigned char time6;/時(shí)間unsigned char speed5='0','0','0','.','0'/速度unsigned char h
13、igh6;/高度unsigned char angle5='0','0','0','0','0'/方位角unsigned char use_sat2;/使用的衛(wèi)星數(shù)unsigned char total_sat2;/天空中總衛(wèi)星數(shù)unsigned char lock;/定位狀態(tài)/串口中斷需要的變量unsigned char seg_count;/逗號(hào)計(jì)數(shù)器unsigned char byte_count;/位數(shù)計(jì)數(shù)器unsigned char cmd_number;/命令類(lèi)型unsigned char mode;/
14、0:結(jié)束模式,1:命令模式,2:數(shù)據(jù)模式unsigned char buf_full;/1:整句接收完成,相應(yīng)數(shù)據(jù)有效。0:緩存數(shù)據(jù)無(wú)效。unsigned char cmd5;/命令類(lèi)型存儲(chǔ)數(shù)組/顯示需要的變量unsigned int dsp_count;/刷新次數(shù)計(jì)數(shù)器/unsigned char time_count;bit page;void sys_init(void);bit chk_key(void);main()unsigned char i;char Bhour;sys_init();lock=1;use_sat0='0'use_sat1='0'
15、total_sat0='0'total_sat1='0'while(1) if(buf_full=0)/無(wú)GPS信號(hào)時(shí)dsp_count+;if(dsp_count>=65000)LCD_cls();/清屏LCD_write_string(0,0,"No GPS connect.");LCD_write_string(0,1,"Please Check.");while(buf_full=0);LCD_cls();dsp_count=0;else/有GPS信號(hào)時(shí) if(chk_key()/檢測(cè)到按鍵切換顯示page=
16、!page;LCD_cls();if(!page)/頁(yè)面1 if(buf_full|0x01)/GGA語(yǔ)句if(lock=0)/如果未定位LCD_write_string(0,0,"*-.-.- ");LCD_write_string(0,1,"* -.-.- ");else/如果已定位 LCD_write_char(0,0,JD_a);/顯示經(jīng)度 for(i=0;i<3;i+) LCD_write_char(i+1,0,JDi); LCD_write_char(4,0,'.'); for(i=3;i<10;i+) LCD_w
17、rite_char(i+2,0,JDi); LCD_write_char(0,1,WD_a);/顯示緯度LCD_write_char(1,1,' '); for(i=0;i<2;i+)LCD_write_char(i+2,1,WDi);LCD_write_char(4,1,'.'); for(i=2;i<9;i+)LCD_write_char(i+3,1,WDi);LCD_write_char(14,1,use_sat0);/顯示接收衛(wèi)星數(shù)LCD_write_char(15,1,use_sat1);buf_full&=0x01;dsp_cou
18、nt=0;if(buf_full|0x02)/GSV語(yǔ)句LCD_write_char(14,1,total_sat0);LCD_write_char(15,1,total_sat1);buf_full&=0x02;dsp_count=0;if(buf_full|0x04)if(lock=0)/如果未定位LCD_write_string(0,0,"*-.-.- ");LCD_write_string(0,1,"* -.-.- ");else/如果已定位 LCD_write_char(0,0,JD_a);/顯示經(jīng)度 for(i=0;i<3;i+
19、) LCD_write_char(i+1,0,JDi); LCD_write_char(4,0,'.'); for(i=3;i<10;i+) LCD_write_char(i+2,0,JDi); LCD_write_char(0,1,WD_a);/顯示緯度LCD_write_char(1,1,' '); for(i=0;i<2;i+)LCD_write_char(i+2,1,WDi);LCD_write_char(4,1,'.'); for(i=2;i<9;i+)LCD_write_char(i+3,1,WDi); LCD_wr
20、ite_char(14,0,use_sat0);/顯示接收衛(wèi)星數(shù)LCD_write_char(15,0,use_sat1);buf_full&=0x04;dsp_count=0;else/頁(yè)面2if(buf_full|0x01)/GGA語(yǔ)句buf_full&=0x01;dsp_count=0;if(buf_full|0x02)buf_full&=0x02;dsp_count=0;if(buf_full|0x04)/RMC語(yǔ)句Bhour=(time0-0x30)*10+time1-0x30)+TIME_AREA;if(Bhour>=24)Bhour-=24;else
21、 if(Bhour<0)Bhour+=24;LCD_write_char(0,1,date4);LCD_write_char(1,1,date5);LCD_write_char(2,1,date2);LCD_write_char(3,1,date3);LCD_write_char(4,1,date0);LCD_write_char(5,1,date1);LCD_write_char(8,1,Bhour/10+0x30);LCD_write_char(9,1,Bhour%10+0x30);LCD_write_char(10,1,':');LCD_write_char(11,
22、1,time2);LCD_write_char(12,1,time3);LCD_write_char(13,1,':');LCD_write_char(14,1,time4);LCD_write_char(15,1,time5);LCD_write_string(5,0,"knot A"); /在此處做的更改if(lock='0')/如果未定位LCD_write_string(0,0,"-.-");LCD_write_string(11,0,"-.-");else /已經(jīng)定位,在此處做的改動(dòng)。/*/*最
23、大速度處理*/ dot_count=0; b=0; for(i=0;i<5;i+) if(speedi!='.') dot_count+; else break ; switch(dot_count) case 1: b=(speed0-'0')*10+(speed2-'0')*1.852; break; case 2: b=(speed0-'0')*100+(speed1-'0')*10+(speed4-'0')*1.852; break; case 3: b=(speed0-'0&
24、#39;)*1000+(speed1-'0')*100+(speed2-'0')*10+(speed4-'0')*1.852; break; if(b>maxspeed) maxspeed=b; /*最大速度處理*/ if(count<10) for(i=0;i<5;i+)LCD_write_char(i,0,speedi);/knot顯示count+; else if(count>15) count=0; hspeed0=maxspeed/1000+0x30; /把小數(shù)轉(zhuǎn)成字符數(shù)組 hspeed1=(maxspeed/1
25、00)%10+0x30; hspeed2=(maxspeed/10)%10+0x30; hspeed3='.' hspeed4= maxspeed%10+0x30; count+;LCD_write_string(5,0,"Km/h A"); LCD_write_char(0,0,hspeed0);LCD_write_char(1,0,hspeed1);LCD_write_char(2,0,hspeed2);LCD_write_char(3,0,hspeed3);LCD_write_char(4,0,hspeed4);/最大速度顯 */ /*/ for(i=
26、0;i<5;i+)LCD_write_char(11+i,0,anglei);buf_full&=0x04;dsp_count=0;bit chk_key(void)if(!KEY1)delayms(10);if(!KEY1)while(!KEY1);delayms(10);return(1); LCD_cls();/清屏return(0);/系統(tǒng)初始化void sys_init() unsigned char i;SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */TMOD = 0x21; /* TMOD: timer
27、 1, mode 2, 8-bit reload */if(GPS_SPD)TH1 = 0xfa; /* TH1: reload value for 9600 baud 11.059MHz */elseTH1 = 0xfd;/* TH1: reload value for 4800 baud 11.059MHz */TR1 = 1; /* TR1: timer 1 run */LCD_init(8);/初始化LCDLCD_write_string(0,0," GPS SIRF II 2 ");LCD_write_string(0,1," 11-11-23 1342
28、 ");for(i=1;i<4;i+)delayms(250);/LCD_cls();IE=0x90;/開(kāi)總中斷、串口中斷/串口接收中斷void uart(void) interrupt 4unsigned char tmp;if(RI)tmp=SBUF;switch(tmp)case '$':cmd_number=0;/命令類(lèi)型清空mode=1;/接收命令模式byte_count=0;/接收位數(shù)清空break;case ',':seg_count+;/逗號(hào)計(jì)數(shù)加1byte_count=0;break;case '*':switc
29、h(cmd_number)case 1:buf_full|=0x01;break;case 2:buf_full|=0x02;break;case 3:buf_full|=0x04;break;mode=0;break;default:if(mode=1)/命令種類(lèi)判斷cmdbyte_count=tmp;/接收字符放入類(lèi)型緩存if(byte_count>=4)/如果類(lèi)型數(shù)據(jù)接收完畢,判斷類(lèi)型if(cmd0='G')if(cmd1='P')if(cmd2='G')if(cmd3='G')if(cmd4='A')
30、cmd_number=1;mode=2;seg_count=0;byte_count=0;else if(cmd3='S')if(cmd4='V')cmd_number=2;mode=2;seg_count=0;byte_count=0;else if(cmd2='R')if(cmd3='M')if(cmd4='C')cmd_number=3;mode=2;seg_count=0;byte_count=0;else if(mode=2)/接收數(shù)據(jù)處理switch (cmd_number)case 1:/類(lèi)型1數(shù)據(jù)接收。GPGGAswitch(seg_count)case 2:/緯度處理if(byte_count<9)WDbyte_count=tmp;break;case 3:/緯
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五版汽車(chē)抵押貸款合同借款人借款用途變更通知合同3篇
- 二零二五年度城市軌道交通內(nèi)部承包合同6篇
- 二零二五版企業(yè)日常經(jīng)營(yíng)客戶(hù)關(guān)系管理與維護(hù)合同2篇
- 二零二五年酒店員工入股與酒店服務(wù)體驗(yàn)優(yōu)化合同3篇
- 二零二五年度廁所革命專(zhuān)項(xiàng)基金使用管理合同3篇
- 二零二五年度新能源風(fēng)能發(fā)電設(shè)備研發(fā)制造合同2篇
- 二零二五版企業(yè)法人借款合同擔(dān)保協(xié)議3篇
- 2025版大清包勞務(wù)合同范本:二零二五年度文化活動(dòng)組織執(zhí)行合同3篇
- 二零二五年海底光纜線路鋪設(shè)及安全保障合同3篇
- 2025年度祠堂宗教活動(dòng)組織與承包合同2篇
- 萬(wàn)達(dá)廣場(chǎng)裝修手冊(cè)
- 云南省律師服務(wù)收費(fèi)管理辦法及標(biāo)準(zhǔn)
- 華為C語(yǔ)言通用編程規(guī)范
- 搞笑詩(shī)朗誦《生活》4人
- 團(tuán)建活動(dòng)滿(mǎn)意度調(diào)查問(wèn)卷
- 數(shù)獨(dú)題目難度系數(shù)3級(jí)共100題后附參考答案
- 齊魯醫(yī)學(xué)數(shù)字疼痛評(píng)分表
- GB∕T 7588.1-2020 電梯制造與安裝安全規(guī)范 第1部分:乘客電梯和載貨電梯
- 植物種植施工方案與技術(shù)措施
- 空調(diào)工程竣工驗(yàn)收單(共1頁(yè))
- STM32固件庫(kù)使用手冊(cè)(中文版)
評(píng)論
0/150
提交評(píng)論