I have a pic18f4520, mplab xc8. Trying to find my problem, but no luck. So far I have Lat: and Lon: showing up on lcd, but no actual data. I was debugging earlier and had some small amount come in, but not the entire string. At this point I have just LAT: (line 1) LON: (line 2). Could someone look over my code and show me where I'm going wrong. It's located in the GetGpsdata after the $GPGGA string is filtered. thanks!!!
Mod edit: code tags
C:
#define _XTAL_FREQ 8000000 // subject to change
#include <stdint.h> // width values
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <string.h> // 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
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 bits, bitmask
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, 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);
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);}} // Move this final value to LCD data
char UART_Init(const long int baudrate){
unsigned int x;
x = (_XTAL_FREQ - baudrate*64)/(baudrate*64);
if(x>255){
x = (_XTAL_FREQ - baudrate*16)/(baudrate*16);
BRGH = 1;}
if(x<256) {
SPBRG = x;
SYNC = 0;
SPEN = 1;
TRISC7 = 1;
TRISC6 = 1;
CREN = 1;
TXEN = 1;
// LCDstring("ME ME ME");
return 1;}
return 0;}
char UART_Data_Ready(){
return RCIF;}
char UART_Read(){
while(!RCIF);
return RCREG;}
void UART_Read_Text(char *Output, unsigned int length){
int i;
for(int i=0;i<length;i++)
Output[i] = UART_Read();}
void GPS_GetDataAndDisplayIt(void){
int i;
i=0;
char Temp = 0, Index = 0;
while(!UART_Data_Ready());
Temp = UART_Read();
if (Temp == '$'){
while(!UART_Data_Ready());
Temp = UART_Read();
if (Temp == 'G'){
while(!UART_Data_Ready());
Temp = UART_Read();
if (Temp == 'P'){
while(!UART_Data_Ready());
Temp = UART_Read();
if (Temp == 'G'){
while(!UART_Data_Ready());
Temp = UART_Read();
if (Temp == 'G'){
while(!UART_Data_Ready());
Temp = UART_Read();
if (Temp == '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(0x01),LCDstring("LAT:"); // cursor to 1st line with message
while(!UART_Data_Ready());
Temp = UART_Read();
while (Temp != ','){
LAT[i] = Temp;
LCDstring(Temp); // Displaying latitude on LCD
while(!UART_Data_Ready());
Temp = UART_Read();
i ++;
if (i == 2){
LCDstring("°"); // Displaying degree sign
LAT[i] = 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[i] = Temp;
while(!UART_Data_Ready());
Temp = UART_Read();
i ++;
if (i == 3){
LCDstring("°"); // Displaying degree sign
LON[i] = 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;
// PORTAbits.RA0 = 0, _delay(1000);
GPS_GetDataAndDisplayIt();
_delay(1000);
//LCDcmd(0x80),LCDstring("hello TED"),LCDcmd(0xC0),LCDstring("Lat: 148.0000"),LCDcmd(0x94),LCDstring("LON: anything"),LCDcmd(0xD4),LCDstring("Anything");
}
return 0;
}
Attachments
-
132.2 KB Views: 8
-
7.9 KB Views: 12
Last edited by a moderator: