Academic Program

Generate Drivers and Main.c

Generate Drivers and Main.c

Generate Code

The generate code button is then clicked to produce the software files. A set of source files including a main.c and a set of header files are both produced by the MCC.

 

The main.c file is shown below. The MCC places a SYSTEM_Initialize function at the top. This function includes all the necessary files for the Timer0 setup. In addition to that, a few commands need to be added by the developer. Within the generated code are two functions that make the code easier:

TMR0_HasOverflow_Occurred
TMR0_Initialize

There is also a function created in the pin_manager files that automatically toggles the I/O pin:

TMR0_HasOverflow_Occurred

The TMR0_HasOverflow_Occurred tests the TMR0IF bit to see if it is a one. An "if statement" is used to test the result of the TMR0_HasOverflow_Occurred function. If the result is one, indicating the TMR0 has overflowed, then the RA2 pin is toggled. Timer0 has to be re-initialized which also clears the TMR0IF bit and preloads the TMR0 register with the proper preload value to create the 2.5 millisecond delay.

The function IO_RA2_Toggle is created in the pin_manager files. This makes generating the I/O toggle quite easy as all the port register settings are handled in the pin_manager functions.