Super Mario Bros on the Motorola 68HC12

advertisement
Tufts University
EECS Department
EE14 Lab
Fall 2002
Super Mario Bros on the Motorola 68HC12
1
Introduction
The practical objective of this lab is to further advance your knowledge of the 68HC12
microprocessor by first gaining familiarity with the timing registers, and second applying that knowledge to
write an assembly program that will play a song through a little PC speaker attached to the 68HC12
evaluation board. This will be accomplished by completing a number of Pre-Laboratory exercises described
in Part 2, below. The Motorola CPU12 Reference Manual (located at each lab station or online1) is an
excellent source of information on the internal registers of the 68HC12. It is necessary to read at least
Section 12: Standard Timer Module.
The code for the Super Mario Bros theme song is attached to this exercise. Either use this song in
your program or create your own song based on the notes and lengths used in the Super Mario Bros code.
This laboratory exercise assumes prior knowledge of basic programming, but the use of subroutines
and loops will be introduced. This exercise can also be done with interrupts, but it is not necessary. The
following is the code for interrupt vector definitions stored in RAM on the 68HC12 evaluation board:
BDLC
ATD
SCI
SPI
Pulse_Edge
Pulse_Overflow
Timer_Overflow
Timer_Ch7
Timer_Ch6
Timer_Ch5
Timer_Ch4
Timer_Ch3
Timer_Ch2
Timer_Ch1
Timer_Ch0
Real_Time
IRQ
XIRQ
intSWI
COP_fail
COP_clk_fail
Reset
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
$0B10
$0B12
$0B16
$0B18
$0B1A
$0B1C
$0B1E
$0B20
$0B22
$0B24
$0B26
$0B28
$0B2A
$0B2C
$0B2E
$0B30
$0B32
$0B3F
$0B36
$0B3A
$0B3C
$0B3E
The interrupt vectors that could be used to complete this lab are Timer Overflow, Timer Channel 0-7
and the Real time interrupt.
http://www.motorola.com.cn/semiconductors/mcudsp/forms/databook/hc12/M68HC12B.PDF
is the online manual for the board.
2
Pre-Laboratory Exercises
EE14 Microprocessor Architecture and Applications
Prof. Karen Panetta
Tufts University
EECS Department
EE14 Lab
Fall 2002
Read Section 12: ‘Standard Timer Module’ from the 68HC12 manual. Answer the following questions to
hand in with your laboratory report.
1.
2.
3.
3
Briefly define the function of the following registers: TMSK1, TMSK2, TCTL2, TIOS, Timer
Input/Output Compare registers, TSCR, TCNT, and TFLG1.
How many bytes of memory does the Super Mario Bros theme song use? What is the maximum
number of bytes that your song can use?
How is the frequency of a specific note translated into assembly language for the Motorola
68HC12?
Lab Exercise
There are a few subroutines that your program could have:
Initialize:
Initialize the counters, set the prescale factor, and clear all flags.
GetNote:
Get the notes one by one and increment the song array.
PlayNote:
This subroutine should play each note, monitor the length of the note, and call the
subroutine that will get the next note. It also needs to control the beat of the song. Each
note (including rest notes) needs to be followed by silence of a reasonable length chosen
by the programmer. This length will have an affect on the tempo of the song. A couple
suggestions for a reasonable length of the “beat” are 1/32 nd or 1/64th of a second. These
lengths are based on the whole note being equivalent to one second.
In the loops that play and test the note it is important to optimize your code for efficiency.
Having optimized code does not necessarily mean fewer lines of code, but rather less
cycles to complete a task. This is why it is important to know the number of cycles for
each instruction.
In the laboratory, you will be given a PC speaker to test if your song plays. One of the two wires
of the PC speaker should be connected to Vcc pin-out and the other can be connected to a port of your
choice, such as the output compare 2 port which corresponds to bit 2 of port B. When you successfully run
your program, play your song for the TA.
If you choose to use the Super Mario Bros theme in place of your own song, it must be loaded into
the EEPROM. The start of the user code/data section of the EEPROM is at $0D00. If you have trouble
loading the data into the EEPROM you can load half of the song into the RAM ($0800-$0900) and then use
the “move” command in the terminal screen, such as move 0800 09ff 0d00. If you composed your
own song and it is short enough you can just load it into RAM. However if both your code and the song are
more than 512 bytes then you will have to store the song in the EEPROM.
4
Questions
1.
2.
3.
4.
5
Why is it important to optimize your code for efficiency? Explain.
What flags in what registers did you set and clear in your program? Why?
Why is the prescale factor especially important for this program? How does it affect the sound?
How did you make sure that the program ended when the song was over?
What to Hand In
The student is required to hand in a formal, typed write-up for this lab. The report should include a cover
page, a typed version of the Pre-Laboratory exercises in Part 2 as well as a printout of the .lst and .asm files
from Part 3 with a TA’s signature, problems you encountered, and answers to questions from Part 4 of the
lab. Your reports will be graded based on content, organization, neatness, and tardiness.
EE14 Microprocessor Architecture and Applications
Prof. Karen Panetta
Tufts University
EECS Department
*********************************************************************
*|][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]][][|*
*|
|*
*|
*|
SUPER MARIOS BROS: Playing a song on 68HC12
|*
*|
|*
*|
|*
*|][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]][][|*
*********************************************************************
*
*
For long songs, load the data into the EEPROM
*
*
by storing it in a separate file, data.asm, org'ed
*
* at $0800, then in HyperTerminal, type "move 0800 0XXX 0d00"
*
* where 0XXX is the last address of your data.
*
*
*********************************************************************
EE14 Lab
Fall 2002
|*
*
*
*********************************************************************
* Port Definitions
*
*********************************************************************
TIOS equ
$80
; Timer Input Capture/Output Compare Select
TCNT equ
$84
; Timer Counter
TSCR equ
$86
; Timer System Control
TCTL2 equ
$89
; Timer Control 2
TMSK1 equ
$8C
; Timer Interrupt Mask 1
TMSK2 equ
$8D
; Timer Interrupt Mask 2
TFLG1 equ
$8E
; Timer Interrupt Flag 1
TC0
equ
$90
; TIC/TOC 0
TC2
equ
$94
; TIC/TOC 2
*********************************************************************
* Notes Lengths
*
*********************************************************************
nWHOLE
equ
128
;whole note is 1 second
nHALF
equ
64
n4TH
equ
32
n8TH
equ
16
n16TH
equ
8
n32ND
equ
4
n64TH
equ
2
n128TH equ
1
nSTEP
equ
n64TH
THEEND
equ
$FFFF
*********************************************************************
* Notes Frequencies
*
*********************************************************************
REST equ
0
; No sound
C0
equ
31312 ; Freq is in Hz
65.40639133
Db0
equ
29555 ; Freq is in Hz
69.29565774
D0
equ
27896 ; Freq is in Hz
73.41619198
Eb0
equ
26330 ; Freq is in Hz
77.78174593
EE14 Microprocessor Architecture and Applications
Prof. Karen Panetta
Tufts University
EECS Department
E0
F0
Gb0
G0
Ab0
A0
Bb0
B0
C
Db
D
Eb
E
F
Gb
G
Ab
A
Bb
B
C1
Db1
D1
Eb1
E1
F1
Gb1
G1
Ab1
A1
Bb1
B1
C2
Db2
D2
Eb2
E2
F2
Gb2
G2
Ab2
A2
Bb2
B2
C3
Db3
D3
Eb3
E3
F3
Gb3
G3
Ab3
A3
Bb3
B3
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
24852
23457
22141
20898
19725
18618
17573
16587
15656
14777
13948
13165
12426
11729
11070
10449
9863
9309
8787
8293
7828
7389
6974
6583
6213
5864
5535
5225
4931
4655
4393
4147
3914
3694
3487
3291
3107
2932
2768
2612
2466
2327
2197
2073
1957
1847
1743
1646
1553
1466
1384
1306
1233
1164
1098
1037
EE14 Lab
Fall 2002
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
82.40688923
87.30705786
92.49860568
97.998859
103.8261744
110
116.5409404
123.4708253
130.8127827
138.5913155
146.832384
155.5634919
164.8137785
174.6141157
184.9972114
195.997718
207.6523488
220
233.0818808
246.9416506
261.6255653 !!!!MIDDLE C!!!!
277.182631
293.6647679
311.1269837
329.6275569
349.2282314
369.9944227
391.995436
415.3046976
440
466.1637615
493.8833013
523.2511306
554.365262
587.3295358
622.2539674
659.2551138
698.4564629
739.9888454
783.990872
830.6093952
880
932.327523
987.7666025
1046.502261
1108.730524
1174.659072
1244.507935
1318.510228
1396.912926
1479.977691
1567.981744
1661.21879
1760
1864.655046
1975.533205
EE14 Microprocessor Architecture and Applications
Prof. Karen Panetta
Tufts University
EECS Department
C4
Db4
D4
Eb4
E4
F4
Gb4
G4
Ab4
A4
Bb4
B4
C5
Db5
D5
Eb5
E5
F5
Gb5
G5
Ab5
A5
Bb5
B5
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
equ
978
924
872
823
777
733
692
653
616
582
549
518
489
462
436
411
388
367
346
327
308
291
275
259
EE14 Lab
Fall 2002
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
; Freq is in Hz
2093.004522
2217.461048
2349.318143
2489.01587
2637.020455
2793.825851
2959.955382
3135.963488
3322.437581
3520
3729.310092
3951.06641
4186.009045
4434.922096
4698.636287
4978.03174
5274.040911
5587.651703
5919.910763
6271.926976
6644.875161
7040
7458.620184
7902.13282
;!!!!!!!!!!! to find note freq its 2048000/freq = number of counts
;INSERT PROGRAM HERE
;1. initialize Timer Registers
;2. main program should play a note, then get the next note,
; and repeat
;3. to play a note:
;
-enable the timer
;
-set the prescalar (if you need to)
;
-tell the HC12 you want to use Bit x of PORTT for output compare
;
-tell the HC12 what you want to do when the compare is true (hint: Table 12-1)
;
-tell the HC12 what time you want the event to occur
*********************************************************************
* Data Storage - Note and Length for Super Mario Bros Tune
*
*********************************************************************
org
$0800
; Place Data for Song in EEPROM
MARIO
fdb
fdb
fdb
fdb
fdb
fdb
fdb
fdb
E2,n8TH
REST,n128TH
E2,n8TH
REST,n8TH
E2,n8TH
REST,n8TH
C2,n8TH
E2,n4TH
EE14 Microprocessor Architecture and Applications
Prof. Karen Panetta
Tufts University
EECS Department
fdb
fdb
fdb
fdb
EE14 Lab
Fall 2002
G2,n4TH
REST,n4TH
G,n4TH
THEEND
EE14 Microprocessor Architecture and Applications
Prof. Karen Panetta
Download