⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spi.s

📁 AVR单片机系统开发经典实例部分源程序
💻 S
字号:
	.module SPI.c
	.area text(rom, con, rel)
	.dbfile C:\AVR\M\1\SPI.c
	.dbfunc e SPI_Init _SPI_Init fV
	.even
_SPI_Init::
	.dbline -1
	.dbline 10
; #include "SPI.h"
; 
; 
; //---------------------------------
; //
; //        SPI初始化函数 
; //
; //---------------------------------
; void SPI_Init(void)
; { 
	.dbline 11
; 	SPI_SCK_OUT();
	sbi 0x17,7
	.dbline 12
; 	SPI_MOSI_OUT();
	sbi 0x17,5
	.dbline 13
; 	SPI_MISO_IN();
	cbi 0x17,6
	.dbline 14
; 	PORTB = 0xFF;
	ldi R24,255
	out 0x18,R24
	.dbline 15
; 	SPI_Low();
	xcall _SPI_Low
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e SPI_Low _SPI_Low fV
	.even
_SPI_Low::
	.dbline -1
	.dbline 25
; }
; 
; 
; //---------------------------------
; //
; //     SPI低速模式设置函数 
; //
; //---------------------------------
; void SPI_Low(void)
; {
	.dbline 26
; 	SPCR |=(1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0);
	in R24,0xd
	ori R24,83
	out 0xd,R24
	.dbline 27
; 	SPSR &= ~(1<<SPI2X);
	cbi 0xe,0
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e SPI_High _SPI_High fV
	.even
_SPI_High::
	.dbline -1
	.dbline 38
; }
; 
; 
; 
; //---------------------------------
; //
; //     SPI高速模式设置函数 
; //
; //---------------------------------
; void SPI_High(void)
; {
	.dbline 39
; 	SPCR = (1<<SPE)|(1<<MSTR);
	ldi R24,80
	out 0xd,R24
	.dbline 40
; 	SPSR |= (1<<SPI2X);
	sbi 0xe,0
	.dbline -2
L3:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e SPI_SrByte _SPI_SrByte fc
;            val -> R16
	.even
_SPI_SrByte::
	.dbline -1
	.dbline 52
; }
; 
; 
; //---------------------------------
; //
; //SPI收发函数 
; //val:要发送的数据
; //SPDR:返回数据
; //
; //---------------------------------
; uint8 SPI_SrByte(uint8 val)
; {
	.dbline 53
; 	SPDR = val;
	out 0xf,R16
L5:
	.dbline 54
L6:
	.dbline 54
; 	while(!(SPSR & (1<<SPIF)));
	sbis 0xe,7
	rjmp L5
	.dbline 55
; 	return SPDR;
	in R16,0xf
	.dbline -2
L4:
	.dbline 0 ; func end
	ret
	.dbsym r val 16 c
	.dbend

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -