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

📄 at45db041.s

📁 一个关于AVR单片机的例程
💻 S
字号:
	.module at45db041.c
	.area text(rom, con, rel)
	.dbfile D:\桌面\教程\at45db041\at45db041.c
	.dbfunc e at4541_init _at4541_init fV
	.even
_at4541_init::
	.dbline -1
	.dbline 15
; /**************************************
; ** Filename: at45db041.c
; ** Describe: Flash 存储器at45db041
; ** Author : 古欣 www.avrvi.com
; ** Time  :   2007-2-14
; **************************************/
; 
; #include "config.h"
; 
; /**************************************
; ** 说明:初始化 at45db041
; ** 除SO对应引脚为输入外,其余都设为输出,RESET高,CS低,芯片工作
; **************************************/
; void at4541_init(void)
; {
	.dbline 16
;  DDR_RESET_SET();
	sbi 0x1a,0
	.dbline 17
;  DDR_CS_SET();
	sbi 0x1a,1
	.dbline 18
;  DDR_SCK_SET();
	sbi 0x1a,2
	.dbline 19
;  DDR_SI_SET();
	sbi 0x1a,3
	.dbline 20
;  DDR_SO_SET();
	cbi 0x1a,4
	.dbline 22
;  
;  CS_LOW();
	cbi 0x1b,1
	.dbline 23
;  RESET_HIGH();
	sbi 0x1b,0
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e at4541_check_busy _at4541_check_busy fc
	.even
_at4541_check_busy::
	.dbline -1
	.dbline 31
; }
; 
; /**************************************
; ** 说明:RDY/~BUSY引脚为高表示准备好
; **                      低表示内部忙
; **************************************/
; unsigned char at4541_check_busy(void)
; {
	.dbline 32
;  if((AT4541_PIN&CHEAK_BUSY)==CHEAK_BUSY)
	in R24,0x19
	andi R24,32
	cpi R24,32
	brne L3
	.dbline 33
;   {
	.dbline 34
;     return 1;
	ldi R16,1
	xjmp L2
L3:
	.dbline 37
;   }
;  else
;   {
	.dbline 38
;    return 0;
	clr R16
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e at4541_commond_send _at4541_commond_send fV
;              i -> R20
;        address -> R22,R23
;        commond -> R10,R11
	.even
_at4541_commond_send::
	xcall push_gset3
	movw R22,R18
	movw R10,R16
	.dbline -1
	.dbline 49
;   }
; }
; 
; 
; /**************************************
; ** 说明:发送操作命令 (0xe800读)(0x8200写)
; ** 数据格式:16位命令字,16位地址位,32位任意数
; ** 输入:命令字,地址位
; **************************************/
; void at4541_commond_send(unsigned int commond,unsigned int address)
; {
	.dbline 50
;  unsigned char i=0;
	clr R20
	.dbline 51
;  SCK_HIGH();
	sbi 0x1b,2
	.dbline 52
;  RESET_HIGH();
	sbi 0x1b,0
	.dbline 53
;  CS_HIGH();
	sbi 0x1b,1
	.dbline 54
;  delay_1ms();
	xcall _delay_1ms
	.dbline 55
;  CS_LOW();
	cbi 0x1b,1
	.dbline 56
;  delay_1ms();
	xcall _delay_1ms
	.dbline 58
;  //16位命令字
;  for(i=0;i<16;i++)
	xjmp L9
L6:
	.dbline 59
;  {
	.dbline 60
;   SCK_LOW();
	cbi 0x1b,2
	.dbline 61
;   if((commond&0x8000)==0x8000)
	movw R24,R10
	andi R24,0
	andi R25,128
	cpi R24,0
	ldi R30,128
	cpc R25,R30
	brne L10
	.dbline 62
;    SI_HIGH();
	sbi 0x1b,3
	xjmp L11
L10:
	.dbline 64
;   else
;    SI_LOW();
	cbi 0x1b,3
L11:
	.dbline 65
	xcall _delay_1ms
	.dbline 66
	sbi 0x1b,2
	.dbline 67
	xcall _delay_1ms
	.dbline 68
	lsl R10
	rol R11
	.dbline 69
L7:
	.dbline 58
	inc R20
L9:
	.dbline 58
	cpi R20,16
	brlo L6
	.dbline 71
;   delay_1ms();
;   SCK_HIGH();
;   delay_1ms();
;   commond=commond<<1;
;  }
;  //16位地址位
;  for(i=0;i<16;i++)
	clr R20
	xjmp L15
L12:
	.dbline 72
;  {
	.dbline 73
;   SCK_LOW();
	cbi 0x1b,2
	.dbline 74
;   if((address&0x8000)==0x8000)
	movw R24,R22
	andi R24,0
	andi R25,128
	cpi R24,0
	ldi R30,128
	cpc R25,R30
	brne L16
	.dbline 75
;    SI_HIGH();
	sbi 0x1b,3
	xjmp L17
L16:
	.dbline 77
;   else
;    SI_LOW();
	cbi 0x1b,3
L17:
	.dbline 78
	xcall _delay_1ms
	.dbline 79
	sbi 0x1b,2
	.dbline 80
	xcall _delay_1ms
	.dbline 81
	lsl R22
	rol R23
	.dbline 82
L13:
	.dbline 71
	inc R20
L15:
	.dbline 71
	cpi R20,16
	brlo L12
	.dbline 84
;   delay_1ms();
;   SCK_HIGH();
;   delay_1ms();
;   address=address<<1;
;  }
;  //32位任意位
;  for(i=0;i<32;i++)
	clr R20
	xjmp L21
L18:
	.dbline 85
	.dbline 86
	cbi 0x1b,2
	.dbline 87
	xcall _delay_1ms
	.dbline 88
	sbi 0x1b,2
	.dbline 89
	xcall _delay_1ms
	.dbline 90
L19:
	.dbline 84
	inc R20
L21:
	.dbline 84
	cpi R20,32
	brlo L18
	.dbline -2
L5:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r address 22 i
	.dbsym r commond 10 i
	.dbend
	.dbfunc e at4541_read _at4541_read fc
;          temp1 -> R20
;          temp2 -> R22
;              i -> R10
	.even
_at4541_read::
	xcall push_gset3
	.dbline -1
	.dbline 99
;  {
;   SCK_LOW();
;   delay_1ms();
;   SCK_HIGH();
;   delay_1ms();
;  }
; }
; 
; /**************************************
; ** 说明:读at45db41
; ** 数据:在执行at4541_commond_send(发送读命令)之后,8位的数从SO输出
; ** 输出:读出的一位数
; **************************************/
; unsigned char at4541_read(void)
; {
	.dbline 100
;  unsigned char i=0,temp1=0,temp2=0;
	clr R10
	.dbline 100
	clr R20
	.dbline 100
	clr R22
	.dbline 102
;  //读出8位,组合在temp2里
;  for(i=0;i<8;i++)
	xjmp L26
L23:
	.dbline 103
;  {
	.dbline 104
;   SCK_LOW();
	cbi 0x1b,2
	.dbline 105
;   delay_1ms();
	xcall _delay_1ms
	.dbline 106
;   if(SO_PIN_HIGH)
	in R24,0x19
	andi R24,16
	cpi R24,16
	brne L27
	.dbline 107
;    temp1=1;
	ldi R20,1
	xjmp L28
L27:
	.dbline 109
;   else
;    temp1=0;
	clr R20
L28:
	.dbline 110
	mov R17,R20
	subi R17,255    ; addi 1
	mov R16,R22
	xcall lsl8
	mov R22,R16
	.dbline 111
	sbi 0x1b,2
	.dbline 112
	xcall _delay_1ms
	.dbline 113
L24:
	.dbline 102
	inc R10
L26:
	.dbline 102
	mov R24,R10
	cpi R24,8
	brlo L23
	.dbline 114
;   temp2=temp2<<1+temp1;
;   SCK_HIGH();
;   delay_1ms();
;  }
;  return temp2;
	mov R16,R22
	.dbline -2
L22:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r temp1 20 c
	.dbsym r temp2 22 c
	.dbsym r i 10 c
	.dbend
	.dbfunc e at4541_write _at4541_write fV
;              i -> R20
;           data -> R22
	.even
_at4541_write::
	xcall push_gset2
	mov R22,R16
	.dbline -1
	.dbline 123
; }
; 
; /**************************************
; ** 说明:写at45db41
; ** 数据:在执行at4541_commond_send(发送写命令)之后,8位的数写入
; ** 输出:写入的一位数
; **************************************/
; void at4541_write(unsigned char data)
; {
	.dbline 124
;  unsigned char i=0;
	clr R20
	.dbline 126
;  //生成写入时序
;  for(i=0;i<8;i++)
	xjmp L33
L30:
	.dbline 127
;  {
	.dbline 128
;   SCK_LOW();
	cbi 0x1b,2
	.dbline 129
;   if(data&0x80==0x80)
	sbrs R22,0
	rjmp L34
	.dbline 130
;    SI_HIGH();
	sbi 0x1b,3
	xjmp L35
L34:
	.dbline 132
;   else
;    SI_LOW();
	cbi 0x1b,3
L35:
	.dbline 133
	xcall _delay_1ms
	.dbline 134
	sbi 0x1b,2
	.dbline 135
	xcall _delay_1ms
	.dbline 136
	lsl R22
	.dbline 137
L31:
	.dbline 126
	inc R20
L33:
	.dbline 126
	cpi R20,8
	brlo L30
	.dbline -2
L29:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r data 22 c
	.dbend
	.dbfunc e at4541_read_status _at4541_read_status fc
;          temp1 -> R20
;          temp2 -> R22
;              i -> R10
;        commond -> R12
	.even
_at4541_read_status::
	xcall push_gset4
	mov R12,R16
	.dbline -1
	.dbline 146
;   delay_1ms();
;   SCK_HIGH();
;   delay_1ms();
;   data=data<<1;
;  }
; }
; 
; /**************************************
; ** 说明:读取寄存器状态
; ** 操作流程:将57H或D7H操作代码传给at45db041 
; ** 随后芯片从SO输出8位寄存器信息,高位在前
; **************************************/
; unsigned char at4541_read_status(unsigned char commond)
; {
	.dbline 147
;  unsigned char i=0,temp1=0,temp2=0;
	clr R10
	.dbline 147
	clr R20
	.dbline 147
	clr R22
	.dbline 148
;  SCK_HIGH();
	sbi 0x1b,2
	.dbline 149
;  RESET_HIGH();
	sbi 0x1b,0
	.dbline 150
;  CS_HIGH();
	sbi 0x1b,1
	.dbline 151
;  delay_1ms();
	xcall _delay_1ms
	.dbline 152
;  CS_LOW();
	cbi 0x1b,1
	.dbline 153
;  delay_1ms();
	xcall _delay_1ms
	.dbline 155
;  //本循环把8位command传给at45db041
;  for(i=0;i<8;i++)
	xjmp L40
L37:
	.dbline 156
;  {
	.dbline 157
;   SCK_LOW();
	cbi 0x1b,2
	.dbline 158
;   if((commond&0x80)==0x80)
	mov R24,R12
	andi R24,128
	cpi R24,128
	brne L41
	.dbline 159
;     SI_HIGH();
	sbi 0x1b,3
	xjmp L42
L41:
	.dbline 161
;   else 
;     SI_LOW();
	cbi 0x1b,3
L42:
	.dbline 162
	xcall _delay_1ms
	.dbline 163
	sbi 0x1b,2
	.dbline 164
	xcall _delay_1ms
	.dbline 165
	lsl R12
	.dbline 166
L38:
	.dbline 155
	inc R10
L40:
	.dbline 155
	mov R24,R10
	cpi R24,8
	brlo L37
	.dbline 168
;   delay_1ms();
;   SCK_HIGH();
;   delay_1ms();
;   commond=commond<<1;
;  }
;  //本循环接收传回的八位数据
;  for(i=0;i<8;i++)
	clr R10
	xjmp L46
L43:
	.dbline 169
;  {
	.dbline 170
;   SCK_LOW();
	cbi 0x1b,2
	.dbline 171
;   delay_1ms();
	xcall _delay_1ms
	.dbline 173
;   
;   if(SO_PIN_HIGH)
	in R24,0x19
	andi R24,16
	cpi R24,16
	brne L47
	.dbline 174
;    temp1 = 1;
	ldi R20,1
	xjmp L48
L47:
	.dbline 176
;   else
;    temp1 = 0;
	clr R20
L48:
	.dbline 178
	mov R17,R20
	subi R17,255    ; addi 1
	mov R16,R22
	xcall lsl8
	mov R22,R16
	.dbline 179
	sbi 0x1b,2
	.dbline 180
	xcall _delay_1ms
	.dbline 181
L44:
	.dbline 168
	inc R10
L46:
	.dbline 168
	mov R24,R10
	cpi R24,8
	brlo L43
	.dbline 182
;   
;   temp2 = temp2<<1 + temp1;
;   SCK_HIGH();
;   delay_1ms();
;  }
;  CS_HIGH(); //停止输出
	sbi 0x1b,1
	.dbline 184
;  
;  delay_ms(500);
	ldi R16,500
	ldi R17,1
	xcall _delay_ms
	.dbline 186
;  
;  return temp2;
	mov R16,R22
	.dbline -2
L36:
	xcall pop_gset4
	.dbline 0 ; func end
	ret
	.dbsym r temp1 20 c
	.dbsym r temp2 22 c
	.dbsym r i 10 c
	.dbsym r commond 12 c
	.dbend
	.dbfunc e at4541_stop _at4541_stop fV
	.even
_at4541_stop::
	.dbline -1
	.dbline 194
; }
; 
; /**************************************
; ** 说明:CS=1 停止at45db041
; **
; **************************************/
; void at4541_stop(void)
; {
	.dbline 195
;   CS_HIGH();
	sbi 0x1b,1
	.dbline 196
;   delay_ms(500);
	ldi R16,500
	ldi R17,1
	xcall _delay_ms
	.dbline -2
L49:
	.dbline 0 ; func end
	ret
	.dbend

⌨️ 快捷键说明

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