共2条
1/1 1 跳转至页
TO,zsmbj TO zsmbj 程序在这....
问
.org $0000
rjmp START
.DEF TEMP1 = R16
.DEF TEMP2 = R17
.DEF TEMP3 = R18
.DEF SPI_DATA = R21
.EQU SPI_SCK = PINB7
.EQU SPI_MISO = PINB6
.EQU SPI_MOSI = PINB5
.EQU SPI_NSS = PINB4
.ORG $0080
rjmp SPI_HANDLE
.ORG $0100
SPI_HANDLE:
in SPI_DATA,SPDR
reti
START:
ldi TEMP1,0x5f
ldi TEMP2,0x02
out spl,TEMP1
out sph,TEMP2 ;设置堆栈
sei ;开全局中断
ldi TEMP1,0xbb
ldi TEMP2,0xff
ldi TEMP3,0xDf
out DDRB,TEMP1
out DDRC,TEMP2 ;PB口方向设为1011 1011,MISO设为输入,其他为输出
out SPCR,TEMP3 ;0101 1100 ,设为主机模式,方式3,fcl/4
ldi TEMP3,0x00 ;用来接受数据的寄存器
sbi PORTB,SPI_NSS
rcall delay
rjmp step1 ;先写9个字节数据
STEP0: ;读9个字节数据
CBI PORTB,SPI_NSS ;片选
ldi SPI_DATA,0x54 ;装入读命令字和地址
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
IN SPI_DATA,SPDR
MOV R0,SPI_DATA ;取出data~1
rcall WRITe
IN SPI_DATA,SPDR
MOV R1,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR
MOV R2,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR
MOV R3,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR
MOV R4,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR
MOV R5,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR
MOV R6,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR
MOV R7,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR ;DATA~9
MOV R8,SPI_DATA
sbi portb,SPI_NSS
RCALL DELAY
RET
STEP1: ;写9个字节数据
cbi PORTB,SPI_NSS ;cs变低
ldi SPI_DATA,0x84 ;装入写命令字和地址
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
;mov SPI_DATA,TEMP2
;rcall WRITE
MOV SPI_DATA,R8
RCALL WRITE
MOV SPI_DATA,R7
RCALL WRITE
MOV SPI_DATA,R6
RCALL WRITE
MOV SPI_DATA,R5
RCALL WRITE
MOV SPI_DATA,R4
RCALL WRITE
MOV SPI_DATA,R3
RCALL WRITE
MOV SPI_DATA,R2
RCALL WRITE
MOV SPI_DATA,R1
RCALL WRITE
MOV SPI_DATA,R0 ;注:R8~R0,是9个准备好的数据
RCALL WRITE
sbi PORTB,4 ;cs变高
rcall delay
RCALL STEP0
LOOP: rjmp LOOP
WRITE:
out spdr,SPI_DATA ;将待传数据送入SPDR,启动SCK。
rcall delay
ret
delay:ldi r31,0x20
del:dec r31
brne del
ret
;DATAFLASH是AT45DB081B
答 1: 先注意,SPI的中断地址是0x0008,不会是你贴错了吧! 答 2: 编写程序时要注意时序:发送采用了1/128时钟,发送一个字节需要128×8个时钟周期。而在实际发送时却只延迟了32×3个周期就发送下一个字节了,这显然不对了。...
答 3: 多谢zsmbj先生... ....
rjmp START
.DEF TEMP1 = R16
.DEF TEMP2 = R17
.DEF TEMP3 = R18
.DEF SPI_DATA = R21
.EQU SPI_SCK = PINB7
.EQU SPI_MISO = PINB6
.EQU SPI_MOSI = PINB5
.EQU SPI_NSS = PINB4
.ORG $0080
rjmp SPI_HANDLE
.ORG $0100
SPI_HANDLE:
in SPI_DATA,SPDR
reti
START:
ldi TEMP1,0x5f
ldi TEMP2,0x02
out spl,TEMP1
out sph,TEMP2 ;设置堆栈
sei ;开全局中断
ldi TEMP1,0xbb
ldi TEMP2,0xff
ldi TEMP3,0xDf
out DDRB,TEMP1
out DDRC,TEMP2 ;PB口方向设为1011 1011,MISO设为输入,其他为输出
out SPCR,TEMP3 ;0101 1100 ,设为主机模式,方式3,fcl/4
ldi TEMP3,0x00 ;用来接受数据的寄存器
sbi PORTB,SPI_NSS
rcall delay
rjmp step1 ;先写9个字节数据
STEP0: ;读9个字节数据
CBI PORTB,SPI_NSS ;片选
ldi SPI_DATA,0x54 ;装入读命令字和地址
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
IN SPI_DATA,SPDR
MOV R0,SPI_DATA ;取出data~1
rcall WRITe
IN SPI_DATA,SPDR
MOV R1,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR
MOV R2,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR
MOV R3,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR
MOV R4,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR
MOV R5,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR
MOV R6,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR
MOV R7,SPI_DATA
RCALL WRITE
IN SPI_DATA,SPDR ;DATA~9
MOV R8,SPI_DATA
sbi portb,SPI_NSS
RCALL DELAY
RET
STEP1: ;写9个字节数据
cbi PORTB,SPI_NSS ;cs变低
ldi SPI_DATA,0x84 ;装入写命令字和地址
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
ldi SPI_DATA,0x00
rcall WRITE
;mov SPI_DATA,TEMP2
;rcall WRITE
MOV SPI_DATA,R8
RCALL WRITE
MOV SPI_DATA,R7
RCALL WRITE
MOV SPI_DATA,R6
RCALL WRITE
MOV SPI_DATA,R5
RCALL WRITE
MOV SPI_DATA,R4
RCALL WRITE
MOV SPI_DATA,R3
RCALL WRITE
MOV SPI_DATA,R2
RCALL WRITE
MOV SPI_DATA,R1
RCALL WRITE
MOV SPI_DATA,R0 ;注:R8~R0,是9个准备好的数据
RCALL WRITE
sbi PORTB,4 ;cs变高
rcall delay
RCALL STEP0
LOOP: rjmp LOOP
WRITE:
out spdr,SPI_DATA ;将待传数据送入SPDR,启动SCK。
rcall delay
ret
delay:ldi r31,0x20
del:dec r31
brne del
ret
;DATAFLASH是AT45DB081B
答 1: 先注意,SPI的中断地址是0x0008,不会是你贴错了吧! 答 2: 编写程序时要注意时序:发送采用了1/128时钟,发送一个字节需要128×8个时钟周期。而在实际发送时却只延迟了32×3个周期就发送下一个字节了,这显然不对了。...
答 3: 多谢zsmbj先生... ....
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
vscode+cmake搭建雅特力AT32L021开发环境被打赏30分 | |
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 |