/*
* File: main.c
*/
#include
// PIC12F1822 Configuration Bit Settings
// CONFIG1
// Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config FOSC = INTOSC
// Watchdog Timer Enable (WDT disabled)
#pragma config WDTE = OFF
// Power-up Timer Enable (PWRT disabled)
#pragma config PWRTE = OFF
// MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config MCLRE = OFF
// Flash Program Memory Code Protection
// (Program memory code protection is disabled)
#pragma config CP = OFF
// Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config BOREN = ON
// Data Memory Code Protection
// (Data memory code protection is disabled)
#pragma config CPD = OFF
// Clock Out Enable
// (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config CLKOUTEN = OFF
// Internal/External Switchover (Internal/External Switchover mode is disabled)
#pragma config IESO = OFF
// Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
#pragma config FCMEN = OFF
// CONFIG2
// Flash Memory Self-Write Protection (Write protection off)
#pragma config WRT = OFF
// PLL Enable (4x PLL disabled)
#pragma config PLLEN = OFF
// Stack Overflow/Underflow Reset Enable
// (Stack Overflow or Underflow will not cause a Reset)
#pragma config STVREN = OFF
// Brown-out Reset Voltage Selection
// (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config BORV = LO
// Low-Voltage Programming Enable
// (High-voltage on MCLR/VPP must be used for programming)
#pragma config LVP = OFF
// クロック周波数指定
// __delay_ms()関数が使用する
#define _XTAL_FREQ 1000000
void main(void) {
// PICマイコン設定
// 内部クロック周波数を1MHzに設定
OSCCON = 0b01011010;
// すべてのピンをデジタルモードに設定
ANSELA = 0b00000000;
// すべてのピンを出力モードに設定 (ただしRA3ピンは常に入力モード)
TRISA = 0b00001000;
// LEDを点灯する
LATA5 = 1;
// スイッチが押されるまで待つ
while(RA3){
}
// LED点滅処理 (永久に繰り返す)
while(1){
// LEDを950ms消灯する
LATA5 = 0;
__delay_ms(950);
// LEDを50ms点灯する
LATA5 = 1;
__delay_ms(50);
}
// 以下の命令は実行されない
return;
}
|