View previous topic :: View next topic |
Author |
Message |
vladtess
Joined: 14 May 2011 Posts: 26
|
ASCII to LCD (ADC conversion) |
Posted: Fri Jun 10, 2011 2:47 pm |
|
|
I've tried to google it and I have seen some results, but without much help.
So here is the code:
Code: | #include <16F877A.h>
#include "LCD.h"
#fuses hs, nowdt, noput, nobrownout, nolvp, nocpd, nowrt, nodebug, noprotect
#use delay(clock=20000000)
//==========================
void main(void)
{
disable_interrupts(GLOBAL);
unsigned int adcByte;
setup_adc(adc_clock_internal); //The ADC uses a clock to work
setup_adc_ports(AN0); //pin 19 ADC0
set_adc_channel(0); //This ADC0 is channel 0
lcd_init(); // Always call this first.
lcd_putc("Voltage is: ");
while (1) //stay in this loop until reset
{
adcByte=read_adc(); //read_adc() return an 8-bit variable
/*I’m using the byte returned as the delay for an LED */
lcd_gotoxy(13,1);
lcd_putc(adcByte);
delay_ms(500);
}
} |
On the LCD I get ASCII characters instead of 1-255 representation that I expect. Now, I know that I must convert it somehow, but I was curious if there is some library that I can use for that. If not, what can I do? Thanks much!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Jun 10, 2011 2:51 pm |
|
|
printf(lcd_putc,"%u",adcByte);
Best Wishes |
|
|
javick82
Joined: 12 Jul 2007 Posts: 43
|
|
Posted: Fri Jun 10, 2011 2:52 pm |
|
|
The "putc" functions use the byte value of the input.
The following all output the character A
putc('A')
putc(65)
putc(0x41)
I would recommend looking into the printf() function in the compiler manual. |
|
|
vladtess
Joined: 14 May 2011 Posts: 26
|
|
Posted: Fri Jun 10, 2011 5:48 pm |
|
|
Thanks you guys!! Works well. |
|
|
|