0% found this document useful (0 votes)
2 views2 pages

#Include LibraryLunchboxCommon.h

The document contains C code for an MSP430 microcontroller that controls multiple LEDs based on the state of an on-board switch. It initializes the system, sets the direction of the pins for the switch and LEDs, and enters an infinite loop to toggle the LEDs when the switch is pressed. The code includes debouncing delays to ensure reliable switch operation.

Uploaded by

Jayesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

#Include LibraryLunchboxCommon.h

The document contains C code for an MSP430 microcontroller that controls multiple LEDs based on the state of an on-board switch. It initializes the system, sets the direction of the pins for the switch and LEDs, and enters an infinite loop to toggle the LEDs when the switch is pressed. The code includes debouncing delays to ensure reliable switch operation.

Uploaded by

Jayesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <Library/LunchboxCommon.

h>
#include <msp430.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>

#define SW BIT3 // Switch -> P1.3 (On-board Switch, Pull-Up


configuration)
#define LED BIT6 // Red LED -> P1.6 (On-Board LED, Active High
Configuration)
#define LED BIT5 // Red LED -> P1.5 (On-Board LED, Active High
Configuration)
#define LED BIT4 // Red LED -> P1.4 (On-Board LED, Active High
Configuration)
/*@brief entry point for the code*/
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; //! Stop Watchdog (Not recommended for code in
production and devices working in field)
initialise_SerialPrint_on_lunchbox(); // a function
int x = 0;
P1DIR |= LED; // Set LED pin -> Output
P1DIR &= ~SW; // Set SW pin -> Input

while(1)
{

if(!(P1IN & SW)) // If SW is Pressed


{
__delay_cycle(20000);
while(!(P1IN & SW));
__delay_cycle(20000);
P1OUT ^= LED1; // Toggle LED

}
if(!(P1IN & SW)) // If SW is Pressed
{
__delay_cycle(20000);
while(!(P1IN & SW));
__delay_cycle(20000);
P1OUT ^= LED2; // Toggle LED

if(!(P1IN & SW)) // If SW is Pressed


{
__delay_cycle(20000);
while(!(P1IN & SW));
__delay_cycle(20000);
P1OUT ^= LED3; // Toggle LED

}
}
}

You might also like