0144224
Newbie level 4

Just a quick overview. I'm about 3 weeks into my C program at School and we're working with the pic16f887. I've been working on this lab for 2 days and its driving my crazy, I'm really stuck now! It's so hard to explain here in detail where I'm going wrong because I don't really know myself. I will post my code below and if someone can point me in the right direction that would be great. All I'm trying to do is get a voltage reading from my pot if the voltage is between certain points. If it is bewteen the voltage reference points I set then the LED indicators and or buzzers will sound. I have choosen RB3,RB4 as the outputs to my leds and AN13 as my analog input pin
#include <htc.h>
__CONFIG(LVPDIS &BORDIS & INTCLK & WDTDIS &PWRTEN);
unsigned char Lights[]={0xff};
static unsigned int ADReading = 0;\
float value = 0;
void Initialize();
void GetAnalogVoltage();
main()
{
Initialize();
for(;
// a for statement that will go on forever
GetAnalogVoltage();
}
void Initialize()
{
OSCCON = 0x7E; // Sets up internal oscillator for 8 MHz.
PORTB =0; // sets porta to 0
TRISB4 = 0; // Selects the output pin.
TRISB3 = 0,
ANS13 = 1; // pin is assigned as an analog input
TRISB = 0; // Trisb is output to light led's
ADCON0 = 10110000; // Selected the input and frequency of oscilation 8mghs/32
ADCON1 = 10000000; // Sets voltage reference A/D conversion results right justified, vdd +, vdd -
}
void GetAnalogVoltage() // Data type, all of the below processes the conversion
{
char i;
ADON = 1; //Analog to Digital Clock is enabled
for(i = 0;i<6;i++); // loop for delay. Waiting time for acquisition
GODONE = 1; // Anolog to Digital conversion in progress, by setting this bit to 1 it starts the conversion cycle
while(GODONE); // Puts the results of the conversion cycle in a while loop. when low the results will go to ADreading
ADReading = ADRESH *256 + ADRESL; // multiplies hi value by 256 and adds low value giving us a 10bit value
value =(5.0*(ADReading/1023.0));
PORTB=0xff;
if(value >=1&&value <=4)
{
TRISB3 =1;
}
else(value <=1&&value >=4);
{
TRISB4 =1;
}
}
#include <htc.h>
__CONFIG(LVPDIS &BORDIS & INTCLK & WDTDIS &PWRTEN);
unsigned char Lights[]={0xff};
static unsigned int ADReading = 0;\
float value = 0;
void Initialize();
void GetAnalogVoltage();
main()
{
Initialize();
for(;
GetAnalogVoltage();
}
void Initialize()
{
OSCCON = 0x7E; // Sets up internal oscillator for 8 MHz.
PORTB =0; // sets porta to 0
TRISB4 = 0; // Selects the output pin.
TRISB3 = 0,
ANS13 = 1; // pin is assigned as an analog input
TRISB = 0; // Trisb is output to light led's
ADCON0 = 10110000; // Selected the input and frequency of oscilation 8mghs/32
ADCON1 = 10000000; // Sets voltage reference A/D conversion results right justified, vdd +, vdd -
}
void GetAnalogVoltage() // Data type, all of the below processes the conversion
{
char i;
ADON = 1; //Analog to Digital Clock is enabled
for(i = 0;i<6;i++); // loop for delay. Waiting time for acquisition
GODONE = 1; // Anolog to Digital conversion in progress, by setting this bit to 1 it starts the conversion cycle
while(GODONE); // Puts the results of the conversion cycle in a while loop. when low the results will go to ADreading
ADReading = ADRESH *256 + ADRESL; // multiplies hi value by 256 and adds low value giving us a 10bit value
value =(5.0*(ADReading/1023.0));
PORTB=0xff;
if(value >=1&&value <=4)
{
TRISB3 =1;
}
else(value <=1&&value >=4);
{
TRISB4 =1;
}
}