|
|
View previous topic :: View next topic |
Author |
Message |
kcj
Joined: 05 Oct 2011 Posts: 33
|
16x2 LCD coding problem. |
Posted: Sat Oct 22, 2011 2:55 pm |
|
|
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
|
|
Posted: Sat Oct 22, 2011 3:15 pm |
|
|
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
|
|
Posted: Sun Oct 23, 2011 6:29 am |
|
|
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 ////
//// |
|
|
|
|
|
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
|