Skip to content

Embedded Systems Programming Lesson 3 Homework

EE319K Introduction to Embedded Systems5/3/2012 version
Course Catalog Description Embedded systems; machine language execution; assembly and C language programming; local variables and subroutines; input/output synchronization; analog to digital conversion and digital to analog conversion; debugging; and interrupts.   EE319K will continue the bottom-up educational approach, started in EE302 and EE306. The overall educational objective is to allow students to discover how the computer interacts with its environment. It will provide hands-on experiences of how an embedded system could be used to solve EE problems. The focus will be understanding and analysis rather than design. The analog to digital converter (ADC) and digital to analog converter (DAC) are the chosen mechanism to bridge the CE and EE worlds. EE concepts include Ohms Law, LED voltage/current, resistance measurement, and stepper motor control. CE concepts include I/O device drivers, debugging, stacks, FIFO queues, local variables and interrupts. The hardware construction is performed on a breadboard and debugged using a multimeter (students learn to measure voltage and resistance). Software is developed in Freescale 9S12 assembly and C; 3 out of the 10 labs are simulated-only in TExaS and other 7 are first simulated on TExaS then run on the real 9S12. Software debugging occurs during the simulation stage. Verification occurs in both stages. Labs 1 through 6 are written in 9S12 assembly language. Labs 8 and 9 are written in a combination of assembly and C.  Labs 7 and 10 are written in a C.
Class: ACA 1.104, Tuesday, Thursday 5-6:15pm   Lab: ACA 1.108 (old EE302 room)
Office Hours (change): Tuesday 3:30-4:50pm, Wednesday 1-2pm, Friday 12noon-1

Instructor: Jonathan W. Valvano, ENS627, 471-5141
email  (put "EE319K" in the email title, send no ZIP files)  
Web page 
Lecture notes and lab assignments 2012 homework 
Data sheets  
Starter files 
Unique Numbers:  16215 Th1-2, 16220 Th2-3, 16225 Th3-4, 16230 Th4-5 
Text: Introduction to Embedded Systems: Interfacing to the Freescale 9S12, Cengage Publishing 2009, ISBN-10: 049541137X | ISBN-13: 9780495411376, by J. W. ValvanoCengage Learning Publisher's Website If you find any mistakes in the book, please let me know. Known errors can be found at list of textbook errors.  We have written a C programming book specific for the Metrowerks compiler and 9S12.

You can download TExaS from the documents section of Blackboard.

Equipment to buy: We are no longer giving microcontroller boards to students. I can tell you the discussions on how to maintain educational excellence in the face of repeated budget cuts has been long and careful. Every group of two students will be required to have one 9S12 board. Either the Technological Arts Adapt9S12DP512 or the Adapt9S12DG128 will suffice.  The first possibility is to buy or borrow a board from a previous EE319K/EE445L student. If you obtain a kit from a previous student, you will need the board, power supply, RS232 cable, and a protoboard. If you do buy a board from another student, I recommend you run the hardware checker to make sure the board is functional. The second possibility is to purchase a new Technological Arts Adapt9S12DG128 kit, which includes a board, power supply, serial cable, and solderless breadboard. The student cost will be $79.00 per kit. The link to pay for this kit is active. The buying process will be:
a) Once you have selected your partner for Labs 3-9, you go to the  web site and pay $79 to TechArts for the kit via PayPal. Please pay for your kit at least 7 days before the demonstration lab period. Our experience is that many credit card companies will add $1 to $3 to the transaction because TechArts is a Canadian company. Neither UT or TechArts sees this added fee. The fee is charged by the credit card company.
b) The department will get an email from TechArts that you have paid.
c) You will go to ENS234 to pickup the kit. There will be specific scheduled hours for the pickup phase, which will be around Feb 8 to 15.
d) There will be a board demonstration lab between labs 2 and 3, the week of Feb 14-18, and you should bring your board to this demonstration. Your TA will show you how to test your board to verify it is operational. If the board does not work during the testing procedure, we will replace it. Our experience with EE319K is if the board works during the initial test, almost all students complete EE319K labs without damaging the board. However, if you do damage your board, then you must purchase another one. Unfortunately we will not be using the board in EE319K in Fall 2012, so you will not have many opportunities to sell it. However, it could be useful for senior lab or other projects. There is no difference to a EE319K student between the Adapt9S12DP512 and Adapt9S12DG128 board. The DG128 board has a little less memory and is a lot less expensive. Every student should own their own voltTAs:    TAs will hold office hours in Lab: ACA 1.106. The office hours will be posted in lab. About 32 students per TA.    Email all professors and TAs (         
Peter Garatoni,

Manan Kathuria,

Jae Hong Min 

Pratyusha Nidamaluri,

Dayo Lawal


Kurt Fellows,

James Beecham,

Austin Blackstone,

Razik Ahmed,

Brandon Carson,

Kin Hong Mok,

Omar Baca,

Sam Oyetunji,

Zack Lalanne,

Nathan Quang Minh Thai,

Paul Fagen,

Outcomes: After the successful conclusion of EE319K students should be able to understand the basic components of a computer, write assembly and C language programs that perform I/O functions and implement simple data structures, manipulate numbers in multiple formats, and understand how software uses global memory to store permanent information and the stack to store temporary information. 

EE319K will have reading assignments from Patt's Introduction to Computing Systems (

Web videos of the Example lessons from the book  Teaching philosophy
I strongly encourage students to take an active role in this class.  Questions are welcome before, during and after class. Please feel free to email, visit or call me if you have questions.

Things you should recall from EE306/BME303

1.      Bits

    1. Numbers - Unsigned and Signed Integer representation in 2’s Complement
    2. True/False - Logical Operations
    3. Characters - ASCII representation

2.      Gates

    2. DeMorgan’s Laws

3.      Computer Components

    1. Central Processing Unit: Arithmetic Logic Unit and Control Unit

                                                              i.      Registers

b.      Memory – ROM and RAM

                                                              i.      Address Space and Addressability

    1. I/O

4.      LC3 Assembly Language

    1. Instruction Set (ISA)

b.      Pseudo-ops

c.       Op-codes and Operands

                                                              i.      Memory operations

                                                            ii.      Arithmetic and Logic operations

                                                          iii.      Control operations – Branches/Jumps

    1. Addressing Modes

5.      Programming

    1. Algorithms

b.      Flow-Charts

c.       Data Types

d.      Arrays

    1. Interrupts

0) Understanding how the computer stores and manipulates data (characters, integers, and fixed-point numbers),
1) The understanding of embedded systems (a system with the computer hidden inside)
2) Assembly language and C programming
3) Understanding how the computer executes instructions (fetch opcode, fetch operand, read data, operate, and write data)
4) The use of a microcontroller (strategic use of RAM ROM and I/O) Microcontrollers typically have a little RAM and a lot of ROM. Globals, locals and the heap go in RAM. Constants and programs go in ROM.
5) Debugging and verification using a simulator and on the microcontroller (embedded systems typically do not have a print function)
6) How input/output actually happens (the students wire up analog and digital signals to the 9S12 and measure them with a voltmeter)
7) The implementation of an I/O driver (a set of programs that perform input/output)
8) Understanding, from an architecture standpoint, how local variables and parameters work (e.g., a space on the stack is dynamically created, the local variable is accessed using stack-pointer relative addressing, then the space is deallocated.)
9) Analog to digital conversion (ADC) e.g., the students interface a slide potentiometer to the ADC, and write software that measures the position of the slide, creating a display like “1.23 cm”
10) Interrupt synchronization, real-time ADC sampling (periodic timer interrupts),
11) Simple motors (e.g., open and closed-loop stepper motor control)
12) Digital to analog conversion (DAC), used to make simple sounds
13) Design and implementation of After the successful conclusion of EE319K students should be able to understand the basic components of a computer, write assembly language programs that perform I/O functions and implement simple data structures, manipulate numbers in multiple formats, and understand how software uses global memory to store permanent information and the stack to store temporary information.
    15% In class Exam 1, Thursday, February 23, 5-6:15pm, ENS507 (change)
    20% In lab Exam ACA 1.106 and ACA 1.108, in regular lab
    regularly scheduled time and place







Go to for demonstration


Lab 1

Digital Lock I/O, parallel port, direction register and logical function, written in assembly (simulated, groups of two)


Lab 2

LED and switch interface (simulated, groups of two)



Real board demonstration, bring your board to lab


Lab 3

LED and switch interface (board, groups of two)


Lab 4

Debugging Techniques, one switch, one LED (simulated and board, groups of two)


Lab 5 

Traffic Light Controller using the real 9S12 (simulated and board, groups of two)



Exam 2 (closed book) in ACA 1.108 Thursday 3/22


Lab 6 

LCD device driver, decimal fixed-point output, local variables (simulated and board, groups of two)



Go to ACA 1.106 for Metrowerks C demonstration


Lab 7a or 7b

Digital Piano or pacemaker using a 4-bit DAC, C (simulated and board, groups of two)


Lab 8

Real-time Position Monitor, ADC, interrupts, LCD, mixture of assembly and C (simulated and board, groups of two)


Lab 9

Distributed DAS, serial port interrupts, FIFO queue, mixture of assembly and C (simulated and board, groups of four)


Lab 10

TRobots programming competition, written in C (simulated, groups of two)

 The following schedule is preliminary, please check the web for the most recent version.





Lecture Schedule

Week 11/17

aLec01, aLec02, aLec03

Lec1.ppt, Lec2.ppt

Chapter 1, Appendix 1.1-1.8.2, Chapter 2 and 3

Introduction Course administration; Embedded systems, development cycle; Flow charts, data flow and call graph

- simulator; Numbers, Hexadecimal

Week 2

aLec03, aLec04,


Lec2.ppt, Lec3.ppt

Chapter 2 and 3, (Patt, Chapters 11 and 12)

Architecture– 9S12 architecture and execution; Simple addressing modes; Memory allocation; C Programming (C Primer) - Introduction to C; Structure of a C program (Cookie Day)

I/O, Execution, stack, subroutines - Parallel ports, direction registers; Logical and shift operations; C Programming – Assignment and Boolean Expressions.

Week 31/31

aLec06, aLec07,



Section 4.7 and 5.7, Chapter 3 and 5

Debugging- Debugging in

Arithmetic - Arithmetic operations; Condition code bits; C Programming – Functions

Week 42/7




Appendix 2, Section 2.6, Section 5.1, 5.2, 6.11

Board- Demo of the board (bring board to class);Switch input and LED output

Modular programming - If-then, loops; Subroutines parameters and the stack; Debugging dump; C Programming – Loops

Week 5




Lec6.ppt, Lec7.ppt

Section 6.1-6.3, 6.11, (Patt, Chapters 14, 16)

Pointers - Indexed addressing; Arrays; Strings

Timers– Timers; Advanced functional debugging. C Programming – Arrays, Indexing, Pointers.

Week 62/21




Chapters 1 – 5

Review for Test 1:

February 23 - Test 1 (closed book), in ENS507

Week 72/28


aLec15, aLec16


Section 6.8, 10.1, 7.1-7.5, 9.1

FSMs- Finite state machines (FSMs); Fixed-point numbers

Locals, parameters- Local variables; Stack frames and parameter passing; I/O synchronization

Week 83/6

aLec16, aLec17


Section 7.1-7.5, 6.8

C Programming – Scope of variables in C (Local/Global); Parameter Passing: Call-by-value and Call-by-reference.

C Programming - Structures and data types; FSMs in C


Spring Break

Week 93/20

aLec17, aLec18


Section 8.4, 10.1, 10.5, (Patt, Chapter 17)

LCD interface - LCD programming; Number conversions; Review for Test 2

March 21 - Test 2 (closed book): In lab (during registered lab time), ACA 1.106/108
Chapter 5 and 6

Week 103/27

aLec19, aLec20, aLec21


Section 9.2, 9.4, 9.6, 9.10, (Patt, Chapter 17)

Interrupts-9S12 interrupts and interrupt processing; Timer and periodic (output compare) interrupts

C programming – Metrowerks; C/assembly interface

Week 114/3

aLec28, aLec29,



Section 11.2-11.3, 11.1, 11.4

DAC conversion- Digital to analog conversion (DAC) on the 9S12; Sound generation

ADC conversion- Analog to digital conversion (ADC) Lab 8 design methods

Week 124/10

aLec23, aLec24, aLec25


Section 10.2, Section 8.1

Numerical calculations - Multiplication and division; Table lookup and interpolation.

Serial I/O - Serial communications interface (SCI); SCI programming and interrupts; Lab 9 introduction

Week 134/17

aLec26, aLec27, aLec30


Section 12.1-12.4, 8.7, (Patt, Chapter 19, skip Sections 19.4)

Thread communication- Producer-consumer problems; FIFO queue; C Programming - FIFO

TRobots - Stepper motors; TRobots discussion

Week 144/24

aLec31, aLec32, aLec33

C structures, abstraction, software design, software testing and TRobots

Week 155/1

aLec34, aLec37

TRobots Competition in Class

Review for Final Exam: Chapter 1 - 13

Due Date, Monday 11pm

Homework Schedule, upload to Blackboard


Homework 1: Hand Assembly


Homework 2: Assembly Concepts


Homework 3: Signed/Unsigned numbers Arithmetic/Logic operations (Patt, Chapters 11 and 12)


Homework 4: If-then-else, Loops, andFunctions (Patt, Chapter 13 and 14)


Homework 5: Functions and Arrays (Patt, Chapters 14, 16.3)


Homework 6: Practice Exam 2s


Homework 7: Solve Exam Problem 1 in C, Pointers and testing (Patt, Chapters 15, and 16)


Homework 8: Solve Exam Problem 2 in C, Pointers and testing (Patt, Chapters 15, and 16


Homework 9: Recursion Problem, (Patt, Chapter 17)


Homework 10: Old Final Exam

Computer Usage:

Introduction to Embedded Systems: Interfacing to the Freescale 9S12

Jonathan W. Valvano, Cengage Publishing, ISBN-10: 049541137X | ISBN-13: 9780495411376

A brief overview

1. Introduction to Embedded Microcomputer Systems
• Basic Components of an Embedded System
• Applications Involving Embedded System
• Flowcharts and Structured Programming
• Concurrent and Parallel Programming
• Product Development Cycle
• Successive Refinement
• Quality Design
• Debugging Theory
• Tutorial 1. Getting Started
• Homework Assignments
2. Introduction to Assembly Language Programming
• Binary and Hexadecimal Numbers
• Addresses, Registers and Accessing Memory
• Assembly Syntax
• Simplified 9S12 Machine Language Execution
• Simple Addressing Modes
• The Assembly Language Development Process
• Memory Transfer Operations
• Subroutines
• Input/Output
• Tutorial 2. Running with TExaS
• Homework Assignments
• Laboratory Assignments
3. Representation and Manipulation of Information
• Precision
• Boolean Information
• 8-Bit Numbers
• 16-Bit Numbers
• Extended Precision Numbers
• Logical Operations
• Shift Operations
• Arithmetic Operations: Addition and Subtraction
• Arithmetic Operations: Multiplication and Division
• Character Information
• Conversions
• Debugging Monitor using a LED
• Tutorial 3. Arithmetic and Logical Operations
• Homework Assignments
• Laboratory Assignments
4. 9S12 Architecture
• Introduction
• Understanding Software Execution At The Bus Cycle Level
• 9S12 Architecture Details
• The Stack
• 16-Bit Timer
• Memory Allocation
• Performance Debugging
• Tutorial 4. Building a Microcomputer and Executing Machine Code
• Homework Assignments
• Laboratory Assignments
5. Modular Programming
• Modular Design
• Making Decisions
• Macros
• Recursion
• Writing Quality Software
• How Assemblers Work
• Functional Debugging
• Tutorial 5a. Editing and Assembling
• Tutorial 5b. Microcomputer-Based Lock
• Homework Problems
• Laboratory Assignments
6. Pointers And Data Structures
• Indexed Addressing Modes used in Implement Pointers
• Arrays
• Strings
• Matrices
• Structures
• Tables
• Trees
• Finite State Machines with Statically-Allocated Linked Structures
• Dynamically Allocated Data Structures
• 9S12 Paged Memory
• Functional Debugging
• Tutorial 6. Software Abstraction
• Homework Assignments
• Laboratory Assignments
7. Local Variables And Parameter Passing
• Local versus Global
• Stack Rules
• Local Variables Allocated on the Stack
• Stack Frames
• Parameter Passing using Registers, Stack and Global Variables
• Tutorial 7. Debugging Techniques
• Homework Problems
• Laboratory Assignments
8. Serial and Parallel Port Interfacing
• General Introduction to Interfacing
• Serial Communications Interface, SCI
• Synchronous Peripheral Interface, SPI
• Scanned Keyboards
• Parallel Port LCD Interface with the HD44780 Controller
• Binary Actuators
• Pulse-Width Modulation
• Stepper Motors
• Homework Problems
• Laboratory Assignments
9. Interrupt Programming and Real-Time Systems
• I/O Synchronization
• Interrupt Concepts
• Key Wakeup Interrupts
• Periodic Interrupt Programming
• Real-Time Interrupt (RTI)
• Timer Overflow, Output Compare and Input Capture
• Pulse Accumulator
• Direct Memory Access
• Hardware Debugging Tools
• Profiling
• Tutorial 9. Profiling
• Homework Problems
• Laboratory Assignments
10. Numerical Calculations
• Fixed-Point Numbers
• Extended Precision Calculations
• Expression Evaluation
• IEEE Floating-Point Numbers
• Tutorial 10. Overflow and Dropout
• Homework Problems
• Laboratory Problems
11. Analog I/O Interfacing
• Approximating Continuous Signals In The Digital Domain
• Digital to Analog Conversion
• Music Generation
• Analog To Digital Conversion
• Multiple Access Circular Queues
• Real-Time Data Acquisition
• Control Systems
• Tutorial 11. Analog Input Programming
• Homework Problems
• Laboratory Assignments
12. Communication Systems
• Introduction
• Reentrant Programming and Critical Sections
• Interthread Communication and Synchronization
• Serial Port Interface Using Interrupt Synchronization
• Distributed Systems.
• Design and Implementation of a Controller Area Network (CAN)
• Inter-Integrated Circuit (I2C) Interface
• Wireless Communication
• Tutorial 12. Performance Debugging
• Homework Problems
• Laboratory Assignments
Appendix 1. Embedded System Development Using TExaS
• Introduction to TExaS
• Major Components of TExaS
• Embedded System Design Process
• Running and Modifying Existing Assembly Language Programs
• TExaS Editor
• Assembly Language Syntax
• TExaS Viewbox
• Microcomputer Interfacing In TExaS
Appendix 2. Running on an Evaluation Board
Appendix 3. Systems Engineering
• Design for Manufacturability
• Battery Power
Appendix 4. Glossary of Terms
Appendix 5. Solutions Manual
• Checkpoint Solutions
• Tutorial Solutions

How to download and install TExaS
A) Go to Cengage site
B) Click Student Companion Site for Introduction to Embedded Systems: Interfacing to the Freescale 9S12, 1st Edition
C) Click TExaS Software (on left)
D) Download 54 Meg zip file and unzip
E) Execute setup.exe in folder created by the zip file.
F) In Setup Type, choose Custom.
G) Select only 9S12DP (whatever microcontroller you will be using). The GCC is a huge and not very efficient compiler, and the examples and manuals on the web are more recent.
H) Delete zip file and the folder created containing the setup.exe.