#include #include "delay.c" __CONFIG(WDTDIS & XT & UNPROTECT & LVPDIS); #define DELAY 250 long tics = 0l; int intflag = 1; void interrupt prv_int(void) @ 0x10 { tics++; if (tics == 6) { tics = 0l; if (intflag == 1) { RB5 = 1; intflag = 0; } else { RB5 = 0; intflag = 1; } } TMR2IF = 0; } 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 //******************************************************************** INTCON = 0; // reset all the flag bits for all the interrupts T2CON = 0x7E; // hex 7E = // 76543210 // 1111110 // 1111 -> postscale value 1:16 // 1 -> enable timer2 // 1x -> prescaler value 1:16 // PR2 = 0xFF; default value TMR2IE = 1; // TMR2 to PR2 enable match interrupt PEIE = 1; // peripheral interrupt enable bit GIE = 1; // global interrupt enable bit (1: enable all) 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); } } }