Skip to content

Instantly share code, notes, and snippets.

@mipsparc
Last active April 10, 2018 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mipsparc/57d87ca30cee4185329975d29ff3fc3a to your computer and use it in GitHub Desktop.
Save mipsparc/57d87ca30cee4185329975d29ff3fc3a to your computer and use it in GitHub Desktop.
E233系ドア上ランプをイメージして、接点状態が変化すると0.3秒点滅を5回繰り返すPIC16F677向けCプログラム
// CONFIG
#pragma config FOSC = INTRCCLK // Oscillator Selection bits (INTOSC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Selection bits (BOR enabled)
#pragma config IESO = OFF // Internal External Switchover bit (Internal External Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
#define _XTAL_FREQ 8000000
#include <xc.h>
void main(void) {
OSCCON = 0b01110000;
ANSEL = 0b00000000;
TRISC = 0b00000000;
PORTC = 0b00000000;
TRISB = 0b11111111;
unsigned char door_open = 0; // 接点が閉じている
unsigned char light_count = 0; // ON 5回 + OFF 5回
while (1){
if (PORTBbits.RB7 != door_open) {
door_open = !door_open;
light_count = 10;
}
if (light_count % 2){ // ON
PORTC = 0b11111111;
light_count --;
__delay_ms(300);
} else if (light_count) { // OFF
PORTC = 0b00000000;
light_count --;
__delay_ms(300);
} else {
PORTC = 0b00000000;
__delay_ms(100);
}
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment