View previous topic :: View next topic |
Author |
Message |
Guest
|
|
Posted: Sun Mar 11, 2007 2:38 am |
|
|
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
|
|
Posted: Sun Mar 11, 2007 1:12 pm |
|
|
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
|
|
Posted: Sun Mar 11, 2007 9:19 pm |
|
|
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
|
|
|
pijang Guest
|
|
Posted: Mon Mar 12, 2007 2:07 am |
|
|
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
|
|
|
|