LEDs - 04
In this section we are going to: - Move our "turn red LED on" code into a function - Build 3 functions, one for each LED - Debug: Step Over the first function while you Step Into the remaining 2 functions called from main() while observing the registers change |
Create a function for the red LED: Here is an example of putting the red LED code into a function called rL_on():
Create two more functions: Now we'll build two more functions, one for the yellow LED [yL_on()] and one for the green LED [gL_on()]:
Call the functions: Next we'll call these 3 functions, rL_on(), yL_on() and gL_on() from our main() function:
Reorder your code so main() is last: The ZDSII IDE compiler is particular: it wants the functions called by main() to precede main(). Failure to do so will result in an error. So here's what the final program could look like:
Stepping through Breakpoints:
If you're going to debug and step through the code, consider using Insert Breakpoint at each of the functions in main as shown below.
Under Debug, choose Connect to Target. Under View | Debug Windows, enable Special Function Registers three times. Change the defaults of AES to GPIO Ports A, B and C. Once you press Debug | Go you can watch each port's values change while stepping.
Step over an existing Breakpoint: Because you've already watched Port B's registers change, you may want to skip over it and check out Port C's registers instead. To do so requires the following: - Insert Breakpoints for all functions under main() - Build | Build - Debug | Connect to Target - Position your flashing cursor on the first function, rL_on() and press <CTRL> <F10> to Run to Cursor. You should see a yellow right-facing arrow within the first red breakpoint - Now we'll skip over this function and move onto the next using <F10> or Step Over - Press <F11> to Step Into the function itself. Continue to press <F11> to advance through each line of code in yL_on() as you watch the registers change on the right side of your screen |