1 / 16

LAB 2: Basic IO

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.

elisa
Download Presentation

LAB 2: Basic IO

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 4101 Introduction to Embedded Systems LAB 2: Basic IO Chung-Ta King National TsingHua University

  2. 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

  3. 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

  4. Recall: Sample Code for Output

  5. Recall: Memory-Mapped IO P1OUT P1IN … swr3,P1OUT P1REN

  6. Configuring the I/O Ports

  7. 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

  8. 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

  9. 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).

  10. Sample Code 1 for Input P1OUT is not initialized and must be written before configuring the pin for output.

  11. Sample Code 1 for Input (MSP430g2553)

  12. Sample Code 2 for Input

  13. Sample Code 2 for Input (for MSP430g2553)

  14. 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

  15. 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.

  16. 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.

More Related