PIC40 Universal Controller

sanatoriumdrumΗλεκτρονική - Συσκευές

25 Νοε 2013 (πριν από 3 χρόνια και 6 μήνες)

78 εμφανίσεις

Introduction

to

Embedded Systems Programming

Instructor’s Outline




With the

PIC40 Universal Controller

Application Development System



Boatner Consulting, LLC Eagle, ID

Introduction to

Embedded Systems Programming

Instructor’s O
utline


Draft 1 101024 [BB]

2

Course Objective


The objective of this course is to transition the student from th
e traditional PC
-
based C/CC++
programming environment to the world of hardware and embedded control. The course is
structured to allow students without strong hardware backgrounds to be success
ful in their first
exposure to the

custom hardware
environment
. Hardware internals are presented at an
introductory level only, so that students in all
EE, CE and CS
-
based curricula can

benefit from
this
program
.


Course Outline


In this course the student will:


1.

Become familiar with

and learn how to use an embedded

microcontroller tool suite:
the Integrated Development Environment (IDE), Compiler,

and
In
-
Circuit Debugger
(ICD).


2.

Learn how to use the API (Applications Programming Interface) functions as a
convenient
high
-
level tool
kit for
the

abstraction of
low
-
level

hardware functions.


3.

Progress from modifying an existing function,

through

w
riting, compiling and testing
new

function
s
, to designing a relatively complex mini
-
application.


4.

Explore the
most appropriate

data
and control
structures needed to
implement

the
design specification.


5.

Learn how to use interrupts, foreground an
d background processes, and understand
the
concept of a multi
-
tasking Real Time Operating System (RTOS).


6.

Be exposed to the concept of binary
Gray Codes, and how to control function
selection

and program flow using an 8
-
position rotary switch.


7.

Work extensively with A/D

(Analog
-
to
-
Digital) conversion,
used in a number of
different applications

throughout the lesson plan
.


8.

Configure

the hardware PWM (Pulse
Width Modulation) peripheral to
contro
l

a
multi
-
tone piezo buzzer.


9.

Become familiar with high
-
level control of
the I2C (Inter
-
Integrated Circuit) bus, and
access a number of peripherals on the bus: RTC (real
-
time clock), temperature
sensor, and EEPROM.


10.

Understand

how the 4x3

switch
-
matrix key
pad

is laid out
,
the trade
-
offs between
different
key scanning techniques, and

how to handle key
bounce.

Introduction to

Embedded Systems Programming

Instructor’s O
utline


Draft 1 101024 [BB]

3


11.

E
xperience
the complexities presented by

even the simplest of user interface
functions
-

setting date and time.


12.

Learn how to use alte
rnative dynamic
menu structures with a combination of
potentiometer and keypad controlled configuration and user selection.


13.

Write a set of functions for a simple note pad application using potentiometer A/D,
keypad, piezo buzzer and
a
detailed
understanding

of the LCD di
splay module
’s
memory mapping
.


14.

Learn

how to toggle between
functions
“stacked”

on a
n

8
-
position switch position, as
an approach to unlimited applications flexibility
.


15.

Learn to
design an interface that can
i
ntegrate

fast and slow
hardware
devices
, using
a

fluidic

bar
-
graph application

as an example
.


Summary of
the

Lessons


In order to aid the instructor, t
he course is structured around a framework of pre
-
defined function
names so that when examining multiple program listings, the code segments
are
easily

identified.
Many of the functions are standardized internally to further streamline the instructor’s efforts.


The course is
also
organized so that the instructor can view and evaluate all completed
and on
-
going development
work literally with the turn of
a knob. The PIC40 Universal Controller has
an 8
-
position switch, with each switch position representing one
,

or an associated grouping
, of
work assignments. Here is a
n outline of completed course work
based on the switch position
s
:


1.

The first lesson requ
ests the student to compile and run the
“Hello World!”

program
as a
starting point for the course. After successfully downloading and integrating all the
working tools,

including
compiler,
the In
-
Circuit D
ebugger,

Integrated Development
Environment, etc.,

compiling and running the program is a milestone. The stud
ent is then
asked to write
his/her own function that automatically centers text on the display.


2.

The name of the student or team, along with other information, is displayed, allowing the
instruc
tor to identify and evaluate the

student or team’s work by PIC40 unit
.
This d
isplay
illustrates the student’s

choice, initialization and utilization of a complex data structure
.


3.

The A/D value of the potentiometer is displayed. The
pot’s

value is quantiz
ed and used
to control the PWM (Pulse Width Modulation)
hardware
peripheral,
verified by
outputting distinct tones to the piezo buzzer.


4.

A test sequence for writing data to and reading from the external EEPROM is executed.
The external EEPROM is accessed
over the I2C (Inter
-
Integrated Circuit) bus.

Introduction to

Embedded Systems Programming

Instructor’s O
utline


Draft 1 101024 [BB]

4


5.

Utilization of t
he 4x3 switch matrix keypad
access functions is demonstrated.

Input
keystrokes from the keypad are written to the display and also used as parameters passed
to the buzzer function to produce
pr
e
-
defined responses
.


6.

Date and time are displayed on one line, and temperature is displayed on a second line.
Both the real
-
time clock (RTC) and the temperature module are accessed externally
through the I2C bus. Through the keypad the user is able to se
t the date and time. The
student is asked to enhance the set_dt( ) function to make it more user friendly.


7.

The concept of dynamic menus is
illustrated. The user
enter
s

a selection range from 1

to

255

and the potentiometer sweeps that range of values
.
T
his demonstrates how flexible
menu structures can be accommodated using the potentiometer knob.


8.

The last selection demonstrates how tasks can be “stacked” on one switch
position. The
functions are toggled

using the <*> key. The two tasks that share this

selection are a
note_pad( ) function, which allows the user to enter and save text, and a function that
uses potentiometer analog input to a generate a
smooth,
sweeping bar graph, similar to
those often seen in audio applications.



Student Prerequisites


The student should have a

solid working knowledge of C programming and a willingness to
learn about hardware systems at an introductory level. At this stage the emphasis is on the
ability to identify and utilize the proper data and control structures, r
ather than a requirement for
previous exposure to hardware design concepts. Use of the API library keeps the focus at a
fairly high level, and most of the hardware discussions are introduced simply to direct the
application design process.


This course do
es not detail the use of the MPLAB IDE /MPLAB ICD2 debugging environment


how to set breakpoints, single
-
step code, observe the state of var
iables, EEPROM, etc. T
his
information is important for the success of t
his course. The instructor may

consider al
lowing at
least one lab session for downloading, configuring and familiarizing the students with the tools
of the trade, prior to introducing the materials in this course. However, the course itself is an
excellent vehicle to teach the
many debugging tech
niques available through the MPLAB tools.


Materials Needed for
the
Course


1.

PIC40 Universal Controller (Student Edition)

2.

MicroChip MPLAB IDE (download free from
www.microchip.com/xxx
)

3.

MicroChip MPLAB C18 Compil
er Student Edition (download free from MicroChip)

4.

MicroChip MPLAB C18 Compiler Reference Manual (download free from MicroChip)

5.

MicroChip PICkit 2

In
-
Circuit Debugger (Cost
approx
$30
)