I am trying to program a 16f628a to count objects passing by an infrared-sensor.
My sensor is working. Using the 2nd comparator in the 16f628a. If I use this code in a continues loop it shows OFF if I hold my hand in the sensor, and ON if I pull it out.
Code: Select all
if (CMCON.C2OUT == 1)
{
LCD_Out(1,5, "off");
PIR1.CMIF = 0;
}
else
{
LCD_Out(1,5, "on ");
}
But this is not fast/accure if something passes it (falling object). So I want to use interrupts, but I can't get it to work.
This is my code
Code: Select all
int counter = 8;
char *tekst;
void interrupt(){
counter++;
PIR1.CMIF = 0;
}
void main() {
VRCON = 0b11001111;
CMCON = 0b00100101;
TRISA = 0b11111111;
TRISB = 0b00000000;
Delay_ms(100);
PIR1.CMIF = 0;
PIR1.CMIE = 1;
INTCON.PEIE = 1;
INTCON.GIE = 1;
Lcd_Config(&PORTB, 2, 3, 1, 7, 6, 5, 4);
LCD_Cmd(LCD_CLEAR);
LCD_Cmd(LCD_CURSOR_OFF);
LCD_Out(2,2, "testing...");
do {
IntToStr(counter,tekst);
LCD_Out(1,1,tekst);
delay_ms(100);
} while(1);
}
Thanks in advance,
Ruud