I wrote a simple code Analog in to control 4 x outputs at different levels. in both mP and mC both work well. (12F675 int OSC)
>mP compiled to 274 bytes of ROM 9 bytes of RAM
>mC compiled to 186 bytes of ROM 9 bytes of RAM
mC
Code: Select all
unsigned temp;
void main() {
GPIO = 0;
CMCON = 7;
TRISIO = 0x0C; // designate gpio 001100
TRISIO.ANS2 = 1; // pin ANS2 as input
ADCON0.VCFG = 0; // Vdd as Vref
do { // beginning of a repeat loop
temp = Adc_Read(ANS2); // ADC conversion
if (!GPIO.F3) {
if (temp > 900) {
GPIO = 0;
GPIO.F0 = 1;
}
else
if (temp > 600) {
GPIO = 0;
GPIO.F1 = 1;
}
else
if (temp > 400) {
GPIO = 0;
GPIO.F4 = 1;
}
else
if (temp > 200) {
GPIO = 0;
GPIO.F5 = 1;
}
}
} while (1); // endless loop (as this condition is never satisfied)
}//~
Code: Select all
program AC_ISR;
var temp : word;
begin
GPIO := 0;
CMCON := 7;
TRISIO := $0C; // designate gpio 001100
SetBit(TRISIO,ANS2); // pin ANS2 as input
ClearBit(ADCON0,VCFG); // Vdd as Vref
repeat // beginning of a repeat loop
begin
temp:=ADC_read(ANS2); // ADC conversion
if testbit(GPIO,3) = 0 then
begin
if temp > 900 then
begin
GPIO := 0;
Setbit(GPIO,0);
end
else
if temp > 600 then
begin
GPIO := 0;
Setbit(GPIO,1);
end
else
if temp > 400 then
begin
GPIO := 0;
Setbit(GPIO,4);
end
else
if temp > 200 then
begin
GPIO := 0;
Setbit(GPIO,5);
end;
end;
end;
until 0 = 1; // endless loop (as this condition is never satisfied)
end.