hamed8419215
Member level 5
I write the following program (in mikroC pro) and get exactly 508 from AD conversion:
//////////////////////////////////////////////////////////////////////////
//Fosc = 4Mhz, OSC = XT, WDT = Disable //
//////////////////////////////////////////////////////////////////////////
void main()
{
TRISC=0x00; //PORTC output
TRISB=0xF0; //Low nibble of PORTB output
TRISA=0xFF; //All PORTA pins as input
ADCON1=0x80; //Right justified, all analog pins as analog input
ADCON0=0xC1; //RC osc, AD on
while(1)
{
Delay_us(50); //Delay for aquation
ADCON0.B2=1; //Setting Go/Done bit (start AD conversion)
while(ADCON0.B2) //Do nothing until conversion complete
asm nop;
PORTC=ADRESL; //Low byte of result
PORTB=ADRESH; //High byte of result
}
}
/////////////
You can see the result as follow:
//////////////////////////////////////////////////////////////////////////
//Fosc = 4Mhz, OSC = XT, WDT = Disable //
//////////////////////////////////////////////////////////////////////////
void main()
{
TRISC=0x00; //PORTC output
TRISB=0xF0; //Low nibble of PORTB output
TRISA=0xFF; //All PORTA pins as input
ADCON1=0x80; //Right justified, all analog pins as analog input
ADCON0=0xC1; //RC osc, AD on
while(1)
{
Delay_us(50); //Delay for aquation
ADCON0.B2=1; //Setting Go/Done bit (start AD conversion)
while(ADCON0.B2) //Do nothing until conversion complete
asm nop;
PORTC=ADRESL; //Low byte of result
PORTB=ADRESH; //High byte of result
}
}
/////////////
You can see the result as follow: