18F4550 ADC test


//variable voltage on AN0 is displayed on PORTB and PORTD in //10bit resolution
//modified codes of mikroc IDE example
//4550 ADC converter
//bit0 to bit7 on PORTB
//bit8 and bit 9 to PORTD bit7 and bit6
//FOSC IS 8mhz
//Tosc= 1/8mhz=12.5e-6
//8xtosc=1e-6
//16xtosc=2e-6
//test on Tad=2e-6
//minimun TACQ is 2.45e-6
//2xTad=4e-6 is used

unsigned int res;
void main()
{
 //OSCcON=0xff;
//OSCCON=0b01110000;

 ADCON1=0x00;       //AN0 as analog i/p on RA0
                   //vref+ to vdd and vref- to vss
                 
 // ADCON2= 0b10001101; //Tacq=2TAD, TAD=16Tosc
  TRISB=0x00;

  TRISD=0x00;      //use only bit7 and bit 6
  TRISA=0xff;
 
   for(;;)
  {
  res=Adc_Read(0);
  PORTB=res;
  PORTD=res>>2;
  delay_ms(10);

  }
 
 
}

 


Comments

Popular posts from this blog

Inductance caculator

Pointer to object array