Skip to content

Instantly share code, notes, and snippets.

@elvircrn
Created February 3, 2018 13:02
Show Gist options
  • Save elvircrn/b6969180af779e813d52da88e756d0c2 to your computer and use it in GitHub Desktop.
Save elvircrn/b6969180af779e813d52da88e756d0c2 to your computer and use it in GitHub Desktop.
#pragma config FOSC = HS, WDTE = OFF, PWRTE = OFF, MCLRE = ON, CP = OFF, \
CPD = OFF, BOREN = OFF, CLKOUTEN = OFF
#pragma config IESO = OFF, FCMEN = OFF, WRT = OFF, VCAPEN = OFF, PLLEN = OFF, \
STVREN = OFF, LVP = OFF
#define _XTAL_FREQ 8000000
#include <xc.h>
volatile unsigned char id;
void init() {
GIE = 1; //Enable global interrupt
PEIE = 1; //Enable peripheral interrupt
ADIE = 1; //Enable ADC interrupt
ADIF = 0;
TMR0IF=0;
TMR0IE=1;
TMR0CS = 0;
PSA = 0;
id = 0;
OPTION_REGbits.TMR0CS = 0;
OPTION_REGbits.PSA = 0;
OPTION_REGbits.PS0 = 1;
OPTION_REGbits.PS1 = 1;
OPTION_REGbits.PS2 = 1;
TMR0 = 0;
INTCONbits.GIE = 1;
INTCONbits.TMR0IE = 1;
}
void interrupt handler() {
if (TMR0IE && TMR0IF) {
PORTB = ++id;
__delay_ms(2000);
TMR0IF = 0;
id--;
}
}
void main(void) {
init();
for (;;) { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment