Hardware Reference
In-Depth Information
Example 6.4
Write an assembly program to use the RTI to time-multiplex four seven-segment displays
using the circuit shown in Figure 4.18. Turn on one display at a time and light each display for
about 1 ms, then switch to the next display. Use display #0 to display #3. Use CodeWarrior and
a demo board programmed with a serial monitor to implement the circuit.
Solution: The algorithm in time-multiplexing four seven-segment displays is similar to that
described in Example 5.8 but uses a RTI to trigger the switch of display. There are 10 display
sequences.
1234
2345
. . .
0123
For each sequence, digits are indexed from 0 to 3. By repeating each sequence 100 times and turn-
ing on one digit for 1 ms, a sequence will last for 0.4 s. Within 0.4 s, there will be 400 RTIs. Let
base , dindex , and timeCnt represent the starting address of a sequence, index to digits within a
sequence, and the repetition count of a sequence, respectively. The following assembly program
performs the seven-segment display shifting:
include “c:\miniide\hcs12.inc”
org
$1000
base
ds.w
1
; base address of the current four-digit sequence
timeCnt
ds.w
1
; repetition count of the current sequence of four digits
dindex
ds.b
1
; digit index in a sequence (0, 1, 2, or 3)
org $1500
start lds #$1500 ; set up stack pointer
jsr SetClk8 ; set E-clock to 24 MHz
movw #Seg7Pat,base ; initialize the base address of a new sequence of digits
clr dindex ; the offset digit to be displayed from the base
movb #$FF,DDRB ; configure Port B for output
movb #$0F,DDRP ; configure Port P lower 4 pins for output
movw #400,timeCnt ; allow four digits to multiplex for 0.4 s
movb #$40,RTICTL ; set RTI to about 1 ms
bset CRGINT,RTIE ; enable RTI locally
cli ; enable interrupt globally
bra $ ; wait for interrupt to occur
; ********************************************************************************
SetClk8
movb
#$02,SYNR
; set SYNR to 2
movb
#$0,REFDV
; set REFDV to 0
movb
#$80,CLKSEL
; enable PLL, keep SYSCLK running in wait mode,
; keep RTI, COP, PLL, and core running in wait mode
movb
#$60,PLLCTL
; disable clock monitor, enable PLL, set automatic
; bandwidth control, disable RTI and COP in pseudo-
; stop
Search WWH ::




Custom Search