Hardware Reference
In-Depth Information
Example 7.9
Suppose that the pins PP3..PP0 are used to drive the four transistors as shown in
Figure 7.41. Write a subroutine to rotate the stepper motor clockwise one cycle using the
half-step sequence.
Solution: The assembly language subroutine is as follows:
#include
“c:\miniIDE\hcs12.inc”
step1
equ
$08
step2
equ
$0C
step3
equ
$04
step4
equ
$06
step5
equ
$02
step6
equ
$03
step7
equ
$01
step8
equ
$09
HStep
movb
#$FF,DDRP
; configure PTP for output
movb
#step1,PTP
bsr
delay10ms
movb
#step2,PTP
bsr
delay10ms
movb
#step3,PTP
bsr
delay10ms
movb
#step4,PTP
bsr
delay10ms
movb
#step5,PTP
bsr
delay10ms
movb
#step6,PTP
bsr
delay10ms
movb
#step7,PTP
bsr
delay10ms
movb
#step8,PTP
bsr
delay10ms
rts
; the following subroutine waits for 10 ms
delay10ms movb
#$90,TSCR1
; enable TCNT and fast flags clear
movb
#$06,TSCR2
; configure the prescale factor to 64
bset
TIOS,IOS0
; enable OC0
ldd
TCNT
addd
#3750
; start an output compare operation
std
TC0
; with 10-ms time delay
brclr
TFLG1,$01,*
rts
end
 
Search WWH ::




Custom Search