📄 spi_dataflash.asm
字号:
;顺序写子程序,用spiwt名称调用
spiwt bcf STATUS,RP0
bcf PORTB,SCK ;模式0
bcf PORTB,cs ;片选
movlw 82H ;加载操作码
movwf spi_out ;置入寄存器
call spiout ;调用子程序输出操作码
movf PA1,w ;加载第一字节地址
movwf spi_out ;置入寄存器
call spiout ;调用子程序输出
movf BA1,w
xorwf PA2,w ;获得第二字节地址
movwf spi_out ;置入寄存器
call spiout ;调用子程序输出
movf BA2,w ;加载第三字节地址
movwf spi_out ;置入寄存器
call spiout ;调用子程序输出
movf spi_wt,w ;加载待写数据
movwf spi_out ;置入寄存器
call spiout ;调用子程序输出
bsf PORTB,cs ;触发写入操作
nop ;延时
retlw 0 ;从子程序返回
;输出子程序,用spiout名称调用
spiout movlw 0x08 ;加载输出位数
movwf spi_cnt ;置入寄存器
nspiout rlf spi_out ;先输出最高位
btfsc STATUS,C ;是否为1
bsf PORTB,SDO ;输出1
btfss STATUS,C ;是否为0
bcf PORTB,SDO ;输出0
nop ;延时
bsf PORTB,SCK ;时钟信号上升沿
nop ;延时
bcf PORTB,SCK ;时钟信号下降沿
decfsz spi_cnt ;检查输出位数
goto nspiout ;输出下一位
retlw 0 ;从子程序返回
;顺序读子程序,用名称spicrd调用
spicrd bcf STATUS,RP0
bcf PORTB,cs ;片选
bcf PORTB,SCK ;模式0
movlw E8H ;加载操作码
movwf spi_out ;置入寄存器
call spiout ;调用子程序输出
movf PA1,w ;加载第一字节地址
movwf spi_out ;置入寄存器
call spiout ;调用子程序输出
movf BA1,w
xorwf PA2,w ;获得第二字节地址
movwf spi_out ;置入寄存器
call spiout ;调用子程序输出
movf BA2,w ;加载第三字节地址
movwf spi_out ;置入寄存器
call spiout ;调用子程序输出
movf DCRE,w ;加载任意位字节
movwf spi_out ;置入寄存器
call spiout ;调用子程序输出
movf DCRE,w ;共需4个任意位字节
movwf spi_out
call spiout
movf DCRE,w
movwf spi_out
call spiout
movf DCRE,w
movwf spi_out
call spiout
retlw 0 ;从子程序返回
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -