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 support@ccsinfo.com

PIC to LCD
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








PostPosted: Sun Mar 11, 2007 2:38 am     Reply with quote

Sir, actually at the include coding have stdlib.h, math.h and flex_lcd.c
I dont know why it does not appear when i posted at this forum

#include <16f877a.h>
#device adc=10;
#include
#include
#use delay (clock = 4000000)
#fuses HS, noprotect, nowdt, nolvp
#byte PORTA = 5
#byte PORTB = 6
#define use_portb_lcd TRUE
#include

void main()
{
double valuein, valueout, result;


set_tris_b(0); //set port b as output
setup_port_a(ALL_ANALOG); //port a analog input
setup_adc(ADC_CLOCK_INTERNAL);

portb=0x00;
delay_ms(3000);
portb=0;

lcd_init();

do

{

set_adc_channel(1);
delay_us(20);
valuein = read_adc(1); //read from port AN1
valueout = valuein*0.035;
result=48+valueout;


lcd_putc("\f The value is\n");
lcd_putc( 48+valueout );

delay_ms(2000);

while(1);

}

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 11, 2007 1:12 pm     Reply with quote

The #include files are missing because when you posted your code,
you didn't disable HTML. There's a tickbox below the posting window
to do this. It looks like this:
Quote:
x Disable HTML in this post

I have tried to get the forum Admin to disable HTML by default for
the whole forum, but it hasn't happened.


Regarding your program, lcd_putc() can't accept a 'double' as a
parameter. It's expecting an 8-bit unsigned integer. You have
to convert the result of the expression into an integer by 'casting' it.
Example:
Code:
putc((int8)(48+valueout));
pijang
Guest







PostPosted: Sun Mar 11, 2007 9:19 pm     Reply with quote

what do u mean by casting?
Is it i have to change the double function to int8 at the top coding?

I have read some notes telling that we must limit the input value.
For example if my input is until 4 or 5 decimal places, i have to cut it down to 2 or 3 depends on my PIC. Is it right?
Then can i know how to limit the input value until 1 or 2 decimal places
For example let say 2.3569 become 2.35..

Then i have to set the program become like this
lcd_putc(48+D1&"."&48+D2&48+D3);

D1=first digit which is 2
D2=second digit after "." which is 3
D3=third digit which is 5

How do i want to set this coding if this assumption is correct?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 11, 2007 10:21 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=29157&highlight=printf+lcdputc
pijang
Guest







PostPosted: Mon Mar 12, 2007 2:07 am     Reply with quote

oo. Now i understand...
So i must use printf command for my analog input..
So how about the rest of my question..

can i limit the value from my input until 2 decimal places?
and what i should declare at the top of this coding?

Is it just using the double function and change lcd_putc to prinf
or i have to use int8 instead of double function?

for example
int8 valuein, valueout, result;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 12, 2007 2:19 am     Reply with quote

See this example program that I posted earlier in the thread.
It shows exactly how to do it.
http://www.ccsinfo.com/forum/viewtopic.php?t=28842&start=7
Also, you need to get a book on the C language or use an
online reference.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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