
Serial Interface
M68HC12B Family Data Sheet, Rev. 9.1
212
Freescale Semiconductor
INCLUDE 'EQUATES.ASM' ;Equates for all registers
; User Variables
; Bit Equates
; ----------------------------------------------------------------------
; MAIN PROGRAM
; ----------------------------------------------------------------------
ORG
$7000
; 16K On-Board RAM, User code data area,
;
; start main program at $7000
MAIN:
BSR
INIT
; Subroutine to initialize SPI registers
BSR
TRANSMIT
; Subroutine to start transmission
FINISH:
BRA
FINIS
; Finished transmitting all DATA
; ----------------------------------------------------------------------
;* SUBROUTINE INIT:
; ----------------------------------------------------------------------
INIT:
BSET
PORTS,#$80
; SET SS Line High to prevent glitch
MOVB
#$E0,DDRS
; Configure PORT S input/ouput levels
; MOSI, SCK, SS* = ouput, MISO=Input
;
MOVB
#$07,SP0BR
; Select serial clock baud rate < 100 KHz
MOVB
#$12,SP0CR1
; Configure SPI(SP0CR1): No SPI interrupts,
; MSTR=1, CPOL=0, CPHA=0
;
MOVB
#$08,SP0CR2
; Config. PORTS output drivers to operate normally,
; and with active pull-up devices.
;
LDX
#DATA
; Use X register as pointer to first character
LDAA
LDAA
SP0SR
SP0DR
; 1st step to clear SPIF Flag, Read SP0SR
; 2nd step to clear SPIF Flag, Access SP0DR
BSET
SP0CR1,#$40
; Enable the SPI (SPE=1)
RTS
; Return from subroutine
; ----------------------------------------------------------------------
;* TRANSMIT SUBROUTINE
; ----------------------------------------------------------------------
TRANSMIT:
LDAA
1,X+
; Load Acc. with "NEW" character to send, Inc X
BEQ
DONE
; Detect if last character(0) has been transmitted
;
; If last char. branch to DONE, else
BCLR
PORTS,#$80
; Assert SS Line to start X-misssion.
STAA
SP0DR
; Load Data into Data Reg.,X-mit.
;
; it is also the 2nd step to clear SPIF flag.
FLAG:
BRCLR
SP0SR,#$80,FLAG
;Wait for flag.
BSET
PORTS,#$80
; Disassert SS Line.
BRA
TRANSMIT
; Continue sending characters, Branch to TRANSMIT.
DONE:
RTS
; Return from subroutine
; ----------------------------------------------------------------------
; TABLE OF DATA TO BE TRANSMITTED
; ----------------------------------------------------------------------
DATA:
DC.B
'Freescale'
DC.B
$0D,$0A
; Return (cr) ,Line Feed (LF)
EOT:
DC.B
$00
; Byte used to test end of data = EOT
END
; End of program