i am new using microcontrollers. at the moment im starting using 16f877 and need to start by programming the adc (10 bit). all i did for now is the code shown below. is it enough to read data? or does it need alteration?
i am using mplab to compile and proteus for schematics.
thanks
maria
#include <htc.h>
#include <pic.h>
unsigned int data;
void main(void)
{
//configuring input/outputs
PORTA = 0x00;
TRISA = 0xFF;
TRISB = 0x00;
//configuring ADC
ADCON0=0b00000001 //setting ADON on
ADCON1=0b10000000 //ADFM is set right
while(1)
{
ADCON0|= GODONE; //start conversion
{
break
}
if (ADRESH == 1)
{
data = ADRESL + 256;
}
else if (ADRESH == 2)
{
data = ADRESL + 512;
}
else if (ADRESH == 3)
{
data = ADRESL + 768;
}
else if (ADRESH == 0)
{
data = ADRESL;
}
}
}
i am using mplab to compile and proteus for schematics.
thanks
maria
#include <htc.h>
#include <pic.h>
unsigned int data;
void main(void)
{
//configuring input/outputs
PORTA = 0x00;
TRISA = 0xFF;
TRISB = 0x00;
//configuring ADC
ADCON0=0b00000001 //setting ADON on
ADCON1=0b10000000 //ADFM is set right
while(1)
{
ADCON0|= GODONE; //start conversion
{
break
}
if (ADRESH == 1)
{
data = ADRESL + 256;
}
else if (ADRESH == 2)
{
data = ADRESL + 512;
}
else if (ADRESH == 3)
{
data = ADRESL + 768;
}
else if (ADRESH == 0)
{
data = ADRESL;
}
}
}