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

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

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

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

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

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

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

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

Why embedded systems?

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

Review Activity 1 CALL and RET commands in assembler

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

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

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

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

Using peripherals on the MSP430 (if time)

Texas Instruments Microcontroller HOW-TO GUIDE Interfacing Keypad with MSP430F5529

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

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

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

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

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

Lab 1: Simon. The Introduction

Lecture 5: MSP430 Interrupt

Texas Instruments Mixed Signal Processor Tutorial Abstract

Interrupts, Low Power Modes

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

Integer Representation

CONTENTS: Program 1 in C:

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

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

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

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

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

6. General purpose Input/Output

Lab 1: Space Invaders. The Introduction

@databasescaling Wednesday, 18 th April 2013

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

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

ME 461 C review Session Fall 2009 S. Keres

Lecture test next week

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

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

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

Before Class Install SDCC Instructions in Installing_SiLabs-SDCC- Drivers document. Solutions to Number Systems Worksheet. Announcements.

EE251: Thursday November 15

COMP2611: Computer Organization. Data Representation

Manipulating Integers

CPS 104 Computer Organization and Programming

Block diagram of processor (Harvard)

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

What is an Interrupt?

Installation tutorial for the Skomer IDE

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

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

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

Getting Started with the Texas Instruments ez430

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

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

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

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

Basic System Memory Architecture View (Functional)

Create and Add the Source File

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

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

LAB A Translating Data to Binary

Integers II. CSE 351 Autumn Instructor: Justin Hsia

Microcontroller Introduction

Integers II. CSE 351 Autumn 2018

Embedded Systems - FS 2018

Embedded Systems - FS 2018

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

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

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

ECE2049: Homework 1. Due: Thursday, 25 May 2017 by 7pm

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

CS107, Lecture 3 Bits and Bytes; Bitwise Operators

Inf2C - Computer Systems Lecture 2 Data Representation

EE 109 Unit 2. Binary Representation Systems

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

Data III & Integers I

ECE2029: Introduction to Digital Circuit Design Lab 3 Implementing a 4-bit Four Function ALU

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

CS 24: INTRODUCTION TO. Spring 2015 Lecture 2 COMPUTING SYSTEMS

ECE2049: Homework 1. Consider the following code to compute the average of your exam grades: #define NUM_EXAMS (3)

Bits, Bytes, and Integers Part 2

Before next weeks lab:

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

srl - shift right logical - 0 enters from left, bit drops off right end note: little-endian bit notation msb lsb "b" for bit

ENE 334 Microprocessors

Week 4: Embedded Programming Using C

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

CS 241 Data Organization Binary

SRF02 Ultrasonic range finder Technical Specification

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

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

Arithmetic and Bitwise Operations on Binary Data

Kpad. Technical Manual

UNIVERSITY OF LIMERICK OLLSCOIL LUIMNIGH COLLEGE OF INFORMATICS & ELECTRONICS DEPARTMENT OF ELECTRONIC & COMPUTER ENGINEERING

Transcription:

ECE2049: Embedded Computing in Engineering Design C Term Spring 2018 Lecture #7: More Digital IO Reading for Today: Davies 7.5-7.9, Users Guide Ch 12 Reading for Next Class: Davies 7.5-7.9, Users Guide Ch 12 Lab #0 (on web): Due NOW!! Lab #1 (on Web) : Early sign-off bonus by Fri 1/26 (code submit 5 pm) Report, code due Tues /30 HW #2 (on Web): Due Fri day 1/26 (in class) EXAM #1 9 am Monday 1/29/2018 in AK-116 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 --Bit = 0 = Not enabled (default) buttons) --Bit = 1 = Enabled (see User's Guide) >> All I/O port registers are memory mapped They have addresses! Read and write to the registers names (defined msp430x55x.h) as if they were C variables! -------------------------------------------------------------------------------------------------------- From last class: Ex: Using CCS C configure Port 3 for digital I/O with Pins 1 and 0 as inputs and Pins 7 thru 4 and outputs. BRUTE FORCE WAY: Does NOT preserve settings for unused pins 2 & 3. P3SEL = 0; // P3SEL = 0000 0000b = ALL P3 pins selected for digital I/O P3DIR = 0xF0; // P3DIR = 1111 0000b = P3.7-4 = Outputs, P3.3-0 = Inputs BETTER WAY: Use bit-wise operators to save any settings pins 2 & 3 may have --Remember, AND with 0 to set a bit to 0, AND with 1 to leave bit alone --OR with 1 to set bit to 1 and OR with 0 to leave bit alone P3SEL = P3SEL & 0x0C; // P3SEL AND 00001100b = 0000 xx00b P3DIR = P3DIR 0xF0; // P3DIR OR 11110000b = 1111xxxxb P3DIR = P3DIR & 0xFC; // P3DIR AND 11111100b = 1111xx00b

Using pre-defined constants to avoid magic numbers >> In C, there is always multiple ways to implement the same functionality >> Some ways are accepted as representing better coding style Try to avoid magic numbers = fixed hard-coded numbers that appear in code without explanation of their meaning or purpose >> These values are pre-defined in the msp430f5529.h header file... we can just use 'em! BIT0 = 00000001 BIT4 = 00010000 BIT1 = 00000010 BIT5 = 00100000 BIT2 = 00000100 BIT6 = 01000000 BIT3 = 00001000 BIT7 = 10000000 BIT2 BIT3 = 0000 0100 or 0000 1000 0000 1100 ~(BIT1 BIT0) = NOT(00000010 OR 00000001) = 1111 1100b From last lecture: Configured P3.1-0 as inputs and P3.7-4 as outputs. P3SEL = P3SEL & (BIT2 BIT3); // = 0000 xx00 P3DIR = P3DIR (BIT7 BIT6 BIT5 BIT4); // = 1111xxxx P3DIR = P3DIR & ~(BIT1 BIT0); // = 1111xx00

Ex: Now, read in from Port 3 Pins 1-0 and put a 1 on the output Pin 7-4 that corresponds to the binary code 0-3 on Pins 1-0. P3.4 should represent 0 and P3.7 should represent 3. 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 */ /* Setup P4.7-4 as digital IO outputs */

char in_p6() // Read in from port 6. Preserve only the low nibble) char inbits; // local variable inbits = return(inbits); // return the value inbits void out_comp_p4(char inbyte) char outbits; // Complement input value, inbyte outbits = // Shift low nibble left to bits 7-4 outbits = //output on P4.7-4 P4OUT = An example of calling these functions inside a main() main(). portconfig(); indata = in_p6(); out_comp_p4(indata); // indata is locally defined char Now you know how to configure Digital IO ports when given that the pins are to be inputs or outputs but how do you know?

Input or Output? Let's take a closer look at the digital IO devices on our lab board starting with the 4 multi-colored 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);