meghna
Joined: 27 Mar 2014 Posts: 1
|
Not able to receive gps data*** Locked - MikroC is off-topic |
Posted: Thu Mar 27, 2014 1:23 am |
|
|
Here is my code to get data from gps module and to display it on lcd. I am using pic16f887 controller and Micro C software. So please help me out as soon as possible in my code.
Code: | sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// Variables
int i = 0;
int received = 0;
char DataType[] = "GPXXX";
char NMEA[] = "$xxxxx,xxxxxxxxx,xxxx.xxx,x,xxxxx.xxx,x,x,xx,x.x,xxx.x,x,xx.x,x,,*xx";
//$GPRMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,ddmmyy,x.x,a*hh
//$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70
char received;
// End Variables
void main()
{
PORTB = 0xFF;
TRISB = 0xff;
ANSEL = 0;
ANSELH = 0;
C1ON_bit = 0;
C2ON_bit = 0; // Set Port B as output port
SPBRG=9600; // Fill SPBRG register to set the baud rate
RCSTA.SPEN=1; // To activate serial port (Tx and Rx pins)
RCSTA.CREN=1; // To enable continuous reception
Lcd_Init();
UART1_Init(9600);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
// LCD Stuff
LCD_Out(1, 1, "Lat ");
LCD_Out(2, 1, "Lon ");
LCD_Chr(1, 10, 0xB0); //Degree Character
LCD_Chr(2, 10, 0xB0); //Degree Character
LCD_Chr(1, 13, 0xB4); //' Character
LCD_Chr(2, 13, 0xB4); //' Character
while(1)
{
if (UART1_Data_Ready() == 1)
{
received = UART1_Read();
if (received == '$') // Check if sentence begins.
{
received = 0;
do
{
if (UART1_Data_Ready() == 1)
{
UART1_Read_Text(DataType, ",", 10); // Capture GPXXX word
received = 1;
}
}
while(received == 0);
// If it is GPGGA Data, then acquire it.
if ((DataType[2] == 'G') && (DataType[3] == 'G') && (DataType[4] == 'A'))
{
received = 0;
do
{
if (UART1_Data_Ready() == 1)
{
UART1_Read_Text(NMEA, "*", 100); // Stop at *XX checksum data
received = 1;
}
}
while(received == 0);
// Fill LCD with relevant data
// Latitude
LCD_Chr(1, 8, NMEA[10]);
LCD_Chr(1, 9, NMEA[11]);
LCD_Chr(1, 11, NMEA[12]);
LCD_Chr(1, 12, NMEA[13]);
LCD_Chr(1, 14, NMEA[15]);
LCD_Chr(1, 15, NMEA[16]);
LCD_Chr(1, 16, NMEA[17]);
LCD_Chr(1, 17, NMEA[18]);
LCD_Chr(1, 18, NMEA[19]);
LCD_Chr(1, 20, NMEA[21]);
// Longitude
LCD_Chr(2, 7, NMEA[23]);
LCD_Chr(2, 8, NMEA[24]);
LCD_Chr(2, 9, NMEA[25]);
LCD_Chr(2, 11, NMEA[26]);
LCD_Chr(2, 12, NMEA[27]);
LCD_Chr(2, 14, NMEA[29]);
LCD_Chr(2, 15, NMEA[30]);
LCD_Chr(2, 16, NMEA[31]);
LCD_Chr(2, 17, NMEA[32]);
LCD_Chr(2, 18, NMEA[33]);
LCD_Chr(2, 20, NMEA[35]);
}
received = "x";
}
}
}
} |
|
|