#include #include "delay.c" __CONFIG(WDTDIS & XT & UNPROTECT & LVPDIS); #define DELAY 250 long tics = 0l; int intflag = 1; void interrupt prv_int(void) { if (!T0IF) return; T0IF = 0; tics++; if (tics == 6) { tics = 0l; if (intflag == 1) { RB5 = 1; intflag = 0; } else { RB5 = 0; intflag = 1; } } } void main() { int flag = 1; //******************************************************************** // setting input & output ports //******************************************************************** TRISB = 0b11000000; // set RB5-RB0 as output CMCON = 0b00000111; // disable comparator on ra0,1,2 TRISA = 0b11111111; // set RA7-RA0 as input //******************************************************************** // setting timer mode //******************************************************************** T0CS = 0; // Enable timer mode PSA = 0; // Enable prescaler assignement PS2 = 1; // PS1 = 1; // 111 mean prescaler set to 1:256 PS0 = 1; // //******************************************************************** // setting interrupt //******************************************************************** INTCON = 0; // reset all the flag bits for all the interrupts GIE = 1; // global interrupt enable bit (1: enable all) T0IE = 1; // TMR0 overflow interrupt enable bit (1: enable TMR0) while(1) { if (RA0 == 1) { flag = 0; } if (RA1 == 1) { flag = 1; } if (RA2 == 1) { PORTB = 0b00111111; flag = 0; } if (RA3 == 1) { PORTB = 0b00000000; flag = 0; } if (flag == 1) { RB4 = 1; DelayMs(DELAY); RB4 = 0; DelayMs(DELAY); RB3 = 1; DelayMs(DELAY); RB3 = 0; DelayMs(DELAY); RB2 = 1; DelayMs(DELAY); RB2 = 0; DelayMs(DELAY); RB1 = 1; DelayMs(DELAY); RB1 = 0; DelayMs(DELAY); RB0 = 1; DelayMs(DELAY); RB0 = 0; DelayMs(DELAY); } } }