<< Chapter < Page | Chapter >> Page > |
The hands-on laboratory consists of configuring the I/O ports, setting up the input lines to read push buttons and the output lines to feed LEDs. The following exercises have been developed for the three hardware development tools.
The first to be discussed is the MSP-EXP430FG4618 Experimenter’s board. Modifications are later made to suit the other development boards. The main differences between the boards are related to the specific ports in which the buttons and LED are (or can be) connected. For the development of this laboratory, Code Composer Essentials v3 has been used.
Detect of the button is pressed:
if (!(P1IN&0x01))
Include a control flow program variable that detects if the LED is blinking or not, when the button is pressed:
- Define a variable that indicates whether the LED is blinking;
unsigned char blink_status=1;
- Set the program flow depending on the state of the variable.
while(1){ // Infinite loop
if (blink_status == 1) {P2OUT ^= 0x04; // Toggle Port P2.2
i=15000; // Delaydo (i--);
while (i !=0);}
if (!(P1IN&0x01)) { // Detect S1 pressed
i=1500; // Delay, button debouncedo (i--);
while (i !=0);while (!(P1IN&0x01)); // Wait for the release of the button
i=1500; // Delay, button debouncedo (i--);
while (i !=0);if (blink_status ==1){ // If led is blinking, stop it
P2OUT&= ~ 0x04; // Turn Led off
blink_status=0;}else
blink_status=1;
This example and many others are available on the MSP430 Teaching ROM.
Request this ROM, and our other Teaching Materials here (External Link)
Notification Switch
Would you like to follow the 'Teaching and classroom laboratories based on the “ez430” and "experimenter's board" msp430 microcontroller platforms and code composer essentials' conversation and receive update notifications?