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

📄 main.s

📁 一个关于AVR单片机的例程
💻 S
字号:
	.module main.c
	.area text(rom, con, rel)
	.dbfile D:\桌面\教程\at45db041\main.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 9
; // ICC-AVR application builder : 2007-2-14 21:34:00
; // Target : M16
; // Crystal: 7.3728Mhz
; // 演示 at45db041 读写过程
; 
; #include "config.h"
; 
; void port_init(void)
; {
	.dbline 10
;  PORTA = 0x00;
	clr R2
	out 0x1b,R2
	.dbline 11
;  DDRA  = 0x00;
	out 0x1a,R2
	.dbline 12
;  PORTB = 0x00;
	out 0x18,R2
	.dbline 13
;  DDRB  = 0x00;
	out 0x17,R2
	.dbline 14
;  PORTC = 0x00; //m103 output only
	out 0x15,R2
	.dbline 15
;  DDRC  = 0x00;
	out 0x14,R2
	.dbline 16
;  PORTD = 0x00;
	out 0x12,R2
	.dbline 17
;  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 22
; }
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 24
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 25
;  port_init();
	xcall _port_init
	.dbline 26
;  at4541_init(); //at45db041初始化
	xcall _at4541_init
	.dbline 28
; 
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 29
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 30
;  TIMSK = 0x00; //timer interrupt sources
	out 0x39,R2
	.dbline 31
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
;          temp1 -> <dead>
;          temp2 -> R22
;    receive_buf -> y+0
;              i -> R20
	.even
_main::
	sbiw R28,10
	.dbline -1
	.dbline 36
;  //all peripherals are now initialized
; }
; 
; void main(void)
; {
	.dbline 38
;  unsigned int temp1;
;  unsigned char i=0,temp2=0;
	clr R20
	.dbline 38
	clr R22
	.dbline 40
;  unsigned char receive_buf[10];
;  init_devices();
	xcall _init_devices
	.dbline 41
;  at4541_commond_send(0x8200,0x00);//开始写指令,地址为0x00
	clr R18
	clr R19
	ldi R16,33280
	ldi R17,130
	xcall _at4541_commond_send
	.dbline 42
;  for(i=0;i<10;i++)
	xjmp L7
L4:
	.dbline 43
	.dbline 44
	mov R16,R20
	xcall _at4541_write
	.dbline 45
L5:
	.dbline 42
	inc R20
L7:
	.dbline 42
	cpi R20,10
	brlo L4
	.dbline 46
;  {
;   at4541_write(i);
;  }
;  at4541_stop();
	xcall _at4541_stop
	.dbline 47
;  delay_ms(500);
	ldi R16,500
	ldi R17,1
	xcall _delay_ms
L8:
	.dbline 50
L9:
	.dbline 49
;  
;  while(!at4541_check_busy())
	xcall _at4541_check_busy
	tst R16
	breq L8
	.dbline 52
;   ;//忙等待
;   
;  if(at4541_check_busy())
	xcall _at4541_check_busy
	tst R16
	breq L18
	.dbline 53
;  {
	.dbline 54
;   at4541_commond_send(0xe800,0x00);
	clr R18
	clr R19
	ldi R16,59392
	ldi R17,232
	xcall _at4541_commond_send
	.dbline 55
;   for(i=0;i<10;i++)
	clr R20
	xjmp L16
L13:
	.dbline 56
	.dbline 57
	xcall _at4541_read
	movw R24,R28
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R16
	.dbline 58
L14:
	.dbline 55
	inc R20
L16:
	.dbline 55
	cpi R20,10
	brlo L13
	.dbline 59
;   {
;    receive_buf[i]=at4541_read();
;   }
;  }
L17:
	.dbline 61
L18:
	.dbline 60
	xjmp L17
X0:
	.dbline -2
L3:
	adiw R28,10
	.dbline 0 ; func end
	ret
	.dbsym l temp1 1 i
	.dbsym r temp2 22 c
	.dbsym l receive_buf 0 A[10:10]c
	.dbsym r i 20 c
	.dbend

⌨️ 快捷键说明

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