Dear Sir,
Yes. I edit " volatile bit GODONE @ (unsigned)&ADCON0*8+2; '
this line in my code and I can build sucessfully.Thanks. But I still can't get the output from my code.RED LED at RC5 got blink although object is not infront of the sensor.Is there anything wrong with my code. By right, I wanted to be measure distance from my GP2D120 sensor and signal output from my 3 LEDs, RC5, RC6 n RC7. But still can't get the correct measurement. Can you please advice? Thanks.
#include<pic.h>
__CONFIG ( 0x3F32 );
#define PORTBIT(adr,bit) ((unsigned)(&adr)*8+(bit)) //no modify this line
static bit LEDR @ PORTBIT(PORTC,5);
static bit LEDG @ PORTBIT(PORTC,6);
static bit LEDB @ PORTBIT(PORTC,7);
volatile bit GODONE @ ((unsigned)&ADCON0*8)+1;
void delay(unsigned char itime);
void main(void)
{
//8bit data-type variables
unsigned char x; //ADC low byte
unsigned char y; //ADC high byte
unsigned int z; //final result
TRISC=0x00; //output
TRISA=0xFF; //inputs
LEDR=0xFF; //clear/switch off LEDS
LEDG=0xFF; //clear/switch off LEDS
LEDB=0xFF; //clear/switch off LEDS
while(1)
{
//ADFM=1, all i/ps analog, +VREF enabled
//Configure the functions of the Port bits
ADCON1=0b10000001;
//clock/channel select & enable bits
//controls the operation of the A/D module
ADCON0=0b11000001;
delay(1);
//Start a2d conversion
//Set GO bit (ADCON0=ADCON0|1
GODONE=1;
//wait end-of-conversion (conversion complete)
while(GODONE==1);
x=ADRESL; //store low byte
x=x>>1; //shift 1 bit to the right
y=ADRESH; //store high byte
y=y<<7; //shift left 7 bit position
z=x|y; //combine together
LEDR=~z; //output on leds
}
}
void delay(unsigned char itime)
{
unsigned char i,j;
for(i=0;i<itime;i++)
for(j=0;j<1;j++);
}