Hardware Reference
In-Depth Information
Example 4.16
Write a program to generate a two-tone siren that alternates between 250 Hz and 500 Hz
with each siren tone lasting half of a second.
Solution:
#include
“c:\miniide\hcs12.inc”
org
$1500
start
lds
#$1500
bset
DDRT,BIT5
; configure PT5 pin for output
forever
ldx
#250
; repeat 500 Hz waveform 250 times
tone1
bset
PTT,BIT5
; pull PT5 pin to high
ldy
#1
jsr
delayby1ms
bclr
PTT,BIT5
ldy
#1
jsr
delayby1ms
dbne
x,tone1
ldx
#125
; repeat 250 Hz waveform for 125 times
tone2
bset
PTT,BIT5
ldy
#2
jsr
delayby1ms
bclr
PTT,BIT5
ldy
#2
jsr
delayby1ms
dbne
x,tone2
bra
forever
#include
“c:\miniide\delay.asm”
;
org
$FFFE
; uncomment this line for CodeWarrior
;
dc.w
start
; uncomment this line for CodeWarrior
end
4.11.4 Interfacing with DIP Switches
A switch is probably the simplest input device we can find. To make input more efficient, a
set of eight switches organized as a dual inline package (DIP) is often used. A DIP package can
be connected to any input port with eight pins, such as Port A, Port B, and Port H, as shown in
Figure 4.19. When a switch is closed, the associated Port A pin input is 0. Otherwise, the associ-
ated Port A pin has a value of 1. Each Port A pin is pulled up to high via a 10-k
Ω
resistor when
the associated switch is open.
Example 4.17
Write a sequence of instructions to read the value from an eight-switch DIP connected to
Port A of the HCS12 into accumulator A.
Solution:
#include “c:\miniide\hcs12.inc”
movb
#$0,DDRA
; configure Port A for input
ldaa
PTA
 
Search WWH ::




Custom Search