
3
* [File]
* DAC.ASM
* [Purpose]
* Use the DAC714 with the SPI interface and an additional port
RamStart
RomStart
StackStart
PORTA
PORTB
PORTD
DDRD
SPCR
SPSR
SPDR
SCSR
SCDR
REG_BASE
PORTA_OFS
PORTB_OFS
PORTD_OFS
DDRD_OFS
SPCD_OFS
SPSR_OFS
SCSR_OFS
CLK
* PORT B bit definitions
UPDATE
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
$C000
$8000
$E000
$1000
$1004
$1008
$1009
$1028
$1029
$102A
$102F
$102F
$1000
$00
$04
$08
$09
$28
$29
$2E
%00100000
EQU
%00000001
***********************************************************************
* [function]
* Start
* [purpose]
* Startup code
* [parameters]
* -
* [returns]
* -
org
Start
lds
jsr
jsr
jmp
RomStart
#StackStart
Init
Main
Cleanup
; init stack
***********************************************************************
* [function]
* Main
* [purpose]
* Main program
* [parameters]
* -
* [returns]
* -
Main
* point to registers
ldx
ldad
std
Loop
#REG_BASE
#0
DacData
bclr
PORTD_OFS,X CLK
; enable the serial receive reg
* Write Data using the SPI interface
ldaa
jsr
ldaa
jsr
DacData
WriteByte
DacData+1
WriteByte
* Update the DAC Latch
bclr
bset
PORTB_OFS,X UPDATE
PORTB_OFS,X UPDATE
* Deselect DAC714
bset
PORTD_OFS,X CLK
*do a ramp function
ldad
addd
std
bne
rts
#1
DacData
DacData
Loop
; hasta la vista
***********************************************************************
* [function]
* Init
* [purpose]
* all initializattion takes place here
* [parameters]
* -
* [returns]
* -
Init
* initialize SPI subsystem to work with DAC714
jsr
rts
InitSPI
***********************************************************************
* [function]
* InitSPI
* [purpose]
* Initialize SPI system to work with ADS121x sigma delta converters
* [parameters]
* -
* [returns]
* -
InitSPI
* 1. prepare port D with the appropriate bits to avoid glitches
* once they actually become an output
ldaa
staa
* 2. Initialize Port D direction bits
ldaa
#%00111000
*
||||||++
*
|||||+—
*
||||+——
*
|||+——
*
||+———
*
++———
staa
* 3. Initialize the SPI control register
ldaa
*
||||||++
*
||||||
*
|||||+—
*
|||||
*
||||+——
*
|||+——
*
||+———
*
|+———
*
+————
*
*
*
staa
rts
#$3f
PORTD
PD1, PD0 are used for async serial I/O (not SPI)
PD2 don’t care for master mode
PD3 enable master serial output
PD4 enable SCK output
PD5 /SS is general purpose I/O pin
don’t care
DDRD
#%01011100
bit rate select. Actual settings depends on the
ratio of the ADS121x- to the micros system clock
clock phase: data is setup on first edge
and latched on second edge
SCK idles High
68HC11 is Master, DAC714 is slave
push pull on port D output drivers
SPI system turned on
SPI interrupts disabled. This sample program
polls the serial ports, Change this if you
want interrupt driven serial I/O. In most
applications, there is no advantage to do so
SPCR
***********************************************************************
* [function]
* WriteByte
* [purpose]
* Writes a single byte to the SPI port, waits until transfer is
* finished
* [parameters]
* ACCA: byte to write
* [returns]
* -
WriteByte
staa
Write10 ldaa
SPSR
bpl
ldaa
rts
SPDR
; wait until transferred
Write10
SPDR
; write data to spi data reg
; read data from spi data reg
***********************************************************************
* [function]
* Cleanup
* [purpose]
* finishes program and jumps back to monitor
Cleanup
ldx
ldx
jmp
#$fffe
0,x
0,x
; point to reset vector
org
2
RamStart
DacData rmb
FIGURE 3. 68HC11 Program.