Introduction to Microcontrollers Lab Manual - Microchip
Introduction to Microcontrollers Lab Manual - Microchip
Introduction to Microcontrollers Lab Manual - Microchip
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
LABS<br />
To use the S<strong>to</strong>pwatch, insert two breakpoints around the section of code you wish <strong>to</strong><br />
time. Run the code <strong>to</strong> the first breakpoint, “Zero” the S<strong>to</strong>pWatch and then run the code<br />
<strong>to</strong> the next breakpoint. The S<strong>to</strong>pwatch will show the number of instruction cycles and<br />
time between the two breakpoints.<br />
Hint: When using the S<strong>to</strong>pwatch with MPLAB SIM Simula<strong>to</strong>r, it is important <strong>to</strong> set the<br />
Simula<strong>to</strong>r Processor Frequency correctly. Otherwise the S<strong>to</strong>pwatch time will be incorrect.<br />
An easy way <strong>to</strong> test if this has been set properly is <strong>to</strong> set breakpoints around a<br />
simple instruction such as MOV. This should execute in 0.062500 uSecs.<br />
1.2.5 The <strong>Lab</strong><br />
1.2.5.1 OBJECTIVE<br />
Program the PIC24 microcontroller <strong>to</strong> use a hardware timer <strong>to</strong> blink an LED at a 1 second<br />
interval (LED on for 1 second then off for 1 second). Show your calculations for the<br />
Timer delay.<br />
Use a subroutine CALL or RCALL somewhere in the code. A common use would be <strong>to</strong><br />
move the configuration instructions for the timer in<strong>to</strong> a subroutine. This keeps the main<br />
line code cleaner with only one line required <strong>to</strong> initialize the timer module at the start of<br />
the code.<br />
Use the s<strong>to</strong>pwatch <strong>to</strong> check your timer and verify it is actually running at 1 sec (5 sec<br />
for the bonus).<br />
Hint: Use one breakpoint at your LED <strong>to</strong>ggle instruction (BTG PORTC, #2), run the<br />
code <strong>to</strong> that breakpoint, then “Zero” the s<strong>to</strong>pwatch and run it again.<br />
1.2.5.2 BONUS<br />
Modify the code and setup a 32-bit TIMER <strong>to</strong> blink the LED at a 5 sec interval. Show<br />
your calculations for the timer delay.<br />
1.2.5.3 PERTINENT INFORMATION<br />
The basic program flow is illustrated in Figure 1-3.<br />
DS51963A-page 16 2011 <strong>Microchip</strong> Technology Inc.