160 likes | 252 Views
CS 4101 Introduction to Embedded Systems. LAB 2: Basic IO. Chung-Ta King National Tsing Hua University. Introduction. In this lab, we will learn the basic IO of MSP430 LanuchPad Configuring the I/O port of LanuchPad for output Configuring the I/O port of LanuchPad for input.
E N D
CS 4101 Introduction to Embedded Systems LAB 2: Basic IO Chung-Ta King National TsingHua University
Introduction • In this lab, we will learn the basic IO of MSP430 LanuchPad • Configuring the I/O port of LanuchPad for output • Configuring the I/O port of LanuchPad for input
LaunchPad Development Board USB EmulatorConnection Embedded Emulation 6-pin eZ430 Connector Crystal Pads Chip Pinouts Part and Socket Power Connector P1.3 Button LEDs and Jumpers P1.0 & P1.6 Reset Button
Recall: Memory-Mapped IO P1OUT P1IN … swr3,P1OUT P1REN
Problem with Input Using a Switch • When the switch is down (closed), MSP430 will detect a 0 from the pin. • When the switch is up (open), what will MSP430 detect? Ans.: random value Floating
Typical Way of Connecting a Button • The pull-up resistor Rpullholds input at logic 1 (voltage VCC) while button is up and logic 0 or VSS when button is down active low • A wasted current flows through Rpull to ground when button is pressed • This is reduced by makingRpull large enough, typically 33 k
Typical Way of Connecting a Button • MSP430 offers internal pull-up/down. • PxREN register selects whether this resistor is used (1 to enable, 0 to disable) • When enabled, the corresponding bit of PxOUT register selects whether the resistor pulls the input up to VCC(1) or down to VSS (0).
Sample Code 1 for Input P1OUT is not initialized and must be written before configuring the pin for output.
Lab 1 • Basic 1: • Upload the sample input program 2 to the MSP430 LaunchPad and run it • Basic 2: • Change the red LED to the green LED • Basic 3: • Run the debugger to show the values of P1IN after each while() statement
Lab 1 • Advanced (Bonus): • Write a program to toggle the LED each time the button is pressed. Turn it on the first time, off the second, on the third, and so on.
Debug • How to know the process is working correctly? • In the code line containing: i = P1IN; j = P1OUT; double-click on the variable i,jto select it. • Then right-click on it and select Add Watch Expression. If needed, click on the Watch tab near the upper right of the CCS screen to see the variable added to the watch window. • Right-click on the appropriate line of code and select Toggle Breakpoint. • When we run the code, it will hit the breakpoint and stop, allowing the variable to be read and updated in the watch window. • Run the code • Do this a few times, observing the value.