ANALOG TO DIGITAL (ADC) OUTPUT LED BINARY


#include<p18f4580.h>
#include<delays.h>
#pragma config OSC=HS
#pragma config LVP=OFF
unsigned int hml;
void adc(void);
void main(void)
{
ADCON0=0X05;
ADCON1=0;
ADCON2=0Xee;
TRISB=0;
while(1)
{
adc();
PORTB=ADRESL;
}
}
void adc(void)
    {
Delay10KTCYx(1);
ADCON0bits.GO=1;
while(ADCON0bits.DONE==1);
hml=ADRESH;
hml<<=8;
hml=hml|ADRESL;
    }

//INPUT USE AN0 TO PIN2 VARIABLE RESISTOR.... PIN1 TO 5V AND PIN3 TO GND
//USE 8LED OUTPUT PORTB
KEMBALI KEATAS