#include <xc.h>
#include <stdint.h>
#define _XTAL_FREQ 4000000
#define sFLASH sGPIO.GP1
#pragma config WDTE = OFF, PWRTE = OFF, CP = OFF, BOREN = OFF
union {
uint8_t port;
struct {
unsigned GP0 : 1;
unsigned GP1 : 1;
unsigned GP2 : 1;
unsigned GP3 : 1;
unsigned GP4 : 1;
unsigned GP5 : 1;
};
} sGPIO;
void main() {
TRISB = 0b00000100;
OPTION_REGbits.T0CS = 1;
OPTION_REGbits.PSA = 0;
OPTION_REGbits.PS = 6;
while(1) {
sFLASH = (TMR0 & 1<<7) != 0;
PORTB = sGPIO.port;
}
}
위 프로그램은 500ms 마다 LED가 깜빡 거립니다. 외부 입력은 CLK 소스로 32.768kHz 입니다.