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

ASCII to LCD (ADC conversion)

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



Joined: 14 May 2011
Posts: 26

View user's profile Send private message

ASCII to LCD (ADC conversion)
PostPosted: Fri Jun 10, 2011 2:47 pm     Reply with quote

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: 19518

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 2:51 pm     Reply with quote

printf(lcd_putc,"%u",adcByte);

Best Wishes
javick82



Joined: 12 Jul 2007
Posts: 43

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 2:52 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 5:48 pm     Reply with quote

Thanks you guys!! Works well.
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