|
|
View previous topic :: View next topic |
Author |
Message |
croc4
Joined: 02 Sep 2005 Posts: 10
|
transfering data to LCD via I2C |
Posted: Fri Mar 17, 2006 1:32 pm |
|
|
I have a project that I'm stuck on. I have a pic (16F628A) that I am using as a I2C master, I'm bit banging the protocol. I also have a ADC connected to the pic. The goal is to read the ADC and then display the reading on the LCD.
I have everything working except for the LCD. I connected a console the the pic and can print the voltage that the pic is reading form the ADC just fine.
My issue is that when I send characters to the LCD (for example "test") it works fine, but to send in numeric values, the internal character set of the LCD is 0x30 to 0x39 (so to send the LCD the number '5', you send 0x35 over the I2C bus. Not my problem is (after much ado) is that if I get a reading of 1.243 from the ADC how does one translate to the LCD's numeric character set, I would imagine that you would send in (0x31, ".", 0x32, 0x34,0x33) which would display fine, but how do you break up the float value of 1.243?
I'm new to programming, so I'm sure I'm going about this the hard way, but I've tried to figure out how to do this and I keep comming up blank
TIA,
Croc4 |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
Re: transfering data to LCD via I2C |
Posted: Fri Mar 17, 2006 1:41 pm |
|
|
croc4 wrote: | ...how do you break up the float value of 1.243? |
The sprintf() function might come handy. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 17, 2006 1:49 pm |
|
|
Use printf to convert to ASCII. Use the re-direction feature of the CCS
printf() function to send the output to your lcd driver. Example:
Code: |
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <lcd.c>
//===============================
void main()
{
float value;
lcd_init();
value = 1.243;
printf(lcd_putc, "%7.3f", value);
while(1);
}
|
|
|
|
croc4
Joined: 02 Sep 2005 Posts: 10
|
Thank you!!! |
Posted: Fri Mar 17, 2006 2:11 pm |
|
|
Thanks, the printf, did the trick. I didn't know you could do that, I have a lot to learn.
Thanks again,
Croc4 |
|
|
gs
Joined: 22 Aug 2005 Posts: 30 Location: Ioannina - Greece
|
|
Posted: Sat Mar 18, 2006 7:52 pm |
|
|
You could also multiply with 1000 and print the result as 1000's,".",100's,10's,1's
If you want to avoid use of floats you could modify the calculations this way. _________________ www.hlektronika.gr |
|
|
|
|
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
|