Introducing the 68HC12 - Computer Science and Engineering
Download
Report
Transcript Introducing the 68HC12 - Computer Science and Engineering
The miniDragon+ Board
and CodeWarrior
Lecture L2.1
miniDragon+
2 pushbutton
switches
Serial cable
A/D Pot
Reset button
Run/Load
switch
Power plug
7-segment
display
I/O headers
Table 1.1 Parallel Ports in the MC9SDP256
Port Name
DDR Name
Available
Pins
Port T
PTT
DDRT
7:0
Port S
PTS
DDRS
7:0
SCI(1:0)
Port M
PTM
DDRM
7:0
LCD
Port P
PTP
DDRP
7:0
Port H
PTH
DDRH
7:0
Port J
PTJ
DDRJ
7,6,1,0
Port AD0
PORTAD0
Input only
7:0
Port AD1
PORTAD1
Input only
7:0
Port A
PORTA
DDRA
7:0
Port B
PORTB
DDRB
7:0
Port E
PORTE
DDRE
7:0
Port K
PORTK
DDRK
7, 5:0
Port
miniDragon
use
7-Seg Display
Switches, pot
Keypad
Mode, XIRQ
Registers associated with parallel I/O ports
Port Data Register
7
6
5
4
3
2
1
0
Px7
Px6
Px5
Px4
Px3
Px2
Px1
Px0
PORTx
Port Data Direction Register
7
6
5
4
3
2
1
0
DDx7
DDx6
DDx5
DDx4
DDx3
DDx2
DDx1
DDx0
DDx[7:0]: Data Direction for Port x
0 – Input
1 – Output
DDRx
Turning on an LED
No current
no light
V2
V1 > V2
R
LED
light
Current
V2
V1 < V2
R
LED
A 7-segment display contains seven light emitting diodes (LEDs)
+5V
a
Common
Anode
f
b
g
e
c
d
a
b
c
d
e
f
g
a
b
c
d
e
f
g
Common
Cathode
The miniDragon+ board has a common-cathode 7segment display. This means that all the cathodes are
tied together and connected
to ground. The output
+5V
pins 6:0 of Port H are connected through a 1 kW
current-limiting
resistor to each of the anodes, g – a.
a
Common
In the common-cathode case, an output 1 will
turn on
a segment and an output 0 will turn it off. Anode
f
b
a
g
b
c
Port H: bit 6 5 4
g bf ec
a
e
c
d
d
e
f
g
3 2 1 0
dd c
e
fb ga
Common
Cathode
Programming in C
using CodeWarrior
LBE_DP256 is a stationery project that we have created that
contains the file main.asm which includes over 80 assembly
language routines to perform many I/O functions for the
MC9S12DP256 microcontroller on the miniDragon+ board.
Example 1a is the default main.c program
for a LBE_DP256 project.
Example 1a
// Example 1a: Turn on every other segment on 7-seg display
#include <hidef.h>
/* common defines and macros */
#include <mc9s12dp256.h>
/* derivative information */
#include "main_asm.h"
/* interface to the assembly module */
#pragma LINK_INFO DERIVATIVE "mc9s12dp256b"
void main(void) {
PLL_init();
// set system clock frequency to 24 MHz
DDRH = 0xff;
// Port H is output
PTH
= 0x55;
// switch on every other segment
for(;;) {}
/* wait forever */
}
Lab 1
Go through the CodeWarrior tutorial in Appendix A.
In this tutorial you will compile and run the C programs
for Examples 1 – 4.