ECE2049: Embedded Computing in Engineering Design A Term Fall Lecture #8: Making it work: LEDs, Buttons & Keypad

Similar documents
ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #7: More Digital IO

ECE2049 Homework #2 The MSP430 Architecture & Basic Digital IO (DUE Friday 9/8/17 at 4 pm in class)

ECE2049: Embedded Computing in Engineering Design A Term Fall Lecture #9: Exam Review w/ Solutions

ECE2049-E17 Lecture 6 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

ECE2049-E18 Lecture 6 Notes 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

ECE2049 E17 Lecture 4 MSP430 Architecture & Intro to Digital I/O

Why embedded systems?

Review Activity 1 CALL and RET commands in assembler

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #11: More Clocks and Timers

ECE2049: Embedded Computing in Engineering Design C Term Spring 2018 Lecture #20: Using SPI The DAC

ECE PRACTICE EXAM #2 Clocks, Timers, and Digital I/O

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Using peripherals on the MSP430 (if time)

ECE2049: Embedded Computing in Engineering Design C Term Spring 2019 Lecture #22: MSP430F5529 Operating Mode & the WDT

ECE2049: Embedded Computing in Engineering Design C Term Spring 2018 Lecture #15: More ADC Examples

Texas Instruments Microcontroller HOW-TO GUIDE Interfacing Keypad with MSP430F5529

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

Lab 1: Space Invaders. The Introduction

Interrupts, Low Power Modes

Lecture 5: MSP430 Interrupt

6. General purpose Input/Output

Integer Representation

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Lab 1: Simon. The Introduction

Getting Started with the Texas Instruments ez430

ECE2049: Embedded Computing in Engineering Design A Term Fall 2017 Lecture #16: Interrupts and Event Driven Code

Reading: Davies , 8.3-4, , MSP430x55xx User's Guide Ch. 5,17

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #3: Of Integers and Endians (pt. 2)

CPE 325: Embedded Systems Laboratory Laboratory #7 Tutorial MSP430 Timers, Watchdog Timer, Timers A and B

ECE2049: Embedded Computing in Engineering Design C Term Spring 2018

CONTENTS: Program 1 in C:

Interfacing CMA3000-D01 to an MSP430 ultra low-power microcontroller

Lecture test next week

Copyright 2015 by Stephen A. Zajac & Gregory M. Wierzba. All rights reserved..spring 2015.

Interfacing CMR3000-D01 to an MSP430 ultra low-power microcontroller

Physics 319 Spring 2015: Introduction to the Programming and Use of Microprocessors

Before next weeks lab:

UC Berkeley EE40/100 Lab Lab 6: Microcontroller Input/Output B. Boser, etc.

IV B.Tech. I Sem (R13) ECE : Embedded Systems : UNIT -2 1 UNIT 2

@databasescaling Wednesday, 18 th April 2013

Scope & Register Access

Reading: Davies , 8.3-4, , MSP430x55xx User's Guide Ch. 5,17, MSP430F5529 Launchpad User's Guide

Embedded Technosolutions

PHYS 319. Things to do before next week's lab Whirlwind tour of the MSP430 CPU and its assembly language Activity 1.

Lab 4: Interrupt. CS4101 Introduction to Embedded Systems. Prof. Chung-Ta King. Department of Computer Science National Tsing Hua University, Taiwan

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

Texas Instruments Mixed Signal Processor Tutorial Abstract

Name: Clint Furrer Project Number: TI003 Project Description: Safety Walking Lights. Description:

Installation tutorial for the Skomer IDE

ECE2049 HW #1-- C programming and Binary Number Representations (DUE 9/1/2017 At the BEGINNING of class)

File: /media/j/texas/my msp430/g3tr/g3tr.c Pagina 1 di 5

ECE2049 HW #1-- C programming and Binary Number Representations (DUE 1/19/2018 At the BEGINNING of class)

Programming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11

Alex Milenkovich 1. CPE/EE 421 Microcomputers: The MSP430 Introduction. Outline

CPE 323 Introduction to Embedded Computer Systems: MSP430 System Architecture An Overview

CS 261 Fall Binary Information (convert to hex) Mike Lam, Professor

ECE2049 HW #1-- C programming and Binary Number Representations (DUE Friday 8/31/2018 At the BEGINNING of class)

// Conditions for 9600/4=2400 Baud SW UART, SMCLK = 1MHz #define Bitime_5 0x05*4 // ~ 0.5 bit length + small adjustment #define Bitime 13*4//0x0D

Interrupts CS4101 嵌入式系統概論. Prof. Chung-Ta King. Department of Computer Science National Tsing Hua University, Taiwan

Lab #3: Keypad Scanning in C Week of 11 February 2019

Lecture (09) PIC16F84A LCD interface LCD. Dr. Ahmed M. ElShafee

More on Arrays CS 16: Solving Problems with Computers I Lecture #13

What is an Interrupt?

Inf2C - Computer Systems Lecture 2 Data Representation

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

Wireless Sensor Networks (WSN)

Basic System Memory Architecture View (Functional)

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Block diagram of processor (Harvard)

MICROPROCESSORS A (17.383) Fall Lecture Outline

Timers and Clocks CS4101 嵌入式系統概論. Prof. Chung-Ta King. Department of Computer Science National Tsing Hua University, Taiwan

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

ECE 4510/5530 Microcontroller Applications Week 7

Integers II. CSE 351 Autumn 2018

Embedded Systems - FS 2018

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Programming Embedded Systems in C Module No: CS/ES/9 Quadrant 1 e-text

LAB A Translating Data to Binary

EE251: Tuesday December 4

University of Texas at El Paso Electrical and Computer Engineering Department

Recap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio

This simulated machine consists of four registers that will be represented in your software with four global variables.

CPE 323: MSP430 Timers

Week 4: Embedded Programming Using C

Welcome to Lab! Feel free to get started until we start talking! The lab document is located on the course website:

MIDTERM#1. 2-(3pts) What is the difference between Von Neumann & Harvard processor architectures?

Embedded programming, AVR intro

Embedded Systems - FS 2018

ENE 334 Microprocessors

EECS 373, Homework 4, Fall 2018 Assigned: Wednesday 10/3; Due: Wednesday 10/10 at 10pm

CPS 104 Computer Organization and Programming

C:\Users\Jacob Christ\Documents\MtSAC\ELEC74 Mt SAC - chipkit\homework Sheets.docx

EE292: Fundamentals of ECE

Integers II. CSE 351 Autumn Instructor: Justin Hsia

C Language Programming through the ADC and the MSP430 (ESCAPE)

Microcontroller Introduction

Asservissement en température numérique d'une cavité ultra-stable au LPL pour le Strontium

ECEN 5613 Embedded System Design Week #9 Fall 2016 Lab #4 10/22/2016

Create and Add the Source File

EEL 4924 Electrical Engineering Design (Senior Design) Team Baudiophile. Wireless Headphones

EMBEDDED HARDWARE DESIGN. Tutorial Interfacing LCD with Microcontroller /I

Transcription:

ECE2049: Embedded Computing in Engineering Design A Term Fall 2018 Lecture #8: Making it work: LEDs, Buttons & Keypad Reading for Today: Users Guide Ch 12 Reading for Next Class: Review all reading, notes, User's Guide 6.1, 6.3, 12 Lab #1 (on Web) : Early sign-off bonus Submit code by 5 pm 9/7! Report due Tues 9/11 HW #2 (on Web): Due TOMORROW 9/7/2018 (in class!) Lab #2 (coming soon): Pre-lab due in lab next week! EXAM #1 2 pm Monday 9/10/2018 in FLPH-UPR Last class: Configuring and reading from and writing to the digital IO ports on the MSP430F5529. --> Using bit-wise operations to configure the digital IO ports MSP430F5529 Basic Digital I/O >> 8 independent, individually configurable digital I/O ports -- Ports 1-7 are 8 bits wide, Port 8 is 3 bits wide >> Each pin of each port can be configured individually as an input or an output >> Each pin of each port can be individually read or written to Function Select Register: Sets function of each pin in the port (e.g. P4SEL) -- Bit = 0 = Pin selected for Digital I/O -- Bit = 1 = Pin not selected for digital I/O (multiplexed pin functions) Direction Register: Sets direction of each pin in the port (e.g. P2DIR) -- Bit = 0 = Corresponding pin is an Input -- Bit = 1 = Corresponding pin is an Output Input Register: Where input to the port is read from (e.g. P2IN) -- Bit = 0 = Logic low -- Bit = 1 = Logic high Output Register: Where data to be output from the port is written (P5OUT) -- Bit = 0 = Logic low -- Bit = 1 = Logic high Drive Strength: Sets drive strength of port (we will usually leave as default) --Bit = 0 = reduced drive strength (default) --Bit = 1 = full drive strength Pull-up/down Resistor Enable: Enable internal pull resistors (we will use with buttons) --Bit = 0 = Not enabled (default) --Bit = 1 = Enabled (see User's Guide)

Another Example: Now, write a function that reads the low nibble from P6 into a byte (use internal pull-up resistors), and another functions that outputs the complement of the low nibble of its input argument on P4.7-4. void portconfig() /* Setup P6.3-0 as digital IO inputs with pull-up resistors */ P6SEL = P6SEL & ~(BIT3 BIT2 BIT1 BIT0); // select for Dig IO P6DIR = P6DIR & ~(BIT3 BIT2 BIT1 BIT0); // set as inputs P6REN = P6REN (BIT3 BIT2 BIT1 BIT0); P6OUT = P6OUT (BIT3 BIT2 BIT1 BIT0); // enable pull res. // set as pull-up /* Setup P4.7-4 as digital IO outputs */ P4SEL &= ~(BIT7 BIT6 BIT5 BIT4); // select for Digital IO P4DIR = (BIT7 BIT6 BIT5 BIT4); // set them as outputs char in_p6() // Read in from port 6. Preserve only the low nibble char inbits; // local variable inbits = P6IN & (BIT3 BIT2 BIT1 BIT0); // AND with 0x0F return(inbits); // return the value inbits void out_comp_p4(char inbyte) char outbits; // Complement input value, inbyte outbits = ~inbyte; // Shift low nibble left to bits 7-4 outbits = outbits << 4; //output on P4.7-4 P4OUT = outbits; An example of calling these functions inside a main() main() char indata;. portconfig(); indata = in_p6(); out_comp_p4(indata); // indata is locally defined char

Input or Output? Let's take a closer look digital IO devices on our lab board starting with the 4 multicolored LED's... >> On what port and pins are these LEDs connected? (are they an input or output device?) --> Check board Schematics posted and/or look thru demo project P6.4 P6.2 P6.1 P6.3 How do the LED functions work?

void initleds(void) // Configure LEDs as outputs, initialize to logic low (off) // Note the assigned port pins are out of order test board // Red P6.2 // Green P6.1 // Blue P6.3 // Yellow P6.4 // smj -- 27 Dec 2016 P6SEL &= ~(BIT4 BIT3 BIT2 BIT1); P6DIR = (BIT4 BIT3 BIT2 BIT1); P6OUT &= ~(BIT4 BIT3 BIT2 BIT1); >> In an application program like the demo project the digital I/O ports are used repeatedly. The application programmer wraps the specific port functionalities by placing the assignments to the port specific registers into useful C functions. void setleds(unsigned char state) // Turn on 4 colored LEDs on P6.1-6.4 to match the hex value // passed in on low nibble state. Unfortunately the LEDs are // out of order with 6.2 is the left most (i.e. what we think // of as MSB), then 6.1 followed by 6.3 and finally 6.4 is // the right most (i.e. what we think of as LSB) so we have // to be a bit clever in implementing our LEDs // // Input: state = hex values to display (in low nibble) // Output: none // // smj, ECE2049, 27 Dec 2015 unsigned char mask = 0; // Turn all LEDs off to start P6OUT &= ~(BIT4 BIT3 BIT2 BIT1); if (state & BIT0) mask = BIT4; // Right most LED P6.4 if (state & BIT1) mask = BIT3; // next most right LED P.3 if (state & BIT2) mask = BIT1; // third most left LED P6.1 if (state & BIT3) mask = BIT2; // Left most LED on P6.2 P6OUT = mask;

>> These functions are easy to manipulate and can be re-sued in other applications with same hardware >> main() is then a series of calls to functions whose names convey their purpose void main(void) // Stop WDT WDTCTL = WDTPW WDTHOLD; // Stop watchdog timer initbuttons(); initleds(); configdisplay(); configkeypad(); while (1) setleds(some_val); What about the buttons? --> There are 2 on Launchpad and 4 on the board. These are the lab board buttons --> Notice no external pull resistors used. Need to configure internal pull resistors on these pins (PxREN) --> Do they need to be Pull-UP or Pull-DOWN?

P7.0 P3.6 P2.2 P7.4 GND What about keypad? P1.5 col 1 of keypad P4.3 MSP430F 1 Pressing the key closes the switch 5529 P1.2 4 P1.3 7 P1.4 *

void configkeypad(void) // Configure digital IO for keypad // smj -- 27 Dec 2015 // Col1 = P1.5 = // Col2 = P2.4 = // Col3 = P2.5 = // Row1 = P4.3 = // Row2 = P1.2 = // Row3 = P1.3 = // Row4 = P1.4 = // Select pins for digital IO P1SEL &= ~(BIT5 BIT4 BIT3 BIT2); P2SEL &= ~(BIT5 BIT4); P4SEL &= ~(BIT3); // Columns are? P2DIR = (BIT5 BIT4); P1DIR = BIT5; P2OUT = (BIT5 BIT4); // P1OUT = BIT5; // // Rows are? P1DIR &= ~(BIT2 BIT3 BIT4); P4DIR &= ~(BIT3); P4REN = (BIT3); // P1REN = (BIT2 BIT3 BIT4); P4OUT = (BIT3); // P1OUT = (BIT2 BIT3 BIT4); Polling >> How do you now monitor and use your properly configured digital I/O ports? ---> By repeatedly checking if button status has changed! --> Without the swdelay main loop executes << 1 ms --> First thing that happens in each loop is to check the button! Inside demo project main.c while (1) // Forever loop ret_val = readbuttons(); setleds(~ret_val);