#include /******************************************************** * * Program Title: Flash D0 with Initialization and Delay Written in Mixed C and Assembly * * Program File Name: Lecture_11B.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); int count; 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) { // WAS the following //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 // New code is the following ... #asm BCF _STATUS, 5 ; //Select Bank 0 ; CLRF _PORTA ; //Initialize PORTA (to all zeros) ; MOVLW 7 ; //Load w with 7 MOVWF _CMCON0 ; //Load CMCON0 with 7 ; //Turns off comparators ; BSF _STATUS, 5 ; //Select Bank 1 ; CLRF _ANSEL ; //Shut off ADC (digital I/O) ; MOVLW 001111B ; //Load w – RA4 and RA5 outputs MOVWF _TRISA ; //copy w to TRIS PORTA ; BCF _STATUS, 5 ; //Select Bank 0 #endasm 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) { // WAS the following // int i, j; // for (i = 0; i < 255; i++) // for (j = 0; j < 255; j++); // New code is the following ... asm(" MOVLW 255") ; //Decimal 255 asm(" MOVWF _count") ; //Initialize counter to 10 asm("Repeat DECFSZ _count,f") ; //Decrement counter asm(" GOTO Repeat") ; //If counter <> 0 return; } /******** END OF delay_routine *************************/