Created
February 3, 2018 13:02
-
-
Save elvircrn/b6969180af779e813d52da88e756d0c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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