zarazagoza
Newbie level 3
- Joined
- May 9, 2013
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,296
I am trying to interface GPS module EM406A with pic18F4550. I want to get longitude and latitude displayed on the lcd. but i seem cannot make it work.
here is my coding.
can someone point me where i did it wrong?
here is my coding.
Code:
#include <p18F4550.h>
#include <delays.h>
/*device configuration*/
#pragma config WDT = OFF, LVP = OFF, FOSC = HS, XINST = OFF
#pragma code isr = 0x08
#pragma interrupt isr
void SendLCD(unsigned char Byte, char type);
void E_TOG(void);
void SendNyb(unsigned char Byte);
void LCD_Init(void);
void SetLine (char line);
void LCD_String(unsigned rom char *string);
void config (void);
void isr (void);
void tx_data(unsigned char);
#define LCD LATA //LCD Latch PORT
#define LCD_RS LATAbits.LATA4 //Register Select (0: Instruction/ 1: Data)
#define LCD_E LATAbits.LATA5 //Enable (Starts data read/write)
#define LCDT TRISA //LCD Tris port
unsigned char rx_data(void);
unsigned char serial_data;
unsigned char longi_data[12];
unsigned char lati_data[12];
unsigned char data,value=0;
unsigned int i=0,pos;
void main()
{
char x,tmp; //Some Variables
//OSCCON = 0x72; //8MHz clock/while(!OSCCONbits.IOFS); //Wait for OSC to become stable
ADCON1 = 0x0F; //Make all pins digital
LCD_Init(); //Initialize the LCD
config();
while(1)
{
data=rx_data(); // Check the string '$GPGGA,'
if(data=='$')
{
data=rx_data();
if(data=='G')
{
data=rx_data();
if(data=='P');
{
data=rx_data();
if(data=='G');
{
data=rx_data();
if(data=='G')
{
data=rx_data();
if(data=='A')
{
data=rx_data();
if(data==',')
{
data=rx_data();
while(data!=',')
data=rx_data();
for(i=0;data!='N';i++)
data=rx_data();
lati_data[i]=data; // Store the Latitude data
}
data=rx_data();
if(data==',')
{
for(i=0;data!='E';i++)
{
data=rx_data();
longi_data[i]=data; // Store the Longitude data
}
}
i=0;
//lcdcmd(0x80);
while(i<11)
{
SetLine(1); //Set Line 1
LCD_String((unsigned rom char*)lati_data[i]); //Send out string
//lcddata(lati_data[i]); // Print the Latitude data
i++;
}
i=0;
//lcdcmd(0xC0);
while(i<12)
{
SetLine(2); //Set Line 2
LCD_String((unsigned rom char*)longi_data[i]); //Send out string
//lcddata(longi_data[i]); // Print the Longitude data
i++;
}
}
}
}
}
}
}
}
Delay1KTCYx(1);
for(i=0;i<12;i++)
{
data=0;
lati_data[i]=0;
longi_data[i]=0;
}
}
void config(void)
{
TXSTAbits.TX9 = 0;
TXSTAbits.TXEN = 0;
TXSTAbits.SYNC = 0;
TXSTAbits.BRGH = 0;
RCSTAbits.SPEN = 1;
RCSTAbits.RX9 = 0;
RCSTAbits.CREN = 1;
BAUDCONbits.BRG16 = 0;
SPBRG = 64;
TRISCbits.RC6 = 1;
TRISCbits.RC7 = 1;
//interrupts
RCONbits.IPEN = 0;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
PIE1bits.RCIE = 1;
}
void isr (void)
{
if(PIR1bits.RCIF == 1)
{
if(PIR1bits.TXIF == 1)
{
TXREG = RCREG;
}
}
}
void tx_data(unsigned char data1)
{
TXREG = data1;
while(PIR1bits.TXIF==0);
}
unsigned char rx_data(void)
{
while(PIR1bits.RCIF==0);
return RCREG;
}
void LCD_String(unsigned rom char *string){
while(*string != 0){ //While the data pointed to isnt a 0x00 do below
SendLCD(*string++,1); //Send out the current byte pointed to
}
}
void LCD_Init(void){
LCDT = 0x00; //Set LCD Pins as output
LCD &= 0xF0; //clear only te db4:db7 pins
Delay10KTCYx(3); //delay 15mS
SendNyb(0x03); //Function set (Interface is 8 bits long.)
Delay10KTCYx(1); //delay 5mS
SendNyb(0x03); //Function set (Interface is 8 bits long.)
Delay100TCYx(3); //delay 150uS
SendNyb(0x03); //Function set (Interface is 8 bits long.)
Delay100TCYx(3); //delay 150uS
SendNyb(0x02); //Function set (Interface is 8 bits long.)
Delay100TCYx(1); //delay 50uS
SendLCD(0x28,0); //Function set (Interface is 4 bits long.) 2-lines, 5x8 dots
Delay100TCYx(1); //delay 50uS
SendLCD(0x10,0); //Cursor move, Shift to the Left
Delay100TCYx(1); //delay 50uS
SendLCD(0x06,0); //Increment
Delay100TCYx(1); //delay 50uS
SendLCD(0x0D,0); //Sets entire display On ,cursor Off, and blinking of cursor position ON
Delay100TCYx(1); //delay 50uS
SendLCD(0x01,0); //Clears entire display and sets DDRAM address 0 in address counter.
Delay10KTCYx(1); //delay 5mS
}
void E_TOG(void){
LCD_E = 1; //Set Enable High
Delay10TCY(); //Delay 5uS
LCD_E = 0; //Set Enable Low
}
void SetLine (char line){
if(line == 1) SendLCD(0x80,0); //Send 0x80 to set line to 1
if(line == 2) SendLCD(0xC0,0); //Send 0xC0 to set line to 2
Delay100TCYx(1); //delay 50uS
}
void SendLCD(unsigned char Byte, char type){
char ByteL;
LCD_RS = type; //Set whether it is a Command (0) or Data/Char (1)
ByteL = Byte & 0x0F; //Place Byte in ByteL and Clear the high part of byte
Byte >>= 4; //Shift over Byte by 4
LCD &= 0xF0; //Clear the LCD portion on the PORTA only
LCD |= Byte; //OR the new data to the LCD portion of PORTA (sending high part of byte)
E_TOG(); //Toggle the E(enable)
Delay10TCY(); //Delay 5uS
LCD &= 0xF0; //Same as above
LCD |= ByteL; //Same as above (sending low part of byte)
E_TOG(); //same as above
}
void SendNyb(unsigned char Byte){
Byte &=0x0F; //Clear the top half of byte
LCD &= 0xF0; //Clear the LCD half of PORTA
LCD |= Byte; //OR the new data into LCD part of PORTA
E_TOG(); //Toggle E(enable)
}
can someone point me where i did it wrong?