Hi
I am using a PIC16F690, programming wiht a MPLAB IDE of a startkit 2 in connection with a HITECH compiler for C.
What I'd like to do is to display on a 7segments a tension value coming from an Input. How can I read the exact value from the ADC ? I mean I receive 3.2V on AN0 and with a case I detect something 3<x<4 and I set the output of a 7segments as 3(0b1111001) . So far I was only able to read if it was High or Low:
The strange thing is also that when I send a low value to AN0, the outputs don't turn off completely but it is like they dim a bit.
Thanks in advance
I am using a PIC16F690, programming wiht a MPLAB IDE of a startkit 2 in connection with a HITECH compiler for C.
What I'd like to do is to display on a 7segments a tension value coming from an Input. How can I read the exact value from the ADC ? I mean I receive 3.2V on AN0 and with a case I detect something 3<x<4 and I set the output of a 7segments as 3(0b1111001) . So far I was only able to read if it was High or Low:
Code:
#include <htc.h>
__CONFIG(MCLREN & UNPROTECT & WDTDIS & INTIO);
void main()
{
ANSEL = 0b10010000; // Select A/D inputs
ANSELH =0b00000000;
ADCON0 =0b00000000; // left justified
CM1CON0 = 0; //Turn off comparator
CM2CON0 = 0; //Turn off comparator
TRISA = 0b011101; //Set pin in output mode
TRISB = 0; //Set pin in output mode
TRISC = 0; //Set pin in output mode
// ANALOG CHANNEL 1 (AN0)
while(1==1)
{
CHS0 = 1; // set channel AN0
GODONE = 1; // start the A-to-D process
while(GODONE) continue;
int advalue = ADRESH;// A-to-D result to "advalue"
//This "if" can be change in a case where depending the value I activate differently the 7segments
if(advalue)
{
PORTA = 0b11111111;
PORTB = 0b11111111;
PORTC = 0b11111111;
}
else
{
PORTA = 0b00000000;
PORTB = 0b00000000;
PORTC = 0b00000000;
}
}
};
The strange thing is also that when I send a low value to AN0, the outputs don't turn off completely but it is like they dim a bit.
Thanks in advance