View previous topic :: View next topic |
Author |
Message |
project2010
Joined: 14 Mar 2010 Posts: 21
|
get data from LCD problem |
Posted: Thu May 13, 2010 2:41 pm |
|
|
i can use the lcd_getc function,but
if i want a 2 digit data, how can i get it?
(using the Flexible LCD driver for 20x4 LCDs)
for example
123456789 < 1 in lcdxy (1,1)
i would like to get 12 , 34 ,56 , 78 into
int8 A1,
int8 A2,
int8 A3,
int8 A4,
A1 = lcd_getc(1,1); <how can i keep get data?
A2 = lcd_getc(3,1);
thank you,
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 13, 2010 3:05 pm |
|
|
Since your program wrote the data to the LCD, you should already
know what the data is. You should not have to read it from the LCD.
But, you need to read the data into a 3-byte array. The last byte of
the array must be set to 0x00. Then use atoi() to convert the numeric
string to an integer. |
|
|
project2010
Joined: 14 Mar 2010 Posts: 21
|
|
Posted: Thu May 13, 2010 11:58 pm |
|
|
Actually, I'm using the keypad to input some number, and store it.
Use for set the time on DS1307.....so need 2 digits stored in one number....
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
project2010
Joined: 14 Mar 2010 Posts: 21
|
|
Posted: Sat May 15, 2010 2:46 pm |
|
|
Code: |
#include<18F4620.h> //include 18F4620 ports
#device adc=10
#fuses HS,NOWDT,PUT,NOPROTECT,NOLVP,NODEBUG
#use delay(clock=20000000) //use 20MHz crystal
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <LCD20x4.c>
#include <KBD.c>
#include <ds1307.c>
#include <stdlib.h>
char abc[2];
int x;
void main()
{
lcd_init();
while(true)
{
abc[0]=2;
abc[1]=5;
abc[2]=0x00;
x=atoi(abc);
printf(lcd_putc,"\%u",x);
}
} |
i have try some pattern....but it doesn't work
keep display 0.......... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19544
|
|
Posted: Sat May 15, 2010 3:03 pm |
|
|
abc, is too small. You have allocated two storage locations, and are then addressing three locations....
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat May 15, 2010 4:48 pm |
|
|
Also, you are not loading the array with ASCII values. The atoi() function
expects an ASCII string. In C, to tell the compiler that a number should
be encoded in ASCII, you should put single quotes around the number.
Example:
However, don't put quotes around the final 0x00. It must actually be
a binary 0. Keep it the same as shown in your post. |
|
|
project2010
Joined: 14 Mar 2010 Posts: 21
|
|
Posted: Sun May 16, 2010 11:33 am |
|
|
Code: |
#include<18F4620.h> //include 18F4620 ports
#device adc=10
#fuses HS,NOWDT,PUT,NOPROTECT,NOLVP,NODEBUG
#use delay(clock=20000000) //use 20MHz crystal
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <LCD20x4.c>
#include <KBD.c>
#include <ds1307.c>
#include <stdlib.h>
int a;
char abc[10];
int x;
void main()
{
lcd_init();
while(true)
{
int a=8;
abc[0]='2';
abc[1]='5';
x=atoi(abc);
printf(lcd_putc,"\%u",x);
}
}
|
it work it can display 25
but how can i put "int a" into "abc[0]"?
that's does not work ,result become 0
Also is atoi max support 0-255 right?
Last edited by project2010 on Sun May 16, 2010 12:16 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 16, 2010 11:46 am |
|
|
1. You ignored Ttelmah's post completely, in which he told you to
increase the size of the abc array.
2. You ignored my example of using single quotes, and changed it to
use double quotes.
Someone else can help on this thread. |
|
|
project2010
Joined: 14 Mar 2010 Posts: 21
|
|
Posted: Sun May 16, 2010 12:18 pm |
|
|
PCM programmer wrote: | 1. You ignored Ttelmah's post completely, in which he told you to
increase the size of the abc array.
2. You ignored my example of using single quotes, and changed it to
use double quotes.
Someone else can help on this thread. |
sorry, i forgot to update the code....
i have read the reply for all guy...
abc[10] increased, use single ' ' < but look like same. |
|
|
|