Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ADC value reading in ccs c and pic16f877a

Status
Not open for further replies.

john120

Banned
Joined
Aug 13, 2011
Messages
257
Helped
11
Reputation
22
Reaction score
10
Trophy points
1,298
Activity points
0
High guy ?help me ploz to solve the issue of reading adc value,I am using ccs c compiler,pic16f877a and lcd 16*2;I want to read the adc value on ANO,but the lcd is always showing 0;
and the error in proteus is :ADC conversion clock period (1e-7)is possibly invalid for device clock,can you plz help me?
see the parts of my codes here below:
#include <16F877A.h>
#DEVICE ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include "lcd.c"

void tempdisplay();
void kagaba();
void messagedisplay();


int1 flag;
float voltsf,MR;
float rise1, rise2, period;
unsigned int adc_value, volts1,volts2,volts3,volts4,volts5,voltsd,x;


#int_ccp1
void isr()
{
if (flag==0)
{
rise1 = CCP_1;
flag=1;
}
else if (flag==1)
{
rise2 = CCP_1;
period=(rise2-rise1);
flag=0;
}
}

void tempdisplay()
{


adc_value = read_adc();
x=adc_value;
volts1 = ((float)(x * 500)/1023.0);
delay_ms(10);
volts2 = ((float)(x * 500)/1023.0);
delay_ms(10);
volts3 = ((float)(x* 500)/1023.0);
delay_ms(10);
volts5 = ((float)(x* 500)/1023.0);
delay_ms(10);
volts4 = ((float)(x* 500)/1023.0);
delay_ms(10);
voltsd = (volts1+volts2+volts3+volts4+volts5)/5;
voltsf=(voltsd*1.8)+32;

}

void kagaba()
{
delay_ms(2000);
printf(lcd_putc, "\fWELCOME");
delay_ms(2000);
}





void main(void)
{

flag=0;
lcd_init();
lcd_gotoxy(1,1);
delay_us(200);

printf(lcd_putc, "\f%3.0f", period);
//delay_ms(2000);
delay_us(2000);
printf(lcd_putc, "\f%3.0f\r\n",voltsf);
delay_us(500);


setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
delay_us(350);


................................
Thx
 

hi , i just wonder why you use a delay function for 350 us after choosing AN0?
16 to 20 us will be fine .
try this !
what about your interrupt execution time ?
 

What is the purpose of finding the volts1 to volts5? All will have the same values. It is useless piece of code. Just calculate one volt value. Post your latest code.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top