Sei sulla pagina 1di 9

FACULTY OF ENGINEERING AND APPLIED SCIENCE

ENGR 3390U
Mechatronics

Mini-Project 1
LED Control
S. Nokleby, C. Chan, D. Fischer
1. Introduction
The purpose of this mini-project is to provide an opportunity to learn how to
program a microcontroller.
You will program a common commercial
microcontroller, the HC(S)12 made by Freescale (formerly Motorola). You will
use Metrowerks CodeWarrior CW12 to generate code that will be executed on
the microcontroller.
You are required to program the microcontroller to create three different number
sequences that will display on an inline LED display and a common-anode 7Segment LED display.
2. Hardware and Software
2.1 Hardware
The hardware available for the mini-project includes:
o Laptop Computer
o Freescale (formerly Motorola) HC(S)12 Microcontroller Board
(MC68EVB912DP256) with Microcontroller Chip MC9S12DP256BCPV
o USB Interface and Cable
o Custom Built LED Panel
Figure 1 shows the HC(S)12, the USB interface, and the custom built LED panel
mounted on the mechatronics board. Figure 2 shows a close-up view of the
LED panel.

HC(S)12

USB Interface

LED Panel

DIL1

DIL2

Figure 1: Mechatronics board with the Freescale HC(S)12 microcontroller board,


USB interface, and LED panel.

Inline LED Display

DIL1

DIL2

Common-Anode Hex Display

Figure 2: Custom built LED panel.

To Port B
(PB0 to PB7)

Inline Green LED Display

2.2 Software
The following software is installed on the laboratory computers and is available to
complete the mini-project:
o Metrowerks CodeWarrior CW12
2.3 Hardware Setup
The Freescale HC(S)12 microcontroller board (MC68EVB912DP256) has
multiple channels for digital I/O, Digital-to-Analog Converter (DAC) processing,
and Pulse Width Modulation (PWM) counter I/O. For more information about the
specification and the use of HC(S)12, please visit:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MC9S12DP256B&srch=1

As a quick reference to the data port locations, you can launch the CodeWarrior
IDE from Metrowerks CodeWarrior CW12 (see Figure 3).

Figure 3: Metrowerks CodeWarrior CW12 V3.1 CodeWarrior IDE.

From the Toolbar, click on Processor Expert. Then, drag your mouse cursor
and click on View | CPU Types Overview to launch the CPU preview window
(see Figure 4).

Figure 4: CPU preview window.


Choose the appropriate CPU type MC9S12DP256BCPV and click on it. This will
launch the pin layout diagram of the CPU (see Figure 5). Simply hover the
mouse cursor on the data port name, it will show you the description of the port
and its corresponding pin location highlighted in yellow (see Figure 6).
For this mini-project, we are interested in using the General Purpose I/O Port
AB to send out digital signals (PA0 to PA7 and PB0 to PB7 highlighted in yellow
in Figure 6) to control the LED Panel which consists of an inline green LED
display and a common-anode hex display. Therefore, the wire leads of the LED
panel should be connected to both PA and PB ports from channel 0 to 7 in
ascending order. A schematic of the LED panel is illustrated in Figure 7 (the
number next to each common-anode hex display indicates the corresponding PA
bit number). Please note that the (common) cathodes of the inline green LED
display are connected to common ground GND while the anodes of the commonanode hex display are connected to the TTL supply Vcc of the HC(S)12
microcontroller board.

Figure 5: CPU pin layout diagram.

Figure 6: General purpose I/O port AB.

PB7

PB6

PB5

PB4

PB3

PB2

PB1

PB0

Inline Green LED Display

Common-anode
Hex Display

6
7

Figure 7: Schematic diagram of LED panel.


You must make sure all DIL1 are in the ON (UP) positions, all DIL2 are in
the OFF (DOWN) positions.
2.4 Software Setup
The HC(S)12 microcontroller board can be programmed in ANSI C using
Metrowerks CodeWarrior, an IDE software that is provided by Freescale for the
programming of the HC(S)12 microcontroller board. You will also need to have a
USB driver that would allow the IDE to download and execute the code you
produce into the Freescale board
3. Pre-Project Requirements

3.1 Pre-Project Responsibilities


You need to create a table listing the bit patterns required to be written to port A
to display all digits from 0 to 9. Also, this table should include the pattern needed
to be written to port A, so that all LEDs in the common-anode hex display module
are turned on (for testing purposes). You must generate a flow chart for LED
control algorithm (see Section 4.1) and write the code in C. You must test your
software within the CodeWarrior Simulator environment. Please note that, to test
your software in the simulator, you will need to use the 7-Segment LED module
in the Visualization Tool, and the LEDs in this module are wired differently to bits
0, 1, 2, 3, 7, of a memory location (e.g. port A) than the hardware 7-Segment
LED module on the controller board. Therefore you will need to experiment to
find out which bit turns on which segment in the simulated module (there are 7
LED segments plus a period LED, therefore in at most 8 tries you should have
the bit to LED mapping done), and, of course, the table that works within the
simulator will be different from the table that works with the actual hardware
module.
3.2 Pre-Project Deliverables
You must submit a short document that includes:

7-Segment display table


Flow chart of your algorithm
Algorithm C code
Screen shot of the Beans CodeWarrior window showing the beans
your application uses
Screen shot of the Visualization Tool window showing the
Instruments you are using
Screen shot of the properties of each Instrument
Simulation results and discussion.

You must complete all pre-project requirements before your scheduled lab
time and submit a copy of your pre-project deliverables (one copy per
group) to the TA at the START of your first lab session for this mini-project.
4. Mini-Project Requirements
4.1 Counter
You are required to program the HC(S)12 microcontroller to generate LED
sequences:

1) Start displaying value 9 and count down in steps of 3 (i.e. display: 9, 6, 3,


0)
2) Start displaying value 0 and count up in steps of 2 up to and including
value 8
3) Start displaying value 0 and count up in steps of 1 up to and including
value 9
4) Turn on all LED segments and individual LEDs.
5) Repeat starting with the first sequence
The counter must display on both the inline green LED display and the commonanode hex display. For the inline green LED display, you must output the results
of your counter in binary. If number 10 is to be displayed, all green LEDs must
turn on. The common-anode hex display should display the correct decimal
number, or turn on all LEDs if number 10 is to be displayed.
Your code must contain two procedures (which you must write) to be used to
control the in-line LEDs and the 7-segment LEDs. Each procedure must accept
a byte type parameter, and return no parameters. Each procedure will be
responsible for displaying on the LEDs the value passed to it by the calling
statement.
You must demonstrate the functionality of your three counters to the TA
before the end of your scheduled lab time allocated for this project.
Sharing of files between groups is NOT permitted and will result in
Academic Misconduct charges.

4.2 Report Requirements


You must submit one report per group that documents your design. The report
must be in the form of a technical report and should include:

title page
group members signing sheet
table of contents
executive summary
project definition
requirements section (state what you must do)
engineering specification section (state the table values appropriate for
controlling the 7-segment display modules)
concept generation section: flowcharts, pseudo-code, program files
(include only the program files in an appendix)
test plan section (to test, you may need a delay procedure so you can see
the various patterns, also you may wish to have a test sequence to make

sure that you can display all digits from 0-9 and not only the once in the
sequnce . State all this in the test section)
discussion and analysis of your prototype demonstration
conclusions
provide as appropriate: freehand sketches, analytical calculations,
references, etc.

4. 4 Submission Requirements
Your submission must comply with the following:

Maximum of 20 pages of project text (1.5 spaced, font Time New Roman,
size 12) excluding appendices and drawings (the number of drawings is
not limited in any way) and a CD/DVD with electronic copies of all files.
Use appropriate project table of contents and formatting. Please state
appropriately the references used (use the following link for guidance:
http://www.ecf.toronto.edu/~writing/handbook.html).

5. Marking Scheme
The overall mini-project will be marked for: completeness, technical merits,
clarity, quality of engineering analysis, feasibility of the proposed design concept,
and the functionality of the prototype.
The report will account for 40% of the mini-project mark. The pre-project
requirements will account for 30% of the mini-project mark. The prototype
demonstration will account for 30% of the mini-project mark.

Potrebbero piacerti anche