/******************************************************************* * FileName: problem3_fisher.c * Processor: PIC18F4520 * Compiler: MPLAB C18 v.3.06 * * Flashes an LED on RB1 when RB0 is pressed * * Creation and Revisions: * Author Date Comments * Matt Boutell 18 Nov 2009 * David Fisher Jan 4, 1010 ********************************************************************/ /** Header Files ***************************************************/ #include #include /** Configuration Bits *********************************************/ #pragma config OSC = INTIO67 // EC = External 4MHz Crystal for PICDEM board only #pragma config WDT = OFF #pragma config LVP = OFF #pragma config BOREN = OFF /** Define Constants Here ******************************************/ #define PRESSED 0 #define UNPRESSED 1 /******************************************************************* * Function: void main(void) ********************************************************************/ #pragma code void main (void) { OSCCONbits.IRCF2 = 0; // sets to 500 kHz OSCCONbits.IRCF1 = 1; OSCCONbits.IRCF0 = 1; ADCON1 = 0x0F; // all digital TRISB = 0b11111110; // 0xFE (only bottom 2 bits matter) PORTBbits.RB0 = 0; // Start low (not required) while (1) { if (PORTBbits.RB1 == PRESSED ) { PORTBbits.RB0 = 0; // 0.5 Seconds -> Need 62500 instruction cycle delays Delay1KTCYx(62); Delay100TCYx(5); PORTBbits.RB0 = 1; // 0.75 seconds -> Need 93750 instruction cycle delays Delay1KTCYx(93); Delay10TCYx(75); } else { PORTBbits.RB0 = 0; } } }