#include /******************************************************** * * Program Title: Flash D0 with Initialization and Delay Written in C * * Program File Name: Lecture_11A.c * * Microprocessors B 17.384 * * Spring 2009 * * Dohn Bowden * * 04/18/2009 * ********************************************************/ /******************************************************** * Function: main * * Description: D0 on PICkit 1 will Flash on and off * * Notes: * * RA4 - Positive LED Connection for D0 * RA5 - Negative LED Connection for D0 * * Returns: This routine contains an infinite loop * ********************************************************/ /* Configuration Word */ __CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \ & UNPROTECT & BORDIS & IESODIS & FCMDIS); void PORTA_init(void); void delay_routine(void); main() { PORTA_init(); while(1 == 1) // Loop Forever { delay_routine(); NOP(); RA4 = 1; // D0 LED On by making RA4 high delay_routine(); RA4 = 0; // D0 LED Off by making RA4 low } // *** END OF While (1 == 1) LOOP return; } /******** END OF main ROUTINE ***************************/ /******************************************************** * Function: PORT_init * * Description: Initializes PORTA to a known condition * * Notes: None * * Returns: None * * ********************************************************/ void PORTA_init(void) { PORTA = 0; // All PORTA Pins are low CMCON0 = 7; // Turn off Comparators ANSEL = 0; // Turn off ADC TRISA = 0b001111; // RA4 and 5 are outputs; RA0,1,2, and 3 are input return; } /******** END OF PORTA_init ****************************/ /******************************************************** * Function: delay_routine * * Description: Causes a delay in program execution * * Notes: * * Delay was determined through trial and error * * Returns: None * ********************************************************/ void delay_routine(void) { int i, j; for (i = 0; i < 255; i++) for (j = 0; j < 255; j++); return; } /******** END OF delay_routine *************************/