/* * File: main.c * Author: Y.Sakazume * * Created on 2016/07/30, 1:56 * * Device: 12F609 * H/W connection: * GP0 Cylinder1 IG output * GP1 Cylinder2 IG output * GP2 Cylinder3 IG output * GP3 IGT input * GP4 G1 input * GP5 Cylinder4 IG output */ #include #define _XTAL_FREQ 8000000 // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. // CONFIG #pragma config FOSC = INTOSCIO, IOSCFS = 8MHZ // Oscillator Selection bits #pragma config WDTE = OFF // Watchdog Timer (WDT disabled) #pragma config PWRTE = ON // Power-up Timer Enable bit (Power-up Timer is enabled) #pragma config CP = OFF // Code Protection bit (Code protection disabled) #pragma config MCLRE = OFF #define IGT GP3 #define G1 GP4 #define CLR GPIO=0 static bit g0_flg=0; static char i; static char data[]={0x01,0x02,0x04,0x20}; void interrupt ISR(void) { //GIE=0; // prohibit INT automatically if(CMIF == 1){ CMIF=0; // __delay_ms(2); // noise margin if(G1==0){ g0_flg=1; i=0; } } else if(GPIF == 1){ if (i > 3) // G1 signal failure g0_flg=0; if(IGT) { if(g0_flg) GPIO=data[i++]; else GPIO=0x27; } else CLR; GPIF=0; } GIE=1; // enable interrupt } void main(void) { ANSEL = 0x08; // set GP4 to analog CMCON0 = 0b10000101; // comparator setup CMHYS = 1; VRCON = 0b100011111; // reference voltage = 3/4*Vdd TRISIO=0x18; // INTEDG = 0; // create INTF interrupt at falling edge IOC3 = 1; CMIE = 1; INTCON=0xc8; while(1){ SLEEP(); } }