Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ADC for Hi-tech C (pic16F877A)

Status
Not open for further replies.

mncp

Newbie level 6
Joined
Dec 12, 2010
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,460
Hi All Guru,

I am very new in PIC and still learning stage.I have some error encountered while building with hi-tech C. I have posted in related forum as well
https://www.edaboard.com/threads/206107/#post890663
I could not find the solution for GODONE??

Error [192] undefined identifier "GODONE"

If you can explain to me,please help. Thanks a lot.
Clovis
 

If you search in <pic.h> for 877, you will find that it includes <pic1687x.h>. This is the file that defines the register names for the pic16f877.

if you look in this file you will find

/* ADCON0 bits */
volatile bit ADCS1 @ (unsigned)&ADCON0*8+7;
volatile bit ADCS0 @ (unsigned)&ADCON0*8+6;
volatile bit CHS2 @ (unsigned)&ADCON0*8+5;
volatile bit CHS1 @ (unsigned)&ADCON0*8+4;
volatile bit CHS0 @ (unsigned)&ADCON0*8+3;
volatile bit ADGO @ (unsigned)&ADCON0*8+2;
// Alternate definition for compatibility with other devices
volatile bit GODONE @ (unsigned)&ADCON0*8+2;
volatile bit ADON @ (unsigned)&ADCON0*8+0;

So GODONE and ADGO are both defined. You should not be getting the error.
 
  • Like
Reactions: mncp

    mncp

    Points: 2
    Helpful Answer Positive Rating
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++);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top