#include <htc.h>
#include <stdio.h>
[COLOR="red"]__CONFIG(OSC_INTRC_NOCLKOUT & WDT_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & IOSCFS_4MHZ & BOREN_OFF & WRT_OFF );[/COLOR]
long maxvalue = 11110000;
int x=0;
// pupose: sleep mode on, slow count, end of count= adc sample, add sample to total, subtract total from max, output to LED remaining.
// look into: activating adc from interupt, writing to flash, outputting in i2c
int monitor_function(){
[COLOR="red"] long z;
long total;
int count;
long remaining;[/COLOR]
//retrieve adc value
z = (ADRESH<<8) | ADRESL; //need to concatonate? C = (A<<4) | B ;
total = total + z; //largest value?
count;
count ++;
if (count == 10){
//write total to flash
count =0;
}
remaining = maxvalue - total;
return remaining;
}
int main(){
// Interupts
INTCON = 0b[COLOR="red"]00[/COLOR]000000;
PIE1 = 0b00100000;
//Port settings
TRISIO = 0b00111001;
ANSEL = 0b01101000;
//ADC settings
ADCON0 = 0b10001101;
// Timer1 settings
T1CON = 0b10111101;
//Comparitor Settings
CCP1CON = 0b00001011;
// Compare N timer setting
CCPR1H = 0b00000000 ;
CCPR1L = 0b00001001;
GP2 = 0;
TMR1 = 0;
int y;
while(x<10000000){
x++;
if(CCPIF == 1){
GP2= 1;
//implement a go ==0 check before continueing
y= monitor_function();
CCPIF = 0;
}
else
GP2=0;
}
return 0;
}