Southwestern Indian Polytechnic Institute

Southwestern Indian Polytechnic Institute

Southwestern Indian Polytechnic Institute

A National Indian Community College

Division of Instruction

Department of Advanced Technical Education

Electronics Technology

ENGR 290 – Introduction to Microcontrollers

ENGR 290L – Introduction to Microcontrollers Lab

June 8, 2008

Course Syllabus


Thiscourseisdesignedtoprovidestudentswithanunderstandingofthe fundamentalprinciplesof microcontroller’shardware & software and its applicationin industry, alongwithintensivereinforcementthroughlabcoursework. The objective of ENGR 290/290L is for students to design and build a simple control system using a Motorola MC9S12 microcontroller. The design will include interfacing the microcontroller to a sensor and plant, and programming the control function into the microcontroller.Students are required to provide written and oral descriptions of their work for the class. The format includes individual, team, and class discussions and exercises.Classroom presentationwillbe throughlecture,audio/visual aids, and hands-on interactivedemonstrations.Monitoringofthe student’sprogress andcomprehensionwillbethrougha combination of standard testing procedures and lab projects, with major evaluations at mid-term and trimester-end(final).


Students should be familiarwith programming paradigm and concept and have a programming experience with anyhigh level programming language preferably C.

Terminal Objectives

Uponcompletionofthiscourse,thestudentshould be able

  • Work with microcontrollers to develop applications in the ECE and other related fields
  • Distinguish between the characteristics of a microcontroller, its applications and how it compares to a microprocessor.
  • Understand the relationship between hardware, software as they relate to microcontroller embedded systems and how they work together to solve a problem.
  • Work with the important features of embedded systems such as timers, interrupts, A/D, serial and parallel communications and their applications.
  • Work with an Integrated Development Environment, an Evaluation Board, and various other tools for project design, troubleshooting and debugging.
  • Analysis of a given flow chart and hardware schematic to deduce operation and functions of a microcontroller/embedded system.
  • Synthesis of a microcontroller/embedded system from a real-life problem statement.
  • Program the MC9S12 microcontroller in assembly language and in C, including use of subroutines and interrupt service routines
  • Use some of the internal peripherals of the MC9S12.
  • Interface external hardware to the MC9S12.
  • Use the Motorola manuals and data sheets to get the information necessary to do the above tasks.

Course Outline

The course will be outlined as follows:

Lecture 1

  • Introduction to Microprocessors and Microcontrollers.
  • Basic computer concepts
  • The processor
  • Memory and its various types
  • The computers software
  • The HCS12 CPU registers
  • Memory addressing

Lecture 2

  • Decimal, Hexadecimal and Binary Numbers
  • Convert binary and hex numbers to unsigned decimal
  • Convert unsigned decimal to hex
  • Binary, Hex, Signed and Unsigned Decimal
  • Signed number representation --- 2's Complement form
  • Overflow and Carry
  • Addition and subtraction of binary and hexadecimal numbers
  • The Condition Code Register (CCR): N, Z, V and C bits

Lecture 3

  • Introduction to Basic Digital logic gates
  • Analog vs. Digital signal
  • Noise issues
  • AND gate
  • OR gate
  • NOT gate
  • XOR gate
  • NAND gate
  • NOR gate
  • Basic digital circuit

Lecture 4

  • Introduction to the 9S12 Microcontroller
  • The HCS12 CPU Registers
  • CPU 12 Reference Manual
  • MC9S12 V1.5 Core User Guide
  • 68HC12 Address Space
  • 68HC12 ALU
  • 68HC12 Programming Model
  • Some 9S12 Instructions
  • The load and Store Instructions
  • Transfer and Exchange Instructions
  • Move Instructions
  • Add and Subtract Instructions
  • A Simple Assembly Language Program
  • Assembling an Assembly Language Program

Lecture 5

  • More on 9S12 Addressing Modes
  • Inherent Mode
  • Immediate Mode
  • Direct Mode
  • Extended Mode
  • Relative Mode
  • Indexed Mode
  • The N, Z, C and V bits of the Condition Code Register (CCR)
  • Addition and Subtraction of Hex numbers in microcontroller
  • Simple 9S12 programs
  • Hex code generated from a simple 9S12 program
  • More on 9S12 assembly language programming
  • More on HC12 Addressing Modes
  • Inherent, Extended, Direct, Immediate, Indexed, and Relative Modes
  • Summary of 9S12 Addressing Modes

Lecture 6

  • More on addressing modes.
  • 9S12 cycles and execution time.
  • AS12 Assembler Directives
  • Using X and Y registers as pointers
  • How to tell which branch instruction to use
  • How to hand assemble a program
  • Number of cycles and time taken to execute an 9S12 program

Lecture 7

  • AS12 Assembler Directives
  • label field
  • Dc.b , Dc.w, Ds.b , Ds.w
  • end
  • equate
  • org
  • A Summary of 9S12 instructions
  • Disassembly of 9S12 op codes
  • MC9S12 V1.5 Core User Guide Version 1.2, Section 12
  • A summary of 9S12 instruction
  • How to tell which branch instruction to use

Lecture 8

  • Disassembly of 9S12 op codes
  • Writing an assembly language program
  • Disassembly of 9S12 op codes
  • Use flow charts to lay out structure of program
  • Use common flow structures
  • if-then
  • if-then-else
  • do-while
  • while
  • Do not use spaghetti code
  • Plan structure of data in memory
  • Plan overall structure of program
  • Work down to more detailed program structure
  • Implement structure with instructions
  • Optimize program to make use of instruction efficiencies
  • Do not sacrifice clarity for efficiency

Lecture 9

  • Another simple program in assembly language
  • Using the stack and the stack pointer
  • Flow charts
  • Assembly language program
  • Assembly listing file
  • Assembly map file
  • The Stack and the Stack Pointer
  • The stack is an area of memory used for temporary storage
  • The stack pointer points to the last byte pushed onto the stack
  • Some instructions which use the stack, and how data is pushed onto and pulled off of the stack.

Lecture 10

  • More on programming in assembly language
  • Introduction to Ports on the HC12
  • Good programming style
  • Tips for writing programs
  • Input and Output Ports
  • Simplified Input Port
  • Simplified Output Port
  • Ports on the HC12
  • A simple program to use PORTA and PORTB
  • Subroutines and the Stack
  • Parameter Passing
  • Result returning
  • Allocation of local variables
  • An example of a simple subroutine
  • Using D-Bug12 Routines
  • Using a subroutine with PORTA to make a binary counter on LEDs

Lecture 11

  • Some more simple assembly language programs
  • Using 9S12 input and output ports
  • Using a subroutine to wait for and respond to an event
  • Using an input port to check the state of DIP switches
  • Using an output port to control LEDs
  • An assembly language program to display a pattern on a set of LEDs

Lecture 12

  • Introduction to Programming the 9S12 in C
  • Data Types
  • Variable Declaration
  • Constants
  • Arithmetic Operations
  • Bitwise Operations
  • Relational and Logical operations
  • Precedence of operations
  • Comparison of C and Assembly programs for the HC12
  • How to compile a C program using the GNU-C compiler
  • Using pointers to access the contents of specific addresses in C
  • Using the iodp256.h header file

Lecture 13

  • More on Programming the 9S12 in C
  • If-Else statement
  • Multiway conditional statement
  • Switch statement
  • For-Loop statement
  • While statement
  • Do-While statement
  • Goto statement
  • Introduction to the 9S12 Hardware Subsystems
  • A summary of 9S12 hardware subsystems
  • Introduction to the 9S12 Timer subsystem
  • Setting and clearing bits in Assembly and C
  • Some simple programs in C
  • Function to delay for a given number of milliseconds
  • Program to increment the LEDs connected to PORTA
  • Program to display a particular pattern on PORTA

Lecture 14

  • More on Programming the 9S12 in C
  • Pointers and Addresses
  • Arrays
  • Pointer and Arrays
  • Passing arrays to a Function
  • Initializing Arrays
  • Structures
  • The 9S12 has a 16-bit free-running counter to determine the time and event happens, and to make an event happen at a particular time
  • The counter is normally clocked with an 8 MHz clock
  • The Timer Overflow (TOF) bit -- when the timer rolls over from 0x0000 to 0xFFFF it sets a flip-flop to show that this has happened.
  • The Timer Prescaler (PR2:0) bits of Timer Interrupt Mask 2 (TMSK2) register: Allows you to change the frequency of the clock driving the 16-bit counter.

Lecture 15

  • Introduction to Interrupts
  • What is Interrupt
  • Why are interrupts used
  • Interrupt Maskability
  • Interrupt Priority
  • Interrupt Service
  • Interrupt Vector
  • Interrupt Programming
  • Overhead of Interrupts
  • How to generate an interrupt when the timer overflows
  • How to tell the 9S12 where the Interrupt Service Routine is located
  • Using interrupts on the HC12
  • The 9S12 registers and stack when a TOF interrupt is received
  • The 9S12 registers and stack just after a TOF interrupt is received
  • Interrupt vectors for the MC9S12DP256
  • The 9S12 registers and stack when a TOF interrupt is received
  • The 9S12 registers and stack just after a TOF interrupt is received
  • Interrupt vectors for the MC9S12DP256

Lecture 16

  • The Real Time Interrupt
  • CRG Block User Guide
  • Exceptions on the 9S12
  • Using interrupts on the 9S12
  • The Real Time Interrupt on the 9S12

Lecture 17

  • The 9S12 Input Capture Function
  • ECT_16B8C Block User Guide
  • Interrupts on the 9S12
  • Capturing the time of an external event
  • The 9S12 Input Capture Function
  • Registers used to enable the Input Capture Function
  • Using the 9S12 Input Capture Function
  • A program to use the 9S12 Input Capture in polling mode
  • Using the Keyword volatile in C
  • A program to use the 9S12 Input Capture in interrupt mode

Lecture 18

  • The 9S12 Output Compare Function
  • ECT_16B8C Block User Guide
  • Review of Timer Overflow and Input Capture
  • Making an event happen at a specific time on the HC12
  • The 9S12 Output Compare Function
  • Registers used to enable the Output Compare Function
  • Using the 9S12 Output Compare Function
  • A program to use the 9S12 Output Compare to generate a square wave
  • Setting and clearing bits in the Timer Subsystem
  • Introduction of Pulse Width Modulation

Lecture 19

  • The 9S12 Pulse Width Modulation System
  • PWM_8B8C Block User Guide
  • What is Pulse Width Modulation
  • The 9S12 Pulse Width Modulation system
  • Registers used by the PWM system
  • How to set the period for PWM Channel 0
  • How to set the clock for PWM Channel 0
  • Interdependence of clocks for Channels 0 and 1
  • PWM Channels 2 and 3
  • Using the 9S12 PWM
  • A program to use the 9S12 PWM

Lecture 20

  • Basics of A/D conversion
  • A Data Acquisition System
  • Analog Voltage and Digital Code Characteristic
  • A/D conversion algorithm
  • Optimal voltage range for A/D conversion
  • Scaling circuit
  • The HCS12 A/D Convertor
  • Signal pins related to A/D convertor
  • Registers Associated With A/D convertor
  • Procedures for performing A/D conversion

Lecture 21

  • The 9S12 Serial Peripheral Interface (SPI)
  • SPI Block User Guide

Lecture 22

  • Preparation for Final Lab Project
  • Simple Motor Control

Lecture 23

  • The 9S12 Pulse Accumulator
  • ECT_16B8C Block User Guide

Lecture 24

  • Survey of Microcontrollers

Laboratory Outline

The laboratory will be outlined as follows:

  • Become familiar with firmware/software (assembly and C) and hardware covered in this course. Given a program, enter, assemble, download, and run that program on an HCS12 microcontroller based evaluation board.
  • Write a program that employ D-Bug 12 subroutines
  • Write and run a “chaser light” assembly language program. Make minor revisions to the given program.
  • Using a multiplexing technique, display the student’s birthday on a quad 7-segment display using the format: mm dd and then the year in four digits.
  • Develop a simple alarm system making use of switches for modes, push buttons for windows, LEDs for status, and the speaker for sounding an alarm.
  • Using HSC12 timer Interrupts
  • Making use of A/D to develop a simple digital voltmeter.
  • Making use of PWM generation module
  • ‘C’ programming and the LCD display.
  • Project for remaining weeks. Tentative choices: motor control, Digital Thermometer, Infrared control of a device.


The primary textbook for this course is The HCS12/9S12, An Introduction to Hardware and Software Interfacing, by Han-Way Huang, Thomas/Delmar Learning, 2006. Additional text used for this course are: CPU 12 Reference Manual, MC9S12 V1.5 Core User Guide Version , AS12 Assembler Reference (as12d) , Wytec Dragon12 Plus User's Manual,and various application notes that comes with the Dragon12-Plus evaluation board.


DRAGON12-Plustm, the Freescale HCS12 / 9S12 microcontroller trainer


Homework is assigned for each unit to provide practical experience in applying the concepts presented during lecture. Periodic quizzes covering two or more units are given to insure complete understanding of the material. There are two major evaluations during the trimester, one at mid-term and another at the end of the trimester (final).

The Total Overall Grade is computed on the following basis:

Attendance/Attitude: 5%

Homework/Quizzes: 10%

Lab Experiment: 40%

Mid-Term Exam: 20%

Final Exam: 20%

In accordance with SIPI's grading policy the final letter grade is based on the following scale:

90 to 100 = A

80 to 89 = B

70 to 79 = C

60 to 69 = D

59 and Below = F

Students in this course are required to maintain a 2.0 GPA (C). Any student receiving the grade of D or F will have to repeat the course.


Evaluations are accomplished in three categories:

  1. Objective type: In this area, the student's recall ability is explored. The student will be required to respond with single answers such as True/False, Matching, and/or Multiple Choice statements.
  1. Subjective Type: In this area, the student’s critical thinking ability is explored. On written examinations, the studentwill be required to respond with an essay on procedures, functions, operations, or development of a single topic.

Written reports are graded on the student’scomprehension, originality, and accuracy.

3. Performance Type:

  1. Formal - The student will correctly complete a functional system from a schematic diagram, complete all measurements, and calculate all values for their comparability.

B.Informal – The student will be observed on daily performance in the areas of class participation, assignment completion, and attendance.

Attendance Policy

The formal attendance policy is defined on pages 32 and 33 of the 2001-2002 Student Handbook. There are five (5) allowable absences for both RENG 220 and RENG 220L. Any student exceeding this limit will be disenrolled according to the aforementioned procedures.

Course/Instructor Expectations

In order to obtain the highest possible grade, the student is required to attend classes regularly (classes meet MWF for a one-hour lecture and TTH for a one-and-a-half-hour lab), excel on all quizzes, exams, and homework assignments, and finish any given assignments on time including quizzes. No late homework is accepted without prior instructor approval.