Chung-Ta King National Tsing Hua University

Slides:



Advertisements
Similar presentations
Chapter 6 General Purpose Input/Output
Advertisements

EMS1EP Lecture 6 Digital Inputs
Lab 1 I/O, timers, interrupts on the eZ430-RF2500 Thomas Watteyne EE290Q – Spring 2010
Outline MSP430 LaunchPad MSP430 Microcontroller
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Chung-Ta King National Tsing Hua University
Lab7: Introduction to Arduino
Embedded Sumo 1T4 – 1T5 UTRA.
Chung-Ta King National Tsing Hua University
An Introduction to C Adam Gleitman – IAP 2014.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
LAUNCHXL2-RM57L – Project 0
KEG-012 A.K.A. EMMA AND DAVE’S GROUPS Design Projects.
Dr. Hoganson CSIS HC11 Demo Program This is our first lab using the 68HC11 microcontroller. We will “talk” to the microcontroller from a PC, run.
Embedded Programming and Robotics
Chung-Ta King National Tsing Hua University
LAB 7: WDT+ and Low-Power Optimization
Silicon Labs ToolStick Development Platform
Embedded Systems Design 1 Lecture Set 6 I/O Ports.
1 Applied Control Systems Technology. 2 Pin configuration Applied Control Systems.
© AJH 2013, V2.0 Computer Programming Embedded Systems Programming Stand-alone code, system initialisation, operating systems. Low-level operations; port.
A Simple Tour of the MSP430. Light LEDs in C LEDs can be connected in two standard ways. Active high circuit, the LED illuminates if the pin is driven.
Lecture 11: TI MSP430 Timers Compare Modes
LAB 8: Program Design Pattern and Software Architecture
FIRST GADGETEER PROJECT. Where are you? Making a VS project Parts of a C# program Basics of C# syntax Debugging in VS Questions? 2.
ECS642U Embedded Systems Digital I/O William Marsh.
Lecturers: Professor John Devlin Mr Robert Ross
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Microcontroller Intel 8051 [I/O Ports]. Pin out of the 8051 –40 pin package –32 pins are used for the 4 ports. –V CC / V SS –ALE Address Latch Enable.
1 - Remove LED from 13 and GND - Bring out your breadboard from HW#4 Arduino Overview:
ECE Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560.
LHO 22 C and the  The Silicon Labs ISE uses the Keil C51 compiler.  The code size is limiter to 2K  C has replaced PL/M (the original Intel high.
MICROCONTROLLER INTERFACING WITH STEPPER MOTOR MADE BY: Pruthvirajsinh Jadeja ( ) COLLEGE:DIET BRANCH:EC.
Introduction to Arduino A very basic intro to Arduino, the IDE and the Servos class.
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
Programming and Debugging with the Dragon and JTAG Many thanks to Dr. James Hawthorne for evaluating the Dragon system and providing the core content for.
National Tsing Hua University CS4101 嵌入式系統概論 Introduction to LaunchPad Prof. Chung-Ta King Department of Computer Science National Tsing Hua University,
Introduction In this lab , we will learn
Outline Introduction to NuMaker TRIO Programming environment setup
Lab 7 Basic 1: Game of Memory
CS4101 嵌入式系統概論 General Purpose IO
Programming and Debugging with the Dragon and JTAG
Lecture 8: TI MSP430 Interrupts, ISRs
CS4101 嵌入式系統概論 Introduction to LaunchPad
Microcontroller basics
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
CS4101 Introduction to Embedded Systems Lab 1: MSP430 LaunchPad IDE
Microcontroller Applications
Chapter 6 General Purpose Input/Output
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
Lesson Outline Peripherals Memory-Mapped IO Ports GPIO Multiplexing
Prof. Chung-Ta King Department of Computer Science
UCD ElecSoc Robotics Club 2017/2018
CS4101 嵌入式系統概論 General Purpose IO
Arduino.
Reset Sources and Watchdog Timer
Blinking an LED Using MSP430ware to Control GPIO
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 2: Timer and Clock Prof. Chung-Ta King Department of Computer Science National.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 3: Interrupt Prof. Chung-Ta King Department of Computer Science National Tsing.
Programming Boe-Bots (Part 1)
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
CS-4540 Robotics - Lab 05 Switch inputs to the Arduino Uno
CS4101 Introduction to Embedded Systems Lab 8: Arduino DAC and PWM
ECE 3567 Microcontroller Lab
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
ECE 3567 Microcontrollers Lab
ECE 3567 Microcontrollers Lab
A modular robot for use in the RoboSumo lab
Presentation transcript:

Chung-Ta King National Tsing Hua University 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

LaunchPad Development Board USB Emulator Connection Embedded Emulation 6-pin eZ430 Connector Crystal Pads Chip Pinouts Part and Socket P1.3 Button Power Connector LEDs and Jumpers P1.0 & P1.6 Reset Button

Recall: Sample Code for Output #include <msp430x2231.h> void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog P1DIR |= 0x41; // set P1.0 & 6 to outputs for(;;) { volatile unsigned int i; P1OUT ^= 0x41; // Toggle P1.0 & 6 i = 50000; // Delay do (i--); while (i != 0); } 4

Recall: Memory-Mapped IO P1REN … P1IN P1OUT sw r3,P1

Configuring the I/O Ports Registers (Mem Addr) Functions Descriptions P1IN (0x0020) Port 1 input This is a read-only register that reflects the current state of the port's pins. P1OUT (0x0021) Port 1 output The values written to this read/write register are driven out to corresponding pins when they are configured to output. P1DIR (0x0022) Port 1 data direction Bits written as 1 (0) configure the corresponding pins for output (input). P1SEL (0x0026) Port 1 function select Bits written as 1 (0) configure corresponding pins for use by the specialized peripheral (for general-purpose I/O). P1REN (0x0027) Port 1 resistor enable Bits set in this register enable  pull-up/down resistors on the corresponding I/O pins.

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 Rpull holds 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 making Rpull 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 #include <msp430g2231.h> // Pins for LED and button on port 1 #define LED1 BIT0 //P1.0 to red LED #define B1 BIT3 //P1.3 to button void main(void){ WDTCTL = WDTPW + WDTHOLD; //Stop watchdog timer P1OUT |= LED1; //Preload LED1 P1DIR = LED1; //Set pin with LED1 to output for(;;){ //Loop forever if((P1IN & B1) ==0){ //Is button down or not P1OUT &= ~LED1; } else{ P1OUT |= LED1; } } P1OUT is not initialized and must be written before configuring the pin for output.

Sample Code 1 for Input (MSP430g2553) #include <msp430g2553.h> #define LED1 BIT0 //P1.0 to red LED #define B1 BIT3 //P1.3 to button void main(void){ WDTCTL = WDTPW + WDTHOLD; //Stop watchdog timer P1OUT |= LED1 + B1; P1DIR = LED1; //Set pin with LED1 to output P1REN = B1; //Set pin to use pull-up resistor for(;;){ //Loop forever if((P1IN & B1) ==0){ //Is button down or not P1OUT &= ~LED1; } else{ P1OUT |= LED1; } }

Sample Code 2 for Input #include <msp430g2231.h> #define LED1 BIT0 //P1.0 to red LED #define B1 BIT3 //P1.3 to button volatile unsigned int i,j; void main(void){ WDTCTL = WDTPW + WDTHOLD; //Stop watchdog timer P1OUT |= LED1; //Preload LED1 P1DIR = LED1; //Set pin with LED1 to output for(;;){ while((P1IN & B1) != 0){ //Loop on button up i = P1IN; j = P1OUT; } P1OUT &= ~LED1; // Turn LED1 off while((P1IN & B1) == 0){ //Loop on button down i = P1IN; j = P1OUT; } P1OUT |= LED1; // Turn LED1 on }

Sample Code 2 for Input (for MSP430g2553) #include <msp430g2553.h> #define LED1 BIT0 //P1.0 to red LED #define B1 BIT3 //P1.3 to button volatile unsigned int i, j; void main(void){ WDTCTL = WDTPW + WDTHOLD; //Stop watchdog timer P1OUT |= LED1 + B1; P1DIR = LED1; //Set pin with LED1 to output P1REN = B1; //Set pin to use pull-up resistor for(;;){ while((P1IN & B1) != 0){ //Loop on button up i = P1IN; j = P1OUT; } P1OUT &= ~LED1; // Turn LED1 off while((P1IN & B1) == 0){ //Loop on button down P1OUT |= LED1; // Turn LED1 on }

Lab 1 Basic 1: Basic 2: Basic 3: 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,j to 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.