CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

UART and GPS

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
uni_student



Joined: 01 Aug 2007
Posts: 38
Location: AUckland, NEW ZEALAND

View user's profile Send private message Send e-mail MSN Messenger

UART and GPS
PostPosted: Sun Dec 07, 2008 2:23 pm     Reply with quote

Hi, trying to display GPS data on an LCD that start with"$P" or "$G" and all others discarded. For some reason I am still displaying other data such as"$F" and "$ ". GPS is working fine and LCD working fine , but somewhere in the code I am going wrong! Help appreciated, Cheers.

Code:

#include <18f452.h>
#include <string.h>
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
//
#use rs232 (baud=4800, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8, ERRORS)

//

//Misc defines
#define GREEN_LED PIN_E2

//LCD defines
#define D0_LCD PIN_B0
#define D1_LCD PIN_B1
#define D2_LCD PIN_B2
#define D3_LCD PIN_B3
#define D4_LCD PIN_B4
#define D5_LCD PIN_B5
#define D6_LCD PIN_B6
#define D7_LCD PIN_B7
#define EN_LCD PIN_D6
#define RS_LCD PIN_D7

#define RW_LCD PIN_D5
#define TOP_LINE 0x80
#define BOTT_LINE 0xC0
#define CLEAR_DISP 0x01
#define RETURN_HOME 0x02

void LCD_INIT (int x);
void DATA_MANIP (unsigned int x);




void LCD_INIT (int x){
..........
}

void DATA_MANIP (unsigned int x){
    output_high (EN_LCD);
    output_bit ( D0_LCD, x & 0x01 );
    output_bit ( D1_LCD, x & 0x02 );
    output_bit ( D2_LCD, x & 0x04 );
    output_bit ( D3_LCD, x & 0x08 );
    output_bit ( D4_LCD, x & 0x10 );
    output_bit ( D5_LCD, x & 0x20 );
    output_bit ( D6_LCD, x & 0x40 );
    output_bit ( D7_LCD, x & 0x80 );
    output_low (EN_LCD);
}


//
void main (void){
   char r;
   int x, y;

   LCD_INIT (0);   //
   x=0;
   y=0;
   while(TRUE){
       r=getc();
       if ((x>0)&&(x<15)){   //Display charactors to end of lcd display
         x++;
         DATA_MANIP (r);
       } else if (x==15){    //End of display line
         delay_ms(2000);
         x=0;
         if(y==0){
            LCD_INIT (2); //Bottom Line
            y=1;
         } else{
            LCD_INIT (1); //Top Line
            y=0;
         }
       } else if ((r=='$')&&(x==0)){  //start of new gps data
         r=getc();
         if (r=='G') {
            DATA_MANIP ('$');
            DATA_MANIP ('G');
            x++;
         }
         if (r=='P'){
            DATA_MANIP ('$');
            DATA_MANIP ('P');
            x++;
         }
       } else{
         x=0;
       }
    }
}


Last edited by uni_student on Sun Dec 07, 2008 2:49 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 07, 2008 2:38 pm     Reply with quote

Post the manufacturer and part number of your LCD.
uni_student



Joined: 01 Aug 2007
Posts: 38
Location: AUckland, NEW ZEALAND

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Sun Dec 07, 2008 2:48 pm     Reply with quote

Quote:

Post the manufacturer and part number of your LCD.


Unsure of manufacturer of LCD (will check when home from work), but has Hitachi HD44780 driver in it. 16x2 LCD display, got it from futurlec.com.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 07, 2008 2:51 pm     Reply with quote

My suggestion is to use the flex LCD driver:
http://www.ccsinfo.com/forum/viewtopic.php?t=24661
Then you can call lcd_putc() to display a character, or use printf
to display a string (and re-direct the output of printf to lcd_putc).
It's much easier than your method.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Dec 07, 2008 4:28 pm     Reply with quote

Although the code has long-winded actions, as the port B single bit output, it most likely doesn't keep the required timing according to HD44780 spec. With a parallel interface, it's easy to check the busy flag before writing to the display.

The single bit output can be replaced by a simple output_b(x);
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group