Hardware Reference
In-Depth Information
Solution: The values (bit 11 to bit 0 in Figure 10.18) corresponding to 1.5 V, 3.0 V, and 4.5 V are
1229 (0x4CD), 2458 (0x99A), and 3686 (0xE66), respectively.
The assembly program that can generate the specified waveform is as follows:
#include “c:\miniide\hcs12.inc”
org
$1500
lds
#$1500
bset
DDRK,BIT7
; configure PK0 pin for output
jsr
openSPI
forever ldd
#$34CD
jsr
sendMCP4922
; output 1.5 V from OUTA pin
ldy
#1
; wait for 1 ms
jsr
delayby1ms
;
ldd
#$39AA
jsr
sendMCP4922
; output 3.0 V from OUTA pin
ldy
#1
jsr
delayby1ms
ldd
#$3E66
jsr
sendMCP4922
; output 4.5 V from OUTA pin
ldy #1
jsr delayby1ms
bra forever
; ********************************************************************************
; The following subroutine sends out the value to be converted by MCP4922.
; The value to be sent is passed in double accumulator D.
; ********************************************************************************
sendMCP4922
bclr
PTK,BIT7
jsr
putcSPI0
tfr
B,A
jsr
putcSPI0
bset
PTK,BIT7
rts
; ********************************************************************************
; The following subroutine enables SPI to shift data on the rising edge of SCK and
; force SCK to be idle low, and shift data at 6 MHz for the 24-MHz E-clock.
; ********************************************************************************
openSPI
movb
#$10,SPI0BR
; set SPI 0 baud rate to 6 MHz
movb
#$50,SPI0CR1
; disable interrupt, enable SPI, SCK idle low,
; data latched on the rising edge, msb first
movb
#$02,SPI0CR2
; disable bidirectional mode, stop SPI in wait mode
movb
#0,WOMS
; enable Port S pull-up (push-pull)
rts
#include “c:\miniide\delay.asm”
#include “c:\miniide\spi0util.asm”
end
The C language version of the program to be compiled by CodeWarrior for generating the
specified waveform is as follows:
#include “c:\cwHCS12\include\hcs12.h”
#include “c:\cwHCS12\include\delay.h”
// include delay.c in the project
Search WWH ::




Custom Search