ANALOG TO DIGITAL (ADC) ON AND OFF LED USING VARIABLE RESISTOR VOLTAGE CONTROLLER

#include<p18f4580.h>
#include<string.h>
#include<delays.h>
#pragma config WDT=OFF
#pragma config OSC=HS
#pragma config PWRT=ON
#pragma config DEBUG=OFF
#pragma config LVP=OFF
#define  rs   PORTBbits.RB4
#define  rw   PORTBbits.RB1
#define  en   PORTBbits.RB5
#define LED PORTBbits.RB7
unsigned long ADC,MOV,COL;
unsigned char OFF[]="...LED OFF...",M,F,ON[]="...LED ON....";
void lcddata(unsigned char D);
void lcdcmd(unsigned char D);
void main(void)
{
    ADCON0=0x01;
    ADCON1=0x0b;
    ADCON2=0xbc;
    TRISD=0;
    TRISB=0;
    PORTB=0;
    PORTD=0;
    Delay100TCYx(100);
    lcdcmd(0x38);
    lcdcmd(0x01);
    lcdcmd(0x0C);
    lcdcmd(0xC0);
    while(1)
    {
        lcdcmd(0x80);
        for(F=0;F<40;F++)
            {
            Delay10KTCYx(1);
            ADCON0=0x01;
            Delay10KTCYx(1);
            ADCON0bits.GO=1;
            while(ADCON0bits.DONE==1);
            MOV=ADRESH;
            MOV<<=8;
            ADC=MOV|ADRESL;
            COL=COL+ADC;
            }
        COL=COL/40;
        if(COL<38)
        {
            for(M=0;M<strlen(OFF);M++)
            lcddata(OFF[M]);
            LED=0;
        }
        else
        {
            for(M=0;M<strlen(ON);M++)
            lcddata(ON[M]);
            LED=1;
        }
    }
}
void lcddata(unsigned char D)
{
    PORTD=D;
    rs=1;
    rw=0;
    en=1;
    Delay100TCYx(1);
    en=0;
    Delay100TCYx(100);
}
void lcdcmd(unsigned char D)
{
    PORTD=D;
    rs=0;
    rw=0;
    en=1;
    Delay100TCYx(1);
    en=0;
    Delay100TCYx(100);
}


//INPUT USE AN0 TO PIN2 VARIABLE RESISTOR.... PIN1 TO 5V AND PIN3 TO GND
//LCD PORT D
//RS    PORTB 4
//RW   PORTB 1
//EN    PORTB 5
//LED PORTB 7
KEMBALI KEATAS