TuftsUniversityEE14 Lab
EECS DepartmentFall 2002
Super Mario Broson the Motorola 68HC12
1Introduction
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 thecode for interrupt vector definitions stored in RAM on the 68HC12 evaluation board:
BDLCequ$0B10
ATDequ$0B12
SCIequ$0B16
SPIequ$0B18
Pulse_Edgeequ$0B1A
Pulse_Overflowequ$0B1C
Timer_Overflowequ$0B1E
Timer_Ch7equ$0B20
Timer_Ch6equ$0B22
Timer_Ch5equ$0B24
Timer_Ch4equ$0B26
Timer_Ch3equ$0B28
Timer_Ch2equ$0B2A
Timer_Ch1equ$0B2C
Timer_Ch0equ$0B2E
Real_Timeequ$0B30
IRQequ$0B32
XIRQequ$0B3F
intSWIequ$0B36
COP_failequ$0B3A
COP_clk_failequ$0B3C
Resetequ$0B3E
The interrupt vectors that could be used to complete this lab are Timer Overflow, Timer Channel 0-7 and the Real time interrupt.
is the online manual for the board.
2Pre-Laboratory Exercises
Read Section 12: ‘Standard Timer Module’ from the 68HC12 manual. Answer the following questions to hand in with your laboratory report.
- 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?
3Lab 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/32nd 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.
4Questions
- 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?
5What 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.
*********************************************************************
*|][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]][][|*
*| |*
*| |*
*| 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. *
* *
*********************************************************************
*********************************************************************
* Port Definitions *
*********************************************************************
TIOSequ$80; Timer Input Capture/Output Compare Select
TCNTequ$84; Timer Counter
TSCRequ$86; Timer System Control
TCTL2equ$89; Timer Control 2
TMSK1equ$8C; Timer Interrupt Mask 1
TMSK2equ$8D; Timer Interrupt Mask 2
TFLG1equ$8E; Timer Interrupt Flag 1
TC0equ$90; TIC/TOC 0
TC2equ$94; TIC/TOC 2
*********************************************************************
* Notes Lengths *
*********************************************************************
nWHOLEequ128;whole note is 1 second
nHALFequ64
n4THequ32
n8THequ16
n16THequ8
n32NDequ4
n64THequ2
n128THequ1
nSTEPequn64TH
THEENDequ$FFFF
*********************************************************************
* Notes Frequencies *
*********************************************************************
RESTequ0; No sound
C0equ31312; Freq is in Hz65.40639133
Db0equ29555; Freq is in Hz69.29565774
D0equ27896; Freq is in Hz73.41619198
Eb0equ26330; Freq is in Hz77.78174593
E0equ24852; Freq is in Hz82.40688923
F0equ23457; Freq is in Hz87.30705786
Gb0equ22141; Freq is in Hz92.49860568
G0equ20898; Freq is in Hz97.998859
Ab0equ19725; Freq is in Hz103.8261744
A0equ18618; Freq is in Hz110
Bb0equ17573; Freq is in Hz116.5409404
B0equ16587; Freq is in Hz123.4708253
Cequ15656; Freq is in Hz130.8127827
Dbequ14777; Freq is in Hz138.5913155
Dequ13948; Freq is in Hz146.832384
Ebequ13165; Freq is in Hz155.5634919
Eequ12426; Freq is in Hz164.8137785
Fequ11729; Freq is in Hz174.6141157
Gbequ11070; Freq is in Hz184.9972114
Gequ10449; Freq is in Hz195.997718
Abequ9863; Freq is in Hz207.6523488
Aequ9309; Freq is in Hz220
Bbequ8787; Freq is in Hz233.0818808
Bequ8293; Freq is in Hz246.9416506
C1equ7828; Freq is in Hz261.6255653 !!!!MIDDLE C!!!!
Db1equ7389; Freq is in Hz277.182631
D1equ6974; Freq is in Hz293.6647679
Eb1equ6583; Freq is in Hz311.1269837
E1equ6213; Freq is in Hz329.6275569
F1equ5864; Freq is in Hz349.2282314
Gb1equ5535; Freq is in Hz369.9944227
G1equ5225; Freq is in Hz391.995436
Ab1equ4931; Freq is in Hz415.3046976
A1equ4655; Freq is in Hz440
Bb1equ4393; Freq is in Hz466.1637615
B1equ4147; Freq is in Hz493.8833013
C2equ3914; Freq is in Hz523.2511306
Db2equ3694; Freq is in Hz554.365262
D2equ3487; Freq is in Hz587.3295358
Eb2equ3291; Freq is in Hz622.2539674
E2equ3107; Freq is in Hz659.2551138
F2equ2932; Freq is in Hz698.4564629
Gb2equ2768; Freq is in Hz739.9888454
G2equ2612; Freq is in Hz783.990872
Ab2equ2466; Freq is in Hz830.6093952
A2equ2327; Freq is in Hz880
Bb2equ2197; Freq is in Hz932.327523
B2equ2073; Freq is in Hz987.7666025
C3equ1957; Freq is in Hz1046.502261
Db3equ1847; Freq is in Hz1108.730524
D3equ1743; Freq is in Hz1174.659072
Eb3equ1646; Freq is in Hz1244.507935
E3equ1553; Freq is in Hz1318.510228
F3equ1466; Freq is in Hz1396.912926
Gb3equ1384; Freq is in Hz1479.977691
G3equ1306; Freq is in Hz1567.981744
Ab3equ1233; Freq is in Hz1661.21879
A3equ1164; Freq is in Hz1760
Bb3equ1098; Freq is in Hz1864.655046
B3equ1037; Freq is in Hz1975.533205
C4equ978; Freq is in Hz2093.004522
Db4equ924; Freq is in Hz2217.461048
D4equ872; Freq is in Hz2349.318143
Eb4equ823; Freq is in Hz2489.01587
E4equ777; Freq is in Hz2637.020455
F4equ733; Freq is in Hz2793.825851
Gb4equ692; Freq is in Hz2959.955382
G4equ653; Freq is in Hz3135.963488
Ab4equ616; Freq is in Hz3322.437581
A4equ582; Freq is in Hz3520
Bb4equ549; Freq is in Hz3729.310092
B4equ518; Freq is in Hz3951.06641
C5equ489; Freq is in Hz4186.009045
Db5equ462; Freq is in Hz4434.922096
D5equ436; Freq is in Hz4698.636287
Eb5equ411; Freq is in Hz4978.03174
E5equ388; Freq is in Hz5274.040911
F5equ367; Freq is in Hz5587.651703
Gb5equ346; Freq is in Hz5919.910763
G5equ327; Freq is in Hz6271.926976
Ab5equ308; Freq is in Hz6644.875161
A5equ291; Freq is in Hz7040
Bb5equ275; Freq is in Hz7458.620184
B5equ259; Freq is in Hz7902.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
fdbE2,n8TH
fdbREST,n128TH
fdbE2,n8TH
fdbREST,n8TH
fdbE2,n8TH
fdbREST,n8TH
fdbC2,n8TH
fdbE2,n4TH
fdbG2,n4TH
fdbREST,n4TH
fdbG,n4TH
fdbTHEEND
EE14 Microprocessor Architecture and ApplicationsProf. Karen Panetta