#include <p18f4550.h>
#include <math.h>
#include <timers.h>
#include <adc.h>
#pragma config WDT = OFF
void main(){
char a,b;
float r ;
float temp;
int ReadPR;
float sampledPR;
ADCON1 = 0x0E;
TRISD = 0x00;
TRISB = 0x80;
while(1){
if(!PORTBbits.RB7){
TRISB = 0x00;
/*config A/D*/
OpenADC(ADC_FOSC_4 &
ADC_RIGHT_JUST &
ADC_2_TAD,
ADC_CH0 &
ADC_INT_OFF &
ADC_VREFPLUS_VDD,
0x0E);
/*wait for acquisition time*/
Delay1KTCYx(1);
/*start A/D conversion*/
ConvertADC();
/*wait till the conversion completed*/
while(BusyADC());
/*
conversion finished
read the converted value
*/
ReadPR = ReadADC();
sampledPR = 5*(ReadPR/1023);
temp = (1.4+sampledPR)/30;
r = pow( 10,temp );
r = 1/r;
a = (char) r;
b = (char)((r-a)*10);
PORTB =a;
PORTD =b;
TRISB = 0x80;
CloseADC();
}
}
}