#include <p18f2520.h>
#include <GLCD.h>
#include <adc.h>
#include <delays.h>
#include <stdlib.h>
#pragma config WDT = OFF, LVP = OFF, OSC = INTIO67
void main (void){
int read;
char adc_ret[10];
ADCON1 = 0x0d;
CMCON = 0x07; // no comparators
OSCCON = 0x70;
TRISA = 0XFF;
TRISC = 0x00;
//Setup
Init_GLCD();
OpenADC(ADC_FOSC_RC & ADC_LEFT_JUST & ADC_12_TAD,
ADC_CH1 & ADC_INT_OFF & ADC_VREFPLUS_VDD &
ADC_VREFMINUS_VSS, 13);
SetChanADC( ADC_CH1 );
PutMessage((rom char*)"test");
Delay10KTCYx(200);
while (1){
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for completion
read = 523;ReadADC();
itoa(read,adc_ret);
PutMessage((rom char*)adc_ret);
Delay10KTCYx(250);
SetPos(0,0);
}
//This section of code works, I used it check ADC function
/*ConvertADC();
while(BusyADC());
i = ReadADC();
if(i<125)PORTC = 0b00000001;
else if(i>126 && i<250)PORTC = 0b00000011;
else if(i>251 && i<375)PORTC = 0b00000011;
else if(i>376 && i<400)PORTC = 0b00000111;
else if(i>401 && i<525)PORTC = 0b00001111;
else if(i>526 && i<650)PORTC = 0b00011111;
else if(i>651 && i<750)PORTC = 0b00111111;
else if(i>751 && i<875)PORTC = 0b01111111;
else if(i>876 && i<1023)PORTC = 0b11111111;
*/
}