Scope & Register Access

Similar documents
Register Access. Common - Last updated 7/25/18

Scope. Scope. Region of a program in which a defined object is visible. Defined Objects. Two types of regions. Variables Functions

6. General purpose Input/Output

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

Arrays. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18

The digital I/O is configured with user software. The setup and operation of the digital I/O is discussed in the following sections.

Timer 32. Last updated 8/7/18

Basic System Memory Architecture View (Functional)

Decisions II. Switch Statement. If else allows a 2 way decision Switch allows for n-way decisions

MSP-EXP430fr5994 Experimenter Board with noforth 5994

Code Composer Studio. MSP Project Setup

Interconnects, Memory, GPIO

Interrupts. Why Interrupts

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

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

Using peripherals on the MSP430 (if time)

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

More Arrays. Last updated 2/6/19

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

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

Why embedded systems?

Review Activity 1 CALL and RET commands in assembler

Types. C Types. Floating Point. Derived. fractional part. no fractional part. Boolean Character Integer Real Imaginary Complex

Interrupts, Low Power Modes

MSP430FG4618 Programming Reference Revision 3

Global & Local Identifiers

Create and Add the Source File

Lecture test next week

AMCAT Procedure functions and scope Sample Questions

Lecture 5: MSP430 Interrupt

Practice Sheet #07 with Solutions

Embedded Technosolutions

ADC 14. Last updated 9/1/18

Wireless Sensor Networks (WSN)

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

Unit 7. Functions. Need of User Defined Functions

Block diagram of processor (Harvard)

Type Definition. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18

Two Wire Interface (TWI) also commonly called I2C

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

Lab 1: I/O, timers, interrupts on the ez430-rf2500

PROGRAMMAZIONE I A.A. 2017/2018

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Serial Peripheral Interface (SPI)

APS105. Modularity. C pre-defined functions 11/5/2013. Functions. Functions (and Pointers) main. Modularity. Math functions. Benefits of modularity:

Universität Dortmund. IO and Peripheral Interfaces

Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14

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

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

Question 2. [5 points] Given the following symbolic constant definition

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #07. Topic: Pointer in C Date:

M1-R4: Programing and Problem Solving using C (JAN 2019)

QUIZ Lesson 4. Exercise 4: Write an if statement that assigns the value of x to the variable y if x is in between 1 and 20, otherwise y is unchanged.

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

Serial Peripheral Interface (SPI) Last updated 8/7/18

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

Getting Started with the Texas Instruments ez430

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

Python Boot Camp. Day 3

Chapter 10. Implementing Subprograms

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

Quiz1 Fall 2007 October 2 nd, UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated :October 2nd, 2007.

The MC9S12 Timer Output Compare Function Making an event happen at specific time on the HC12 The MC9S12 Output Compare Function

CS240: Programming in C

Chapter 5 C Functions

Storage class in C. Automatic variables External variables Static variables Register variables Scopes and longevity of above types of variables.

Capturing the Time of an External Event Input Capture Subsystem

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

The MC9S12 Timer Input Capture Function

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

EL6483: Brief Overview of C Programming Language

Day08 A. Young W. Lim Mon. Young W. Lim Day08 A Mon 1 / 27

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

LECTURE - 4 Programming MSP430 using Code Composer Studio(CCS)

EE C Program Elements

Team 3. By: Miriel Garcia. Microcontrollers/ TI MSP430F5438A. ECE 480 senior Design. Application Note 4/3/15

12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return

ALGORITHM 2-1 Solution for Exercise 4

Texas Instruments Microcontroller HOW-TO GUIDE Interfacing Keypad with MSP430F5529

Texas Instruments Mixed Signal Processor Tutorial Abstract

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

Getting Started with the MSP430 IAR Assembly

C Programming Language

/* EXAMPLE 1 */ #include<stdio.h> int main() { float i=10, *j; void *k; k=&i; j=k; printf("%f\n", *j);

Function I/O. Last Updated 10/30/18

Variables and Functions. ROBOTC Software

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

Standard Version of Starting Out with C++, 4th Edition. Chapter 6 Functions. Copyright 2003 Scott/Jones Publishing

Lecture 5 Tao Wang 1

! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How?

Arrays. Comp Sci 1570 Introduction to C++ Array basics. arrays. Arrays as parameters to functions. Sorting arrays. Random stuff

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

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura

COP4020 Programming Assignment 1 - Spring 2011

Why VC++ instead of Dev C++?

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter 2012

Lecture 6. Statements

Transcription:

Scope & Register Access

Scope Scope Region of a program in which a defined object is visible Defined Objects Variables Functions Two types of regions Blocks Not in a block 2 tj

Scope Program Prototype Blocks Statements enclosed in { } Contents of Main Contents of Functions Not in a Block Global Area // comments #include <stdio.h> int foo; int fun1(int x, int y); // function prototype int main(void){ int x; int y; Main s Area float a; if( ){ float x = a * 3; float a; float b; Nested Block Area } else b = x * y; } // end of main int fun1 (int i, int j){ int x; int y; } // end of fun1 Global Area Function fun1 Area 3 tj

Scope Scope An objects scope extends from it s declaration to the end of it s block Global Scope Any object defined in the global area of a program Visible anywhere in the current program Local Scope Any object defined in a block area Includes Main and Functions Visible anywhere in the current block 4 tj

Scope Scope Local definitions supersede global definitions within a block // example #include <stdio.h> int x; int y; These x, y are not the same as these int main(void){ int x; float y; } 5 tj

Scope Scope // comments #include <stdio.h> int foo; int fun1(int x, int y); int main(void){ int x; int y; float a; if( ){ float x = a * 3; float a; float b; } else b = x * y; } // end of main int fun1 (int i, int j){ int x; int y; } // end of fun1 // function prototype foo is visible here this a- is visible here but this is a new a- 6 tj

Scope Scope 7 tj

Scope Scope 8 tj

IO Register Access

IO Structure Controlled by a series of registers 10 tj

IO Structure Output Path Direction Register 1 for output Data Register 0 or 1 11 tj

IO Structure Input Path Direction Register 0 for input Input Register 0 or 1 12 tj

IO Structure Input Path w/ Pull-up Pull Up/Down Register 1 for Enable Direction Register 0 for input Data Register 1 for pull-up Input Register 0 or 1 13 tj

IO Structure Input Path w/ Pull-down Pull Up/Down Register 1 for Enable Direction Register 0 for input Data Register 0 for pull-down Input Register 0 or 1 14 tj

Register Set (simplified) 8 bit registers 1 bit for each of 8 I/O pins 8 I/O pins assigned to a port 10 ports 1 through 10 Register Names P port x port number function port function P2DIR Port 2 Direction Register 15 tj

Register Set (simplified) PxDIR Direction register 0 for input, 1 for output PxIN Input Data Register Holds the value of the input pin 0 or 1 PxOUT Output Data Register Holds the value for the output pin 0 or 1 Holds the value of the pull-up/down when pull ups/down enabled 0 for pull down, 1 for pull up PxREN Enable Pull-Up/Down Register 1 for enabled 16 tj

Register Set (advanced) PxDS Drive Strength Register 0 for regular strength, 1 for high drive strength PxSEL0, PxSEL1 Mode Select Register PxIE Interrupt Enable Register 1 for enable PxIES Interrupt Edge Select Register 0 for high -> low, 1 for low -> high PxIFG Interrupt Flag Register Set to 1 on selected edge transition PxIV Interrupt Vector Register 17 tj

IO Port Configuration portmap(2, OUTPUT); Pin 2 is actually Port 6, bit 0 Need to set this pin to an output P6DIR = 0x01; P6DIR = b00000001; P6DIR = 1; // set port 6 bit 0 to an output // set port 6 bit 0 to an output // set port 6 bit 0 to an output 18 tj

IO Port Configuration P6DIR = 0x01; P6DIR = b00000001; P6DIR = 1; // set port 6 bit 0 to an output // set port 6 bit 0 to an output // set port 6 bit 0 to an output These set the other 7 pins to inputs this may not be OK P6DIR = 0x01; // set port 6 bit 0 to an output P6DIR = babcdefgh b00000001 P6DIR = babcdefg1 Only the bit we want to change is changed 19 tj

IO Port Configuration portmap(3, INPUT); Pin 3 is actually Port 3, pin 2 P3DIR &= ~0x04; // set port 3 bit 2 to an input P3DIR &= ~b0000100; // set port 3 bit 2 to an input P3DIR = babcdefgh & ~b00000100 P6DIR = babcdefgh & b11111011 P6DIR = babcde0fg Only the bit we want to change is changed 20 tj

IO Port Configuration portmap(4, INPUT_PULLUP); Pin 4 is actually Port 3, pin 3 P3DIR &= ~0x08; // set port 3 bit 3 to an input P3OUT = 0x08; // prepare to make pullup P3REN = 0x08 // enable pull_x for port 3 pin 3 21 tj

IO Port Configuration portmap(5, INPUT_PULLDOWN); Pin 5 is actually Port 4, pin 1 P4DIR &= ~0x02; // set port 4 bit 1 to an input P4OUT &= ~0x02; // prepare to make pulldown P4REN = 0x02 // enable pull_x for port 4 pin 1 22 tj

IO usage Write a square wave to pin 5 to drive an LED #include msp.h P4DIR = 0x02; // set port 4 bit1 (pin 5) to an output P4OUT &= ~0x02; // initialize output to 0 while(1){ _delay_cycles(460000); P4OUT = 0x02; _delay_cycles(460000); P4OUT &= ~0x02; } // high // low 23 tj

IO usage Read from pin 5 as an input #include msp.h P4DIR &= ~0x02; P4REN &= ~0x02; // set port 4 bit 1 (pin 5) to an input // Ensure pullx not enabled while(1){ int foo; foo = P4IN & 0x02; // check only bit 1 // if high foo has the value 0x02 NOT 1 // or foo = (P4IN & 0x02) && 0x01; // if high foo has the value 0x01 } 24 tj

IO usage Make a decision based on pin 5 as an input #include msp.h P4DIR &= ~0x02; P4REN &= ~0x02; // set port 4 bit 1 (pin 5) to an input // Ensure pullx not enabled while(1){ if ((P4IN & 0x02)!= 0) //do this if high else // do this if low // or THIS WILL NOT WORK if ((P4IN & 0x02) == 1) //do this if high else // do this if low } if (P4IN & 0x02) //do this if high else // do this if low 25 tj