定义X-TalthFRIQ 8000000 / /改变LCDcmd,包括/lt;Stdio.H.& Gt;15;Car Luon(15);Car UrtARTION(const long int BurdRead);LVP= OFF,CPD= OFF,OSC=INTIO7,WDT=OFCHARAR UARTHINIT(const long int BurdRead){un= int int x;x=(x xTalthFrq-BaDead * 64)/(BaurRead *64);SpBrg= x;Syc=0;SPEN=1;TrISC7=1;TrISC6=1;CREN=1;TXEN=1。1;返回1;返回0;} chARUARTYDATAAdRead(){RealRCIF;} chuUARTHEAD Read(){()!Mode LCDcmd(0x32);//LCDCMD(0x2C);//2-L模式LCDcmd(0x0C);//DISP on,Curs关闭,Blink On LCDcmd(0x01);}//Culsial-LCDcmd(int UnORN){//LCD CMD 4位,E(BIT7),RS(BIT4)PORTD=0;/E=0 Rs=0 int=UNICORN;γ延迟(2000);麒麟=((麒麟& gt;and 4;);0x0f)0x80;//e=1 Rs=0,将上NIB写入LCD:SR R=UNICORN,Y延迟(2000);UNICORN=UNICORN ANP;0x0F;//E=0,保存较低(下NIB将被发送)PORTD=独角兽,Y延迟(2000);PORTD=0;//E=0 RS= 0 UnrONN=TEMP;麒麟=(U)NICORN和0x0F)0x80;//E=1 Rs=0,将下一个NIB写入LCD:清除高位位、位掩码PORTD=独角兽、Y延迟(2000);UNICORN = UNICORN和AMP;0x0F;//E=0,保存较低(下NIB要发送)POTD=独角兽,γ延迟(2000);} LCDDATA(int独角兽){//LCD CMD 4位,E(BIT7),RS(BIT4)PORTD。=0;/e=0个RT=0个int=UNICORN;γ延迟(1000);UNICORN=((麒麟& gt;4;);0x0f)×0x90;//e=1 RS= 1,写上NIB到LCD:S.R. 4位,PORTD=独角兽,γ延迟(1000);UNICORN=(麒麟和0x0F)0x10;//E=0 RS= 1,保存较低(下NIB要发送)PORTD=独角兽,γ延迟(1000);PORTD=0;/E=0 Rs=0麒麟=TEMP;UNICORN=(UNICORN和0x0F)×0x90;//E=1 Rs=1,写下NIB到LCD:清除高位位,位掩码PORTD=独角兽,γ延迟(1000);UNICORN=(独角兽和0x0F)0x10;//E=0 RS= 1,保存较低(下NIB要发送)PORTD=独角兽,γ延迟(1000)}空LCDstring(char *独角兽){int=0;int计数;int计数=Strlln(UNICORN);//计数=字符串John的长度(i和lt;计数){//while循环以确定LCD字符串的数据长度Timp=独角兽[i++];//TEMP=部分2LCD增量为空值放置LCDATATE(TEMP);} VOID GPSGETDATA和DISIT(空隙){int i;i=0;char TEMP=0;而(!)UTARJDATAYRADYY());TEMP= UARTHARAD();如果(TEMP==$$){//$同时(!)UARTHARDATAYRADYY());TEMP= UARTHAREAD();如果(TEMP= =“G”){//g同时(!)UARTHARDATAYRADYY());TEMP= UARTHARAD Read();如果(TEMP==P’){//P同时(!)UARTHARDATAYRADYY());TEMP= UARTHAREAD();如果(TEMP= =“G”){//g同时(!)UARTHARDATAYRADYY());TEMP= UARTHAREAD();如果(TEMP= =“G”){//g同时(!)UTARJDATAYRADYY());TEMP= UARTHAREAD();如果(TEMP= =‘A’){//A同时(!)UARTHYDATAYRADYY());TEMP= UARTHARAD Read();//跳过“,”同时()!UARTHYDATAYRADYY());TEMP= UARTHARAD Read();(TEMP!{“!”){同时(!)UARTHARDATAYRADYY());TEMP= UARTHARAD Read();I++;} i=0;LCDCMD(0x0C),LCDstring(“LAT::”);/ /光标到第一条带消息的同时(!)UARTHYDATAYRADYY());TEMP= UARTHARAD Read();(TEMP!{LAT= TEMP;LCDstring(TEMP);/ /在LCD上显示纬度,同时(!)UTARJADATAYRADY());TEMP= UARTHARAD Read();I++;I=(i=2){ LCDstring(“°”);/ /显示度符号LAT=TEMP;} i=0;同时(!)UARTHARDATAYRADYY());TEMP= UARTHARAD Read();LCDstring(′);LCDstring(TEMP);//显示方向LCD LCDCMD(0xC0),LCDstring(“Lon:”);/ /光标到第二行带有消息同时(!)UARTHYDATAYRADYY());TEMP= UARTHARAD Read();(!)UARTHYDATAYRADYY());TEMP= UARTHARAD Read();(TEMP!{LCDStand(TEMP);/ /显示LCD Lon=TEMP的经度;同时()!UTARJADATAYRADY());TEMP= UARTHARAD Read();I++;I=(i=3){ LCDstring(“°”);//显示度符号Lon=TEMP;} },(!)UARTHYDATAYRADY());TEMP= UARTHARAD Read();//跳过“,”同时()!UARTHYDATAYRADY());TEMP= UARTHARAD Read();//跳过“,”同时()!UARTHYDATAYRADY());TEMP= UARTHARAD Read();//跳过“,”同时()!UARTHYDATAYRADY());TEMP= UARTHARAD Read();//跳过“,”同时()!UARTHYDATAYRADY());TEMP= UARTHARAD Read();//跳过“,”同时(TEMP!{“!”){同时(!)(LCDcmd)(Typ=UARTAX Read());/LCDDATA(TEMP);} } } } } int main(空隙){OSCCon=0x76;//将内部振荡器设置为8MHz TrISA=0B11111110;TrISD= 0x00;TrISC=0B11111111;//GPS(RC7)LCDINIT();(0x01);UARTHARINIT(9600);而(1){PababiTr.R0=1;//led在GPSGETDATA和DISDL上。UARTAyt();γ延迟(1000);}返回0;}
以上来自于百度翻译
以下为原文
#define _XTAL_FREQ 8000000 // subject to change
#include // width values
#include
#include
#include
#include // string readout data
void LCDinit(), LCDcmd(int unicorn), LCDstring(char *unicorn), LCDdata(int unicorn);
char LAT[15];
char LON[15];
char UART_Init(const long int baudrate);
#pragma config BOREN = ON,LVP = OFF,CPD = OFF,OSC = INTIO7,WDT = OFF
char UART_Init(const long int baudrate){
unsigned int x;
x = (_XTAL_FREQ - baudrate*64)/(baudrate*64);
SPBRG = x;
SYNC = 0;
SPEN = 1;
TRISC7 = 1;
TRISC6 = 1;
CREN = 1;
TXEN = 1;
return 1;
return 0;}
char UART_Data_Ready(){
return RCIF;}
char UART_Read(){
while(!RCIF);
return RCREG;}
void LCDinit(){
LCDcmd(0x33); // 4b Mode
LCDcmd(0x32); // E
LCDcmd(0x2C); // 2-L mode
LCDcmd(0x0C); // Disp On,Curs Off,Blink On
LCDcmd(0x01);} // clear
void LCDcmd(int unicorn){ // LCD CMD 4-BIT, E(bit7),RS(bit4)
PORTD = 0; // E=0 RS=0
int temp = unicorn;
_delay(2000);
unicorn = ((unicorn >> 4) & 0x0F)|0x80; // E=1 RS=0, writes UPPER NIB to LCD: S.R. 4 bits, clears upper
PORTD = unicorn, _delay(2000);
unicorn = unicorn & 0x0F; // E=0, preserve lower (lower nib is to be sent)
PORTD = unicorn, _delay(2000);
PORTD = 0; // E=0 RS=0
unicorn = temp;
unicorn = (unicorn & 0x0F)|0x80; // E=1 RS=0, writes LOWER NIB to LCD: clears upper bits, bitmask
PORTD = unicorn, _delay(2000);
unicorn = unicorn & 0x0F; // E=0, preserve lower (lower nib is to be sent)
PORTD = unicorn, _delay(2000);}
void LCDdata(int unicorn){ // LCD CMD 4-BIT, E(bit7),RS(bit4)
PORTD = 0; // E=0 RS=0
int temp = unicorn;
_delay(1000);
unicorn = ((unicorn >> 4) & 0x0F)|0x90; // E=1 RS=1, writes UPPER NIB to LCD: S.R. 4 bits,
PORTD = unicorn, _delay(1000);
unicorn = (unicorn & 0x0F)|0x10; // E=0 RS=1, preserve lower (lower nib is to be sent)
PORTD = unicorn, _delay(1000);
PORTD = 0; // E=0 RS=0
unicorn = temp;
unicorn = (unicorn & 0x0F)|0x90; // E=1 RS=1, writes LOWER NIB to LCD: clears upper bits, bitmask
PORTD = unicorn, _delay(1000);
unicorn = (unicorn & 0x0F)|0x10; // E=0 RS=1, preserve lower (lower nib is to be sent)
PORTD = unicorn, _delay(1000);}
void LCDstring(char *unicorn){
int I = 0;
int temp;
int count = strlen(unicorn); // count = the length of the string john
while(I < count){ // While loop to determine the length of data for LCD string
temp = unicorn[I++]; // temp = part2LCD increment for the null value places
LCDdata(temp);}}
void GPS_GetDataAndDisplayIt(void){
int i;
i=0;
char Temp = 0;
while(!UART_Data_Ready());
Temp = UART_Read();
if (Temp == '$'){ // $
while(!UART_Data_Ready());
Temp = UART_Read();
if (Temp == 'G'){ // G
while(!UART_Data_Ready());
Temp = UART_Read();
if (Temp == 'P'){ // P
while(!UART_Data_Ready());
Temp = UART_Read();
if (Temp == 'G'){ // G
while(!UART_Data_Ready());
Temp = UART_Read();
if (Temp == 'G'){ // G
while(!UART_Data_Ready());
Temp = UART_Read();
if (Temp == 'A'){ // A
while(!UART_Data_Ready());
Temp = UART_Read(); // skipping ','
while(!UART_Data_Ready());
Temp = UART_Read();
while (Temp != ','){
while(!UART_Data_Ready());
Temp = UART_Read();
i ++;}
i = 0;
LCDcmd(0x0C),LCDstring("LAT:"); // cursor to 1st line with message
while(!UART_Data_Ready());
Temp = UART_Read();
while (Temp != ','){
LAT = Temp;
LCDstring(Temp); // Displaying latitude on LCD
while(!UART_Data_Ready());
Temp = UART_Read();
i ++;
if (i == 2){
LCDstring("°"); // Displaying degree sign
LAT = Temp;}}
i = 0;
while(!UART_Data_Ready());
Temp = UART_Read();
LCDstring(' ');
LCDstring(Temp); // Display Direction on LCD
LCDcmd(0xC0),LCDstring("LON:"); // cursor to 2nd line with message
while(!UART_Data_Ready());
Temp =UART_Read();
while(!UART_Data_Ready());
Temp = UART_Read();
while (Temp != ','){
LCDstring(Temp); // Display Longitude on LCD
LON = Temp;
while(!UART_Data_Ready());
Temp = UART_Read();
i ++;
if (i == 3){
LCDstring("°"); // Displaying degree sign
LON = Temp;}}
while(!UART_Data_Ready());
Temp = UART_Read(); // Skip ','
while(!UART_Data_Ready());
Temp = UART_Read(); // Skip ','
while(!UART_Data_Ready());
Temp = UART_Read(); // Skip ','
while(!UART_Data_Ready());
Temp = UART_Read(); // Skip ','
while(!UART_Data_Ready());
Temp = UART_Read(); // Skip ','
while(Temp != ','){
while(!UART_Data_Ready());
Temp = UART_Read();
// LCDdata(Temp);
}}}}}}}}
int main(void) {
OSCCON = 0x76; // Sets internal oscillator to 8MHz
TRISA = 0b11111110;
TRISD = 0x00;
TRISC = 0b11111111; // GPS(RC7)
LCDinit();
LCDcmd(0x01);
UART_Init(9600);
while(1){
PORTAbits.RA0 = 1; // LED on
GPS_GetDataAndDisplayIt();
_delay(1000);}
return 0;}
|
|
2018-11-14 15:00:02
评论
举报
|
|
|