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

📄 spi接口发送.s

📁 ICC mega8例子
💻 S
字号:
	.module SPI接口发送.c
	.area text(rom, con, rel)
	.dbfile E:\xiaozhiyong2009\设计资料\项目设计\ICCAVR_mega8_C\ICCAVR_mega8_SPI接口发送\SPI接口发送.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 9
; //ICC-AVR application builder : 2009-3-12 16:45:27
; // Target : M8
; // Crystal: 8.0000Mhz
; 
; #include <iom8v.h>
; #include <macros.h>
; 
; void port_init(void)
; {
	.dbline 10
;  PORTB = 0x00;
	clr R2
	out 0x18,R2
	.dbline 11
;  DDRB  = 0x00;
	out 0x17,R2
	.dbline 12
;  PORTC = 0x00; //m103 output only
	out 0x15,R2
	.dbline 13
;  DDRC  = 0x00;
	out 0x14,R2
	.dbline 14
;  PORTD = 0x00;
	out 0x12,R2
	.dbline 15
;  DDRD  = 0x00;
	out 0x11,R2
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 20
; }
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 22
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 23
;  port_init();
	rcall _port_init
	.dbline 25
; 
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 26
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 27
;  TIMSK = 0x00; //timer interrupt sources
	out 0x39,R2
	.dbline 28
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e spi_master_init _spi_master_init fV
	.even
_spi_master_init::
	.dbline -1
	.dbline 41
;  //all peripherals are now initialized
; }
; 
; //*******************************spi_master*****************************
; /***********************************************************
; 用    途:SPI主从式发送
; Taget   :mega8
; crystal :8M
; 介    绍:PB2-SS,PB3-MOSI,PB4-MISO,PB5-SCK
;          从机的SS要接地
; **********************************************************/
; void spi_master_init()
; {
	.dbline 43
;  //DDR_SPI=(1<<DD_MOSI)|(1<<DD_SCK)
;  DDRB=(1<<3)|(1<<5)|(1<<2);
	ldi R24,44
	out 0x17,R24
	.dbline 45
;  //使能SPI,master,fck/16
;  SPCR=(1<<SPE)|(1<<MSTR)|(1<<SPR1);
	ldi R24,82
	out 0xd,R24
	.dbline -2
L3:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e spi_master_putc _spi_master_putc fV
;          cData -> R16
	.even
_spi_master_putc::
	.dbline -1
	.dbline 49
; }
; //发送数据
; void spi_master_putc(unsigned char cData)
; {
	.dbline 50
;  SPDR=cData;//发送数据
	out 0xf,R16
L5:
	.dbline 52
;  while(!(SPSR&(1<<SPIF)))
;  {;}
	.dbline 52
	.dbline 52
L6:
	.dbline 51
	sbis 0xe,7
	rjmp L5
X0:
	.dbline -2
L4:
	.dbline 0 ; func end
	ret
	.dbsym r cData 16 c
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	.dbline -1
	.dbline 57
; }
; //*********************************************************************
; 
; void main()
; {
	.dbline 58
;  port_init();
	rcall _port_init
	.dbline 59
;  init_devices();
	rcall _init_devices
	.dbline 61
;  
;  spi_master_init();
	rcall _spi_master_init
	rjmp L10
L9:
	.dbline 63
;  while(1)
;  {
	.dbline 64
;   spi_master_putc(0x54);
	ldi R16,84
	rcall _spi_master_putc
	.dbline 65
;  }
L10:
	.dbline 62
	rjmp L9
X1:
	.dbline -2
L8:
	.dbline 0 ; func end
	ret
	.dbend
; }

⌨️ 快捷键说明

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