有哪位大神帮忙看下69P42模拟SPI的程序有木有问题?
SPI_SENDGET_BYTE:
PUSH_A
LDI SPI_COUNT,04H
ANDIM SPI_FLAG,1101B
SPI_SEND_BYTE1:
CLR_SCK ;拉低时钟信号
LDA SPI_TMP_H,0
BA3 SEND_DATA_1 ;先发送高位
CLR_SDI
JMP SPI_SEND_BYTE2
SEND_DATA_1:
SET_SDI
SPI_SEND_BYTE2:
NOP
NOP
NOP
SET_SCK
LDA SPI_TMP_H,0 ;发送的数据左移
ADDM SPI_TMP_H,0
LDA SPI_READBYTE_L,0 ;接收的数据左移
ADDM SPI_READBYTE_L,0
LDA PD,0 ;读取SDO
BA3 GET_DATA_1
ANDIM SPI_READBYTE_L,1110B
JMP SPI_GET_BYTE1
GET_DATA_1:
ORIM SPI_READBYTE_L,0001B
SPI_GET_BYTE1:
SBIM SPI_COUNT,01H ;判断4位是否发送完
BNZ SPI_SEND_BYTE1
LDA SPI_FLAG,0
BA1 SPI_SENDGET_END
LDI SPI_COUNT,04H
ORIM SPI_FLAG,0010B ;4位接收/发送完置位
LDA SPI_TMP_L,0 ;把地位赋值给高位
STA SPI_TMP_H,0
LDA SPI_READBYTE_L,0 ;先接收的4位数据给高位
STA SPI_READBYTE_H,0
JMP SPI_SEND_BYTE1
SPI_SENDGET_END:
CLR_SCK
POP_A
RTNI
有什么问题没有 |