CprE 288 Spring 2014 Homework 5 Due Fri. Feb. 21

Similar documents
CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Tutorial 1: C-Language

Embedded Controller Programming 2

Computer Organization & Systems Exam I Example Questions

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

EE 472 Embedded Systems. Name solutions. Instructions:

CprE 288 Translating C Control Statements and Function Calls, Loops, Interrupt Processing. Instructors: Dr. Phillip Jones Dr.

Overview. The C programming model. The C programming model. The C programming model. The C programming model 1/23/2009. Real-time Systems D0003E

ECE2049: Embedded Systems in Engineering Design Lab Exercise #3 C Term Making a Time and Temperature Display

EL2310 Scientific Programming

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

Goals of this Lecture

C Language Programming

Intermediate Programming, Spring 2017*

Homework #3 CS2255 Fall 2012

ECE332, Week 8. Topics. October 15, Exceptions. Hardware Interrupts Software exceptions

Data Types and Variables in C language

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018

Interrupt vectors for the 68HC912B32. The interrupt vectors for the MC9S12DP256 are located in memory from 0xFF80 to 0xFFFF.

CPS 104 Computer Organization and Programming

BLM2031 Structured Programming. Zeyneb KURT

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

A Fast Review of C Essentials Part I

C Language Advanced Concepts. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Computer Labs: I/O and Interrupts

EL6483: Brief Overview of C Programming Language

Binghamton University. CS-211 Fall Pointers

SIGNED AND UNSIGNED SYSTEMS

Programming in C++ 5. Integral data types

Operators. Lecture 3 COP 3014 Spring January 16, 2018

Computer Systems C S Cynthia Lee

Basic Types, Variables, Literals, Constants

Survey. Motivation 29.5 / 40 class is required

The C Programming Language Guide for the Robot Course work Module

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Pointers. 10/5/07 Pointers 1

Memory, Data, & Addressing I

Lecture 8: Pointer Arithmetic (review) Endianness Functions and pointers

Intro to C: Pointers and Arrays

AN703. Micro64/128. Accessing the 36k of SRAM 12/3/04

Programming refresher and intro to C programming

EECS150 - Digital Design Lecture 12 - Video Interfacing. MIPS150 Video Subsystem

University of Texas at Austin Electrical and Computer Engineering Department. EE319K, Embedded Systems, Spring 2013 Final Exam

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ...

LECTURE 3 C++ Basics Part 2

Memory, Data, & Addressing II CSE 351 Spring

Embedded Systems. Input/Output Programming

Heap Arrays. Steven R. Bagley

The naked computer. The naked computer. Separate bus architecture. Real-time Systems SMD138

Type Checking. Prof. James L. Frankel Harvard University

CSE351: Memory, Data, & Addressing I

CS31 Discussion 1E Spring 17 : week 08

Use a calculator and c = 2 π r to calculate the circumference of a circle with a radius of 1.0.

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

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

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

15-122: Principles of Imperative Computation, Spring Written Homework 12. Due: Sunday 15 th April, 2018 by 10pm. Name: Andrew ID: Section:

CMPE012 Computer Engineering 12 (and Lab) Computing Systems and Assembly Language Programming. Summer 2009

Using peripherals on the MSP430 (if time)

REFERENCES, POINTERS AND STRUCTS

Embedded Systems Programming. ETEE 3285 Topic HW3: Coding, Compiling, Simulating

16.317: Microprocessor Systems Design I Spring 2015

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

Homework. Reading. Machine Projects. Labs. Intel 8254 Programmable Interval Timer (PIT) Data Sheet. Continue on MP3

FINAL EXAM. last name first name

Arduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface.

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

C Programming Language (Chapter 2 of K&R) Variables and Constants

Final CSE 131B Spring 2004

C Language, Token, Keywords, Constant, variable

Structured Data. CIS 15 : Spring 2007

Important Questions for Viva CPU

Special Topics for Embedded Programming

CS-281, Spring 2011 Data Lab: Manipulating Bits Assigned: Jan. 17, Due: Mon., Jan. 31, 11:59PM

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

CMPE-013/L. Introduction to C Programming

ET156 Introduction to C Programming

Midterm Exam Answers Instructor: Randy Shepherd CSCI-UA.0201 Spring 2017

CprE 288 Introduction to Embedded Systems

Microcontroller basics

Ch. 11: References & the Copy-Constructor. - continued -

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I

Memory, Data, & Addressing II

CprE 288 Introduction to Embedded Systems (Timers/Input Capture) Instructors: Dr. Phillip Jones

Memory and Addresses. Pointers in C. Memory is just a sequence of byte-sized storage devices.

Lecture 4: Outline. Arrays. I. Pointers II. III. Pointer arithmetic IV. Strings

Midterm CSE 131B Spring 2005

Lab 5: EBI and ADC: Digital Voltmeter

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

CS Programming In C

Migrating from Keil µvision for 8051 to IAR Embedded Workbench for 8051

CSI33 Data Structures

Representation of Information

from Appendix B: Some C Essentials

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

CS C Primer. Tyler Szepesi. January 16, 2013

CSCI 2212: Intermediate Programming / C Chapter 15

Types, Operators and Expressions

LCDs. Embedded Systems Interfacing. 20 September 2011

Transcription:

CprE 288 Spring 2014 Homework 5 Due Fri. Feb. 21 Notes: Homework answers must be typed using a word editor. Homework is individual work. Adhere to the University s policy relating to the integrity of scholarship. See http://catalog.iastate.edu/academiclife/#regulationstext, Academic Dishonesty. Late homework is accepted within three days from the due date. Late penalty is 10% per day (for each 24 hours following your class). Note: Unless otherwise specified, all problems assume the ATMega128 is being used Question 1: C Operator Precedence (15 pts) Does each of the code pieces serve for its stated purpose? You must explain to get the full credit. Assume the following variable declaration: unsigned int a, b, c, d, mask; unsigned int *p = &a; Hint: Check the operator precedence chart, slide 49 of week 5. a. [3] Check if a is equal to b, or b is equal to c and c is equal to d. if (a == b b == c && c == d) // code Yes, because == higher than &&, and && is higher than b. [3] Check if the upper half of a is equal to the upper half of b. mask = 0xFF00; if (a&mask == b&mask) // code No, because == will run first. == has higher precedence than &. c. [3] Copy a s value to b, meanwhile increment pointer p. b = *p++; Yes, because p++ will run first and * dereference what p points at and assign it into b.

d. [3] Add the lower half of a and the lower half of b, store the result to c. The result should appear in the lower half of c, and the upper half of c should be cleared to zero. c = (a<<8 + b<<8) >> 8; No, + has higher precedence than <<. e. [3] Swap the upper half and the lower half of b. b = b<<8 b>>8; Yes, << and >> has higher precedence than. Question 2: C Type Conversion and Casting (15 pts) What is the outcome of each of the following assignment statements or if- condition? For an assignment statement, state the value of the variable being assigned after the execution of the statement. You must explain to get the full credit. Assume the following variable declaration: signed char byte = -50; short ADC_input = 500; unsigned int n; Hint: If you are not sure about an outcome, you can write a program to find out (using AVR studio). a. [3] byte = ADC_input; byte = 0xF4 because byte only have one byte. If assign 2 bytes of 0x01F4, then the byte will be 0xF4. b. [3] n = (unsigned int) byte; n = 0x00ce because force cast byte to int will give 0x00ce. c. [3] n = (int) byte; n = 0xffce, because byte is an negative number, when it force cast into integer, it will add 1 in front of the original bits.

d. [3] n = ADC_input + (signed char) byte; n = 0x01c2, because 500 minus 50 is equal to 450 = 0x01c2 e. [3] n = ADC_input + (unsigned char) byte; n = 0x02c2, because -50 is 0xce when force into unsigned char. And 0x01f4+ 0xce is equal to 0x02c2 Question 3: C Standard Library (10 pts) Assume in a programming assignment you need a function to test whether a character appears in a C string; for example, yes for C being a character in This is CprE288. Find out such a function in C Standard Library. Write a short program to verify that the function you found works. Test it in a programming environment, e.g. Linux, Microsoft Visual Studio, or Dev- C++ (use only C code). Cut and paste your program code and test output here. Code:

Output: Question 4: Memory- Mapped I/O (10 pts) Consider developing memory- mapped interface for a mouse along the lines of the keyboard example presented in the class. a. Specify the data and control register(s) in this interface. Assume that the mouse transmits (ΔX, ΔY), (the distance the mouse has traveled since last click in byte sized chunks) and left or right click occurrences. Data: char* MSDR; Control register: struct MSCR unsigned int x; unsigned int y; unsigned char traveled; unsigned int left; unsigned int right; unsigned int READY; MSCR:

b. Assume that the I/O address space starts at 0xFF00. Assign addresses to all the data and control registers in the memory- map interface of the mouse. MSDR = 0xFF00; MSCR = 0xFF01; c. Show a polled version of a function readdeltax() that reads ΔX into a program variable deltax. Only fresh data should be read as in the keyboard example in the class. readdeltax() Int oldx = MSCR.x; while(!(mscr.ready)); deltax = MSCR.x oldx; return; d. If we want to allow the mouse to have the capability to interrupt the processor, what else would have to added to its memory map interface? Show an ISR equivalent of readdeltax()that is bound to the interrupt vector CLICK_DELTA_X_VECT. ISR (CLICK_DELTA_X_VECT) int oldx = MSCR.x; if(mscr.ready) deltax = MSCR.x oldx; Question 5: Interrupt Service Routine (10 pts) Explain why a variable shared by an ISR and the foreground program execution must be declared as volatile. In particular, discuss what will happen if volatile is NOT used on the shared variable and compiler optimization is enabled. The following is an example: volatile static int clock_flag = 0; ISR (TIMER1_COMPA_vect) clock_flag = 1; int main()

// other code while (1) if (clock_flag == 1) // advance the clock, print clock on LCD Volatile is intended to prevent the compiler from applying certain optimizations that make the program running in the way you don t mean to be. When volatile is not used, in the while loop, the clock_flag will be always in 0 state, even if the interruption is applied. So, without it, the program will not print clock on LCD forever.