Professional Documents
Culture Documents
Development Tool
3. Connect the Launchpad development board to the PC with the enclosed USB cable.
void main(void)
{
unsigned short int i;
while(1)
{
P1OUT = P1OUT ^ 0x01; // Toggle P1.0
}//end while(1)
}//end main()
12. The first line in main disables the watchdog timer. The watchdog timer is used in many
applications (especially mission critical programs) to verify the microcontroller is
operating properly. For now, it simplifies our programs to disable the watchdog timer.
13. The following line configures the microcontroller to use pin P1.0 as a digital output.
Note, the MSP430 microcontroller has a reduced instruction set (it is a RISC
microcontroller). Therefore, it does not include operations that work on individual bits.
Therefore, all of our operations will be on bytes, not bits. The instruction
takes the logic OR of P1DIR with 0x01. The result is that the least significant bit (lsb)
of P1DIR will be HI.
P1OUT is being bit-wise XOR-ed with 0000 0001 binary. The 7 most significant bits
(msb) of P1OUT are being XOR-ed with 0. The output of any bit XOR-ed with 0 will
simply be the original bit:
P1OUT.7 ^ 0 = P1OUT.7
P1OUT.6 ^ 0 = P1OUT.6
P1OUT.5 ^ 0 = P1OUT.5
P1OUT.4 ^ 0 = P1OUT.4
P1OUT.3 ^ 0 = P1OUT.3
P1OUT.2 ^ 0 = P1OUT.2
P1OUT.1 ^ 0 = P1OUT.1
The least most significant bit of P1OUT (P1OUT.0) is XOR=ed with 1. From the
truth table, the result will be the complement of P1OUT.0.
P1OUT.0 ^ 1 = P1OUT.0
Therefore, the net effect of the instruction leaves the 7 msb of P1OUT unchanged, but
toggles the lsb, P1OUT.0.
P1OUT = P1OUT ^ 0x01;
16. Copy the code, and paste it into the main.c edit window.
If anything is misaligned, go ahead and straighten it out.
17. Click the Save icon near the top right corner of the screen.
20. The results will be shown in the Console and Problems windows. If there are any
errors shown in the Problems window, you may have accidentally changed the code.
Go back and correct the errors. You can disregard any warnings at this time.
24. You can start the program by pressing the Resume button on the toolbar.
29. Save your program and Build it. When it is done, go ahead and click Debug.
30. When you are in the Debugger, go ahead and Resume your program.
short int i;
33. Save and Build the modified program. Click the Debug button and Resume your
program again. Does the LED blinking slow down? Why or why not? What frequency
is the LED toggling at now?
#include <msp430g2553.h>
void main(void)
{
unsigned short int i;
while(1)
{
if (0x08 & P1IN)
{
P1OUT = P1OUT ^ 0x01;
else
{
P1OUT = P1OUT ^ 0x01;
36. Save and Build your modified program. Click on the Debug button and Resume
your program. Demonstrate the program functionality matches your flow chart.
In no event shall the owner or contributors to the tutorials and software be liable
for any direct, indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services; loss of
use, data, or profits; or business interruption) however caused and on any theory
of liability, whether in contract, strict liability, or tort (including negligence or
otherwise) arising in any way out of the use of this software, even if advised of
the possibility of such damage.