logo
HomeAbout  |  Products  |  ApplicationsDownload  |  Contact Us  |  中文
 
Home-> Products-> 8-bit MCU
 
IC Induction
Develop & Tool
Application Project
Customer Service
 
Quick Coding
1 IO Ports 2 AD Converter
3 Timers 4 Capture
5 Compare 6 PWM 7 Interval Timer and Buzzer 8 External Interrupts
9 SPI 10 UART 11 LVR 12 Watch Dog Timer
13 STOP Mode 14 HALT Mode    

9 SPI

1. SPI operation on Master Mode and send data by polling method.

  lda  P_IOC_Buf
  and  #11110000B
  ora  #00000001B
  sta  P_IOC_Buf
  lda  P_IOC_Attrib
  and  #11110000B
  sta  P_IOC_Attrib
  lda  P_IOC_Dir
  and  #11111011B
  ora  #00001011B
  sta  P_IOC_Dir ; set PC2 as input(SDI),pc0.pc1.pc3 as output
  lda  #$AB
  sta  P_SPI_Ctrl0
  lda  #$43
  sta  P_SPI_Ctrl1
  set  P_SPI_Status,CB_SPI_INTIF ;clear TX/RX INT flag
  set  P_INT_Flag2,CB_INT_SPIIF
  ?L_Tx:
  clr  P_IOC_Data,0
  lda  #$5F
  sta  P_SPI_TxData ; send data #$5F incessantly
  ?L_Loop:
  tst  P_SPI_Status,CB_SPI_INTIF ;RX INT ?
  beq  ?L_Loop ; no
  set  P_IOC_Data,0
  set  P_SPI_Status,CB_SPI_INTIF ;clear TX/RX INT flag
  jmp  ?L_Tx

2. SPI operation on Slave Mode and send data by polling method.

  lda  P_IOC_Buf
  and  #11111000B
  sta  P_IOC_Buf
  lda  P_IOC_Attrib
  and  #11110000B
  sta  P_IOC_Attrib
  lda  P_IOC_Dir
  and  #11111000B
  ora  #00001000B
  sta  P_IOC_Dir ;set PC[0:2] as input,pc3 as output
  lda  #$EB
  sta  P_SPI_Ctrl0
  lda  #$C1
  sta  P_SPI_Ctrl1
  set  P_SPI_Status,CB_SPI_INTIF ;clear TX/RX INT flag
  set  P_INT_Flag2,CB_INT_SPIIF
  ?L_Tx:
  tst  P_SPI_Status,CB_SPI_INTIF
  beq  ?L_Tx ;no
  set  P_SPI_Status,CB_SPI_INTIF ;clear TX/RX INT flag
  lda  #$5F
  sta  P_SPI_TxData ;send data #$5F

3. SPI operation on Slave Mode and receive data by polling method.

  lda  P_IOC_Buf
  and  #11111000B
  sta  P_IOC_Buf
  lda  P_IOC_Attrib
  and  #11110000B
  sta  P_IOC_Attrib
  lda  P_IOC_Dir
  and  #11111000B
  ora  #00001000B
  sta  P_IOC_Dir ;set PC[0:2] as input,pc3 as output
  lda  #$EB
  sta  P_SPI_Ctrl0
  lda  #$C1
  sta  P_SPI_Ctrl1
  set  P_SPI_Status,CB_SPI_INTIF ;clear TX/RX INT flag
  set  P_INT_Flag2,CB_INT_SPIIF
  ?L_Rx:
  tst  P_SPI_Status,CB_SPI_INTIF ;RX INT ?
  beq  ?L_Rx ;no
  lda  P_SPI_RxData ;read data
Copyright © BEIJING SUNNORTH TECHNOLOGY CO., LTD Web site:mcu.sunplusmcu.com online real name:凌阳单片机
Unauthorized copy or republish to the content of this website is forbidden. Any one cannot resume on ICP备05061966号