//include file #include //16F84 configuration __CONFIG(0x3FF1); #define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit)) static bit LED0 @ PORTBIT(PORTB, 0); static bit LED1 @ PORTBIT(PORTB, 1); static bit LED2 @ PORTBIT(PORTB, 2); static bit LED3 @ PORTBIT(PORTB, 3); static bit LED4 @ PORTBIT(PORTB, 4); static bit LED5 @ PORTBIT(PORTB, 5); static bit LED6 @ PORTBIT(PORTB, 6); static bit LED7 @ PORTBIT(PORTB, 7); unsigned int i; //for loop pause unsigned int c; //for loop event loop //pause functions void pause_1(); void pause_2(); //main function void main(void) { TRISB = 0x00; PORTB = 0b00000000; while(1) { for(c=0; c<10; c++) { //forward LED0 = 1; pause_1(); LED0 = 0; LED1 = 1; pause_1(); LED1 = 0; LED2 = 1; pause_1(); LED2 = 0; LED3 = 1; pause_1(); LED3 = 0; LED4 = 1; pause_1(); LED4 = 0; LED5 = 1; pause_1(); LED5 = 0; LED6 = 1; pause_1(); LED6 = 0; LED7 = 1; pause_1(); LED7 = 0; //reverse LED6 = 1; pause_1(); LED6 = 0; LED5 = 1; pause_1(); LED5 = 0; LED4 = 1; pause_1(); LED4 = 0; LED3 = 1; pause_1(); LED3 = 0; LED2 = 1; pause_1(); LED2 = 0; LED1 = 1; pause_1(); LED1 = 0; LED0 = 1; pause_1(); }; //re-initalize PORTB PORTB = 0b00000000; for(c=0; c<10; c++) { PORTB = 0b10101010; pause_2(); PORTB = 0b01010101; pause_2(); }; for(c=0; c<10; c++) { PORTB = 0b11110000; pause_2(); PORTB = 0b00001111; pause_2(); }; for(c=0; c<10; c++) { PORTB = 0b11001100; pause_2(); PORTB = 0b00110011; pause_2(); }; for(c=0; c<10; c++) { PORTB = 0b10000001; pause_1(); PORTB = 0b01000010; pause_1(); PORTB = 0b00100100; pause_1(); PORTB = 0b00011000; pause_1(); PORTB = 0b00100100; pause_1(); PORTB = 0b01000010; pause_1(); }; } } void pause_1() { for(i=0; i<4000; i++); for(i=0; i<4000; i++); }; void pause_2() { for(i=0; i<4000; i++); for(i=0; i<4000; i++); for(i=0; i<4000; i++); for(i=0; i<4000; i++); for(i=0; i<4000; i++); for(i=0; i<4000; i++); };