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

16x2 LCD coding problem.

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



Joined: 05 Oct 2011
Posts: 33

View user's profile Send private message

16x2 LCD coding problem.
PostPosted: Sat Oct 22, 2011 2:55 pm     Reply with quote

Hi All,

I am developing a project that sends force data wirelessly via xbees to a PIC18F13k22 to be displayed on a 16x2 LCD screen.

I am new to c coding but somehow have managed to get all the hardware working on a breadboard and have written the following code
Code:

#include <18f13k22.h>
#device ICD=TRUE                     
#use delay(clock=1M, crystal)
#use rs232(baud=9600,xmit=PIN_B7,rcv=PIN_B5,ERRORS)

#include <Flex_lcd.c>
#define Gled PIN_C5
#define Yled PIN_C4

int data18;
int data19;
int data20;
int data21;

int i;
int buffer [22];
int read;
float forceA;
int16 byteA;
float voltsA;

void main()
{
lcd_init();

while(1)
{   

//Checks if there are character in the buffer
     if (kbhit(true))
    {       
         //retrieves the bytes     
          read = getc();         

            //First byte in a 22byte packet xbee sends
            if (read == 0x7E)
            {
                //reads the 22 bytes
                 for(i=0;i<22;i++)
                    {
                      output_low(GLED);
                      read = getc();
                      buffer[i]=read;
                    }         
                     
                     //byte 19&20 contain the force data
                     data18=buffer[19];
                     data19=buffer[20];
                     data20=buffer[21];
                     data21=buffer[22];       
   
                     //converts the 10 bit number in integer
                     byteA=((data19*256)+data20);

                     //Formulea calculated in excell relating force data to volts                 
                     //and bytes xbee sends
                     forceA=((1.09*byteA)-305.18);
                     voltsA=(0.0012*byteA);
                   
                     //prints force and volts result on LCD
                     printf(lcd_putc, "\VoltsA...%4.2f\n", voltsA);
                     delay_ms(1000);
                     printf(lcd_putc, "\ForceA...%4.2f\n", forceA);
                 
                     
            }     
      }
      else
   
    output_high(YLED);
    delay_ms(500);   
}
}

I am having trouble with the LCD, with this code it displays the volt data in the top line LCD, then the Force data in bottom line, then the bottom line changes to force data.

The top line never changes it value, but the bottom line updates there values.

How do i get the top line to automatically update it value?

I have looked in the CCS manual but there is not a lot of command that i can see on LCD, is there any basic code commands that would be useful to a beginner like myself on LCD's.
i.e is there a command to clear the screen of data?

Also the data is being sent rather slowly,i am using random leftover pins for the LCD configuration, is there a quicker way to transmit data?
Would increasing the baud rate do this?

Any help would be greatly appreciated, but i mainly need help on the LCD.

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 22, 2011 3:15 pm     Reply with quote

Quote:
i.e is there a command to clear the screen of data

Look at the list of lcd commands given in the comments at the top of
this CCS driver file:
Quote:

c:\program files\picc\drivers\lcd.c
kcj



Joined: 05 Oct 2011
Posts: 33

View user's profile Send private message

PostPosted: Sun Oct 23, 2011 6:29 am     Reply with quote

Thanks PCM programmer,

Code:

                     //prints force and volts result on LCD
                     printf(lcd_putc, "\fVoltsA...%4.2f\n", voltsA);
                     delay_ms(1000);
                     printf(lcd_putc, "\ForceA...%4.2f\n", forceA);
                 


The \f cleared the screen, and it is working now.
For anybody else who may have similar newbie problem, the commands are

Code:

///////////////////////////////////////////////////////////////////////////////
////                             LCD.C                                     ////
////                 Driver for common LCD modules                         ////
////                                                                       ////
////  lcd_init()   Must be called before any other function.               ////
////                                                                       ////
////  lcd_putc(c)  Will display c on the next position of the LCD.         ////
////                 \a  Set cursor position to upper left                 ////
////                 \f  Clear display, set cursor to upper left           ////
////                 \n  Go to start of second line                        ////
////                 \b  Move back one position                            ////
////              If LCD_EXTENDED_NEWLINE is defined, the \n character     ////
////              will erase all remanining characters on the current      ////
////              line, and move the cursor to the beginning of the next   ////
////              line.                                                    ////
////              If LCD_EXTENDED_NEWLINE is defined, the \r character     ////
////              will move the cursor to the start of the current         ////
////              line.                                                    ////
////                                                                       ////
////  lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)        ////
////                                                                       ////
////  lcd_getc(x,y)   Returns character at position x,y on LCD             ////
////                                                           
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