📄 main.asm
字号:
*************************************
; file name: main.asm
; Originator: jzming
; tianhuang dsp development group
; Description: ASM file for SPI Synchronize serial communicate demo
; Date: 28/5/2003
*************************************************************************************
;set include file
;----------------------------------------------------------------------------
.include "x24x.h"
.ref sys_int
.global _c_int0
;----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Global variables space reservation
;-----------------------------------------------------------------------------
r_char_h .usect ".blk1",1
r_char_l .usect ".blk1",1
DATA .usect ".blk1",20
aux .usect ".blk1",1
;-----------------------------------------------------------------------------
; M A I N C O D E - starts here
;-----------------------------------------------------------------------------
.text
;-----------------------------------------------------------------------------
_c_int0:
call sys_int
CALL _InitSPI
Loop:
CALL W_enable
call W_start
call W_disable
CALL R_start
Loop1:
KICK_DOG
B Loop1
;-----------------------------------------------------------------------------
; M A I N C O D E - ends here
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; S u b r o u t i n e s
;-----------------------------------------------------------------------------
_InitSPI:
;-----------------------------------------------------------------------------
LDP #0E0h
SPLK #0087h, SPICCR ; SPI Configuration Control Register
; clk polarity low, 8 bits character length
; SPI software reset
SPLK #000Ch, SPICTL ; SPI Operation Control Register
; disable receive error interrupt, disable SPI interrupt
; disable transmitter, normal clocking, SPI master
SPLK #0000h, SPIPRI ; SPI interrupt to high pwiority Register
SPLK #007Fh, SPIBRR ; SPI Baud Register
; SPI Baud Register, 500kBaud
; with 10 MHz SYSCLK
SPLK #0000H, SPISTS ; SPI states Register
SPLK #000EH ,SPICTL ; SPI Operation Control Register
; enable transmitter
SPLK #0052h, SPIPC1 ; SPI Port Control Register 1
; SPISTE configured as output pin
; SPICLK pin contains SPI clock
SPLK #0022H ,SPIPC2 ; SPI Port Control Register 2
; SPISIMO and SPISOMI contains SPI data
SPLK #0007H, SPICCR ; wake-up SPI from reset
LDP #DATA ; release SWRST,clock polarity 0,8 bits
LAR AR2,#DATA
RET
;-----------------------------------------------------------------------------
_ReadSPIbuf:
;-----------------------------------------------------------------------------
Wait:
KICK_DOG
LDP #0E0h
BIT SPISTS, BIT6 ; test SPI INT FLAG
BCND Wait,NTC ; wait to finish transmitting/receiving data
;
LACL SPIBUF ; load ACCL with received character
AND #00ffh ; mask unsignificant bits in ACC
SACL *+,AR2
RET
;-----------------------------------------------------------------------------
W_enable:
;------------------STARRT WRITE ENABLE----------------------------------------
LDP #0E0h
RESBIT SPIPC1, RSTB6 ;select the cs
LDP #0E0h
SPLK #04h, SPIDAT ;write start bit "1" and operation code
CALL _ReadSPIbuf
CALL _Delay
LDP #0E0h
SPLK #0C0H,SPIDAT ;write address word
CALL _ReadSPIbuf
LDP #0E0h
SETBIT SPIPC1, SETB6
CALL _Delay
RET
;--------------------END WRITE ENABLE-----------------------------------------
;--------------------START WRITE----------------------------------------------
W_start:
LDP #0E0h
RESBIT SPIPC1, RSTB6
SPLK #05h, SPIDAT ;write start bit "1" and operation code
CALL _ReadSPIbuf
CALL _Delay
LDP #0E0h
SPLK #4fH,SPIDAT ;write address word
CALL _ReadSPIbuf
CALL _Delay
LDP #0E0h
SPLK #44H,SPIDAT ;write the high "8" bit data
CALL _ReadSPIbuf
CALL _Delay
LDP #0E0h
SPLK #0AAH,SPIDAT ;write the low "8" bit data
CALL _ReadSPIbuf
LDP #0E0h
SETBIT SPIPC1, SETB6 ;CS high
CALL _Delay
RESBIT SPIPC1, RSTB6
WAIT2:
; KICK_DOG
RPT #100
CALL _Delay
LDP #0E0h
BIT SPIPC2,BIT3 ;wait if write is busy
BCND WAIT2,NTC
; CALL _Delay
RET
;---------------------END WRITE-----------------------------------------
;---------------------START WRITE DISABLE-------------------------------
W_disable:
LDP #0E0h
RESBIT SPIPC1, RSTB6
SPLK #04h, SPIDAT ;write start bit "1" and operation code
CALL _ReadSPIbuf
CALL _Delay
LDP #0E0h
SPLK #00H,SPIDAT ;write address word
CALL _ReadSPIbuf
LDP #0E0h
SETBIT SPIPC1, SETB6 ;CS high
CALL _Delay
RET
;----------------------END WRITE DISABLE--------------------------------
;----------------------START READ---------------------------------------
R_start:
LDP #0E0h
RESBIT SPIPC1, RSTB6
LDP #0E0h
SPLK #06H, SPIDAT ;write start bit "1" and operation code
CALL _ReadSPIbuf
CALL _Delay
LDP #0E0h
SPLK #4fH,SPIDAT ;write address word
CALL _ReadSPIbuf
CALL _Delay
LDP #0E0h
SPLK #00H,SPIDAT ;read the high "8"bits
CALL _ReadSPIbuf
LDP #r_char_h
SACL r_char_h
CALL _Delay
LDP #0E0h
SPLK #00H,SPIDAT ;read the low "8" bits
CALL _ReadSPIbuf
LDP #r_char_l
SACL r_char_l
LDP #0E0h
SETBIT SPIPC1, SETB6
CALL _Delay
ret
;------------------END READ---------------------------------------------------
;-----------------------------------------------------------------------------
_Delay:
;-----------------------------------------------------------------------------
RPT #0FFh
NOP
NOP
RET
;-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -