ayesh
Newbie level 1
This will give an output for P .P is a voltage. But when we set any voltage(0-5v) as input, output not shows the correct value.
please give a solution...........
please give a solution...........
Code:
/* Sample code to set up the A2D module */
void init_a2d(void){
ADCON0=0x50; // select Fosc/2
ADCON1=0x80; // select left justify result. A/D port configuration 0
ADON=1; // turn on the A2D conversion module
}
/* Return an 8 bit result */
unsigned char read_a2d(){
GO=1; // initiate conversion on the selected channel
while(GO)continue;
return((ADRESH<<8)+(ADRESL));
}
void main(void){
unsigned int x,p;
sci_Init(9600,0);
init_a2d(); // initialise the A2D module
GIE=0; // we don't want interrupts
TRISA=0xff;
TRISB=0x00; // the lower four bits of POTRB will be used in output mode
TRISC=0x80;
PORTC=0xff;
while(1){
x=read_a2d(); // sample the analog value on RA0
[COLOR="#FF0000"] p = (x*5000)/1023;[/COLOR]
char array[10];
int i = p;
sprintf(array, "%d", i);
for(int j=0;j<5;j++)
sci_PutByte(array[j]);
while(1){
}
}
}
Last edited by a moderator: