Hello! I am struggling with my program. With Arduino everything is easy, but with my PIC16F873 is harder. I hope some smart people will watch code and tell whats wrong. I'm using MPLAB IDE and HI-TECH compiler. Build hapens succesfully but when writing code in MC it doesnt go very well.. It doesnt read A0.
Code:
//Simple program to read analog sensor(potenciometer)
//and control 3 leds.
#include "htc.h"
__CONFIG(FOSC_XT & WDTE_OFF & PWRTE_OFF & CP_OFF);
void main()
{
TRISB = 0x00; // B ports are outputs
PORTB = 0; //Beginning condition 0
TRISA = 0xFF; //A port are input
unsigned int val; //Variable for storing converted anolog signal
ADCON0 = 0b01000101; //A/D control bit register
ADCON1 = 0b10000000; //ADFM 1
while(1)
{
GO_DONE = 1; //Start conversion
while(GO_DONE) continue;
val = ADRESL >> 2; //Assign converted value to variable
if (val > 500) {PORTB = 0x01;}
else {PORTB = 0b00000110;} //Turn on 2 LED diodes
}
}
Here the schematic:
http://www.bildites.lv/viewer.php?file=q6hefcnqyezzgjkaukg7.png
Code:
//Simple program to read analog sensor(potenciometer)
//and control 3 leds.
#include "htc.h"
__CONFIG(FOSC_XT & WDTE_OFF & PWRTE_OFF & CP_OFF);
void main()
{
TRISB = 0x00; // B ports are outputs
PORTB = 0; //Beginning condition 0
TRISA = 0xFF; //A port are input
unsigned int val; //Variable for storing converted anolog signal
ADCON0 = 0b01000101; //A/D control bit register
ADCON1 = 0b10000000; //ADFM 1
while(1)
{
GO_DONE = 1; //Start conversion
while(GO_DONE) continue;
val = ADRESL >> 2; //Assign converted value to variable
if (val > 500) {PORTB = 0x01;}
else {PORTB = 0b00000110;} //Turn on 2 LED diodes
}
}
Here the schematic:
http://www.bildites.lv/viewer.php?file=q6hefcnqyezzgjkaukg7.png