Hi,
I went back to basic and found that by removing interupt on timer 0 and remove the reference to ANSEL, (a rewrite of the 12F675 flashing led program) I got it to work.
Still need some work however it may seem that the Adc_Read() does work, however not so well with the interupt.
Code: Select all
#define CLEARWDOG asm CLRWDT
#define CPU_Led PORTA.f0
#define ON 1
#define OFF 0
unsigned L_REF;
unsigned counter;
void ISR_AC() {
if (L_REF > 870) { //
PORTC = 0x0D;
}
else
if (L_REF > 700) { //
PORTC = 0x05;
}
else
if (L_REF > 510) { //
PORTC = 0x01;
}
else
if (L_REF > 480) { //
PORTC = 0x00;
}
else
if (L_REF > 270) { //
PORTC = 0x03;
}
else
if (L_REF > 110) { //
PORTC = 0x07;
}
else //
PORTC = 0x0f;
}//~
void Init() {
PORTA = 0;
PORTC = 0;
TRISC = 0;
TRISA = 0;
ANSEL = 0;
CMCON0 = 7;
TRISA = 0x0C; // designate gpio as output
TRISA.ANS3 = 1; // pin ANS3 as input
ADCON0.VCFG = 0; // Vdd as Vref
// enable TMRO interrupt
counter = 0; // initialize counter
}//~
void main() {
Init();
do {
counter ++;
if (counter > 1200) {
CPU_Led = ~CPU_Led; //CPU Led heart beat
counter = 0; // Reset cnt
}
// beginning of a repeat loop
L_REF = Adc_Read(ANS2); // ADC conversion
ISR_AC();
} while (1); // endless loop
// :
}//~
I am now even more confused I was trying to reference TRISA.ANS3 = 1; it did not work; when I went from Adc_Read(ANS3); to Adc_Read(ANS2); without seting it as an input, it worked?
I found that the interupt not working (was working) wasn't able to see the CPU LED due to the ANSEL registar not set for the CPU led for D0
Andrew