//********************************************************************** /*   『AC電力制御ユニット』 */ //********************************************************************** static unsigned char FLAG; void interrupt(){ if (INTCON.INTF == 1) { INTCON.INTF = 0; FLAG = 1; } } //********************************************************************** void main() { static unsigned char buf[6], cnt, onCnt, offCnt; // OSCCON = 0b01110000; // クロックは8Mhz CMCON = 0b00000111; // コンパレータは使用しない。 // A/D変換を使用する。 ANSEL = 0b00000010; // ポートを初期化する。 TRISA = 0b00111010; TRISB = 0b00001111; // 入力割り込みの設定 INTCON.INTE = 1; INTCON.INTF = 0; OPTION_REG.INTEDG = 1; // LCDを初期化する。 Lcd_Custom_Config(&PORTB,4,5,6,7,&PORTA,0,7,6); Lcd_Custom_Cmd(LCD_CURSOR_OFF); Lcd_Custom_Cmd(LCD_CLEAR); Lcd_Custom_Out(1, 1, "AC-controller V3"); Delay_ms(500); // Lcd_Custom_Cmd(LCD_CLEAR); // INTCON.PEIE = 1; // これ以降の処理で割り込みを許可する。 INTCON.GIE = 1; // これ以降の処理で割り込みを許可する。 // PORTA.F2 = 0; FLAG = 0; onCnt = 5; offCnt = 5; // WordToStr(onCnt * 10, buf); Lcd_Custom_Out(2, 1, buf); Lcd_Custom_Out(2, 6, "%"); while (1) { for (cnt = 0; cnt < onCnt; cnt++) { while (FLAG == 0) ; FLAG = 0; PORTA.F2 = 1; } for (cnt = 0; cnt < offCnt; cnt++) { while (FLAG == 0) ; FLAG = 0; PORTA.F2 = 0; } // if (PORTA.F5 == 0) { while (PORTA.F5 == 0) Delay_ms(1); onCnt++; if (onCnt > 10) onCnt = 0; offCnt = 10 - onCnt; // WordToStr(onCnt * 10, buf); Lcd_Custom_Out(2, 1, buf); Lcd_Custom_Out(2, 6, "%"); } } } //**********************************************************************