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

📄 mmc.s

📁 你熟悉QT吗?Linux系统上领先的GUI
💻 S
字号:
	.module mmc.c
	.area text(rom, con, rel)
	.dbfile G:\mega8\atmega16\mp3_7210\mmc.c
	.dbfunc e SPI_masterinit _SPI_masterinit fV
	.even
_SPI_masterinit::
	.dbline -1
	.dbline 52
; #include <iom16v.h>
; 
; // MMC commands
; #define MMC_GO_IDLE_STATE		0
; #define MMC_SEND_OP_COND		1
; #define MMC_SEND_CSD			9
; #define MMC_SEND_CID			10
; #define MMC_SEND_STATUS			13
; #define MMC_SET_BLOCKLEN		16
; #define MMC_READ_SINGLE_BLOCK		17
; #define MMC_WRITE_BLOCK			24
; #define MMC_PROGRAM_CSD			27
; #define MMC_SET_WRITE_PROT		28
; #define MMC_CLR_WRITE_PROT		29
; #define MMC_SEND_WRITE_PROT		30
; #define MMC_TAG_SECTOR_START		32
; #define MMC_TAG_SECTOR_END		33
; #define MMC_UNTAG_SECTOR		34
; #define MMC_TAG_ERASE_GROUP_START 	35
; #define MMC_TAG_ERARE_GROUP_END		36
; #define MMC_UNTAG_ERASE_GROUP		37
; #define MMC_ERASE			38
; #define MMC_CRC_ON_OFF			59
; 
; #define R1_BUSY				128
; #define R1_PARAMETER			 64
; #define R1_ADDRESS			 32
; #define R1_ERASE_SEQ			 16
; #define R1_COM_CRC			  8
; #define R1_ILLEGAL_COM			  4
; #define R1_ERASE_RESET		  	  2
; #define R1_IDLE_STATE		  	  1
; 
; #define led1_off      (PORTA|=(1<<6))
; #define led1_on       (PORTA&=~(1<<6))
; #define led2_off      (PORTA|=(1<<5))
; #define led2_on       (PORTA&=~(1<<5))
; 
; #define disable_mmc_cs	(PORTB|=(1<<0))
; #define enable_mmc_cs	(PORTB&=~(1<<0))
; 
; 
; 
; unsigned char  ram_data[512];
; 
; 
; 
; extern void LCD_write(unsigned char data,unsigned char dc); 
; 
; /***********SPI初始化******************/
; void SPI_masterinit(void) 
;      {
	.dbline 54
;                             //不中断 允许    主模式            fck/4	 
;       SPCR=0b01010000;	      //SPIE SPE DORD MSTR CPOL CPHA SPR1 SPR0
	ldi R24,80
	out 0xd,R24
	.dbline -2
	.dbline 56
; 
; 	 }
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e SPI_tx_rx _SPI_tx_rx fc
;       spi_data -> R16
	.even
_SPI_tx_rx::
	.dbline -1
	.dbline 61
; 	
; /***********SPI读取/写入****基础SPI传送命令******/
; unsigned char SPI_tx_rx(unsigned char spi_data);
; unsigned char SPI_tx_rx(unsigned char spi_data) 
;      {
	.dbline 62
; 	 SPDR=spi_data;
	out 0xf,R16
L3:
	.dbline 63
L4:
	.dbline 63
; 	 while (!(SPSR&0x80));
	sbis 0xe,7
	rjmp L3
	.dbline 64
; 	 return SPDR;
	in R16,0xf
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbsym r spi_data 16 c
	.dbend
	.dbfunc e MMC_sendCmd _MMC_sendCmd fc
;           temp -> R20
;           A7_0 -> y+8
;          A15_8 -> y+6
;         A23_16 -> y+4
;         A31_24 -> R20
;            cmd -> R22
	.even
_MMC_sendCmd::
	xcall push_gset2
	mov R20,R18
	mov R22,R16
	.dbline -1
	.dbline 69
; 	 }
; /***********MMC_sendCmd();*****基础传送命令*******/
; unsigned char MMC_sendCmd(unsigned char cmd,unsigned char A31_24,unsigned char A23_16,unsigned char A15_8,unsigned char A7_0);
; unsigned char MMC_sendCmd(unsigned char cmd,unsigned char A31_24,unsigned char A23_16,unsigned char A15_8,unsigned char A7_0)
;      {
	.dbline 71
; 	 signed char temp;
; 	 enable_mmc_cs;
	cbi 0x18,0
	.dbline 73
; 
; 	 SPI_tx_rx(cmd|0x40);       //cmd"01xxxxxx"
	mov R16,R22
	ori R16,64
	xcall _SPI_tx_rx
	.dbline 74
; 	 SPI_tx_rx(A31_24);
	mov R16,R20
	xcall _SPI_tx_rx
	.dbline 75
; 	 SPI_tx_rx(A23_16);
	ldd R16,y+4
	xcall _SPI_tx_rx
	.dbline 76
; 	 SPI_tx_rx(A15_8);
	ldd R16,y+6
	xcall _SPI_tx_rx
	.dbline 77
; 	 SPI_tx_rx(A7_0);
	ldd R16,y+8
	xcall _SPI_tx_rx
	.dbline 78
; 	 SPI_tx_rx(0x95);          //crc for cmd0
	ldi R16,149
	xcall _SPI_tx_rx
	.dbline 80
; 
; 	 SPI_tx_rx(0xff);         //one empty cycle
	ldi R16,255
	xcall _SPI_tx_rx
	.dbline 82
;  
; 	 temp=SPI_tx_rx(0xff);    //0=busy 
	ldi R16,255
	xcall _SPI_tx_rx
	mov R20,R16
	.dbline 84
; //LCD_write(temp,1);  //test point
; 	 if ((temp-0x80)>=0)         //0b1xxxxxxx=err
	mov R24,R20
	subi R24,128
	cpi R24,0
	brlt L7
	.dbline 85
; 	 	   {
	.dbline 86
; 		   temp=0xff;
	ldi R20,255
L9:
	.dbline 87
L10:
	.dbline 87
; 		   while (SPI_tx_rx(0xff)==0);  
	ldi R16,255
	xcall _SPI_tx_rx
	tst R16
	breq L9
	.dbline 89
; //		   led1_on;  //test point
; 		   }
	xjmp L8
L7:
	.dbline 91
; 	 else 
; 	 	  if (cmd==MMC_SEND_STATUS)    //如果是读状态命令
	cpi R22,13
	brne L18
	.dbline 92
; 	 	  	  {
	.dbline 93
; 		  	  temp=SPI_tx_rx(0xff);       //read STATUS
	ldi R16,255
	xcall _SPI_tx_rx
	mov R20,R16
L14:
	.dbline 94
L15:
	.dbline 94
; 		 	  while (SPI_tx_rx(0xff)==0);  
	ldi R16,255
	xcall _SPI_tx_rx
	tst R16
	breq L14
	.dbline 96
; 			 // led1_on;
; 	 	  	  }
	xjmp L13
X0:
	.dbline 98
; 	 	  else                            //是其他命令
; 	 	  	  {
L17:
	.dbline 99
L18:
	.dbline 99
; 		  	  while (SPI_tx_rx(0xff)==0);  
	ldi R16,255
	xcall _SPI_tx_rx
	tst R16
	breq L17
	.dbline 101
; 			//  led1_on;
; 	 	  	  }
L13:
L8:
	.dbline 102
; 	 return temp;		  	 	  
	mov R16,R20
	.dbline -2
L6:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r temp 20 C
	.dbsym l A7_0 8 c
	.dbsym l A15_8 6 c
	.dbsym l A23_16 4 c
	.dbsym r A31_24 20 c
	.dbsym r cmd 22 c
	.dbend
	.dbfunc e MMC_finish _MMC_finish fV
	.even
_MMC_finish::
	.dbline -1
	.dbline 106
; 	 }	
; /***********MMC_finish();***停止卡片******/
; void MMC_finish(void)
;      {
	.dbline 107
; 	  disable_mmc_cs;
	sbi 0x18,0
	.dbline 108
; 	  SPI_tx_rx(0xff);
	ldi R16,255
	.dbline -2
	.dbline 109
; 	 }
L20:
	.dbline 0 ; func end
	xjmp _SPI_tx_rx
	.dbend
	.dbfunc e MMC_flush _MMC_flush fV
;        counter -> R20
;      flush_num -> R22
	.even
_MMC_flush::
	xcall push_gset2
	mov R22,R16
	.dbline -1
	.dbline 114
; 
; /***********MMC_flush();*****丢弃几个字节*******/
; void MMC_flush(unsigned char flush_num);
; void MMC_flush(unsigned char flush_num)
;      {
	.dbline 116
	clr R20
	xjmp L25
L22:
	.dbline 116
	ldi R16,255
	xcall _SPI_tx_rx
L23:
	.dbline 116
	inc R20
L25:
	.dbline 116
; 	 unsigned char counter;
; 	 for (counter=0;counter<flush_num;counter++) SPI_tx_rx(0xff); //丢弃几个字节
	cp R20,R22
	brlo L22
	.dbline 117
; 	 MMC_finish();	  
	xcall _MMC_finish
	.dbline -2
	.dbline 118
; 	 }
L21:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r counter 20 c
	.dbsym r flush_num 22 c
	.dbend
	.dbfunc e MMC_reset _MMC_reset fV
;        lcd_add -> <dead>
;   mmc_response -> R20
;        counter -> R22
	.even
_MMC_reset::
	xcall push_gset2
	sbiw R28,5
	.dbline -1
	.dbline 122
; 			 			 	
; /***********MMC_reset();***将MMC卡转到SPI模式****/
; void MMC_reset(void)
;      {
	.dbline 124
	clr R22
	xjmp L30
L27:
	.dbline 124
	ldi R16,255
	xcall _SPI_tx_rx
L28:
	.dbline 124
	inc R22
L30:
	.dbline 124
; 	  unsigned char counter,mmc_response,lcd_add;
; 	  for (counter=0;counter<11;counter++) SPI_tx_rx(0xff);//80个时钟开始总线
	cpi R22,11
	brlo L27
	.dbline 126
; 
; 	  mmc_response=MMC_sendCmd(MMC_GO_IDLE_STATE,0,0,0,0);   //send cmd0
	clr R2
	std y+4,R2
	std y+2,R2
	std y+0,R2
	clr R18
	clr R16
	xcall _MMC_sendCmd
	mov R20,R16
	.dbline 127
; 	  MMC_finish();
	xcall _MMC_finish
	.dbline 129
; 	  
; 	  for (counter=0;counter<80;counter++)   //失败尝试次数
	clr R22
	xjmp L34
L31:
	.dbline 130
; 	  	  {
	.dbline 132
; 
; 		  mmc_response=MMC_sendCmd(MMC_SEND_OP_COND,0,0,0,0);
	clr R2
	std y+4,R2
	std y+2,R2
	std y+0,R2
	clr R18
	ldi R16,1
	xcall _MMC_sendCmd
	mov R20,R16
	.dbline 133
; 		  MMC_finish();
	xcall _MMC_finish
	.dbline 135
; 
; 		  if (mmc_response==0)               //切换到SPI成功
	tst R20
	brne L35
	.dbline 136
; 		  	  {
	.dbline 137
;               led2_on;
	cbi 0x1b,5
	.dbline 138
; 			  counter=81;                     //跳出失败尝试次数
	ldi R22,81
	.dbline 139
; 			  }
	xjmp L36
L35:
	.dbline 140
; 		  else  led1_on;                     //切换到SPI失败
	cbi 0x1b,6
L36:
	.dbline 142
L32:
	.dbline 129
	inc R22
L34:
	.dbline 129
	cpi R22,80
	brlo L31
	.dbline -2
	.dbline 144
; 
; 		  } 
; 	  
; 	 }
L26:
	adiw R28,5
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l lcd_add 6 c
	.dbsym r mmc_response 20 c
	.dbsym r counter 22 c
	.dbend
	.dbfunc e MMC_check _MMC_check fc
;   mmc_response -> R20
	.even
_MMC_check::
	xcall push_gset1
	sbiw R28,5
	.dbline -1
	.dbline 149
; 		
; /***********MMC_check();******测试卡是否正常为0***********/
; unsigned char MMC_check(void);
; unsigned char MMC_check(void)
;      {
	.dbline 151
; 	  unsigned char mmc_response;
; 	  mmc_response=MMC_sendCmd(MMC_SEND_STATUS,0,0,0,0);   //send cmd
	clr R2
	std y+4,R2
	std y+2,R2
	std y+0,R2
	clr R18
	ldi R16,13
	xcall _MMC_sendCmd
	mov R20,R16
	.dbline 152
; 	  MMC_finish();
	xcall _MMC_finish
	.dbline 153
; 	  LCD_write(0x55,1);                    //test point
	ldi R18,1
	ldi R16,85
	xcall _LCD_write
	.dbline 154
; 	  LCD_write(mmc_response&0x93,1);       //test point
	ldi R18,1
	mov R16,R20
	andi R16,147
	xcall _LCD_write
	.dbline 155
; 	  LCD_write(0x55,1);                    //test point
	ldi R18,1
	ldi R16,85
	xcall _LCD_write
	.dbline 156
; 	  return (mmc_response&0x93);
	mov R16,R20
	andi R16,147
	.dbline -2
L37:
	adiw R28,5
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r mmc_response 20 c
	.dbend
	.dbfunc e MMC_name _MMC_name fV
;        lcd_add -> <dead>
;   mmc_response -> R20
;        counter -> R22
	.even
_MMC_name::
	xcall push_gset2
	sbiw R28,5
	.dbline -1
	.dbline 162
; 	 }				 
; 	 
; 
; /***********MMC_name();**获得卡的名字*****/
; void MMC_name(void)
;      {
	.dbline 163
; 	  unsigned char counter,lcd_add,mmc_response=1;
	ldi R20,1
	.dbline 164
; 	  mmc_response=MMC_sendCmd(MMC_SEND_CID,0,0,0,0);
	clr R2
	std y+4,R2
	std y+2,R2
	std y+0,R2
	clr R18
	ldi R16,10
	xcall _MMC_sendCmd
	mov R20,R16
	xjmp L40
L39:
	.dbline 166
	.dbline 167
	xcall _MMC_finish
	.dbline 168
	clr R2
	std y+4,R2
	std y+2,R2
	std y+0,R2
	clr R18
	ldi R16,10
	xcall _MMC_sendCmd
	mov R20,R16
	.dbline 169
	ldi R18,1
	xcall _LCD_write
	.dbline 170
	cbi 0x1b,6
	.dbline 172
L40:
	.dbline 165
; 	  while (mmc_response)                      //读到数据为0表示正常,就跳出
	tst R20
	brne L39
	.dbline 173
; 	  		{
; 			MMC_finish();
; 	  		mmc_response=MMC_sendCmd(MMC_SEND_CID,0,0,0,0);
; 			LCD_write(mmc_response,1);          //test point
; 			led1_on;         //test point
; //			prog_flag=1;     //错误标记
; 			}
; 	  led1_off;	       //test point
	sbi 0x1b,6
	.dbline 174
; 	  for (counter=0;counter<26;counter++)
	clr R22
	xjmp L45
L42:
	.dbline 175
	.dbline 176
	ldi R16,255
	xcall _SPI_tx_rx
	ldi R24,<_ram_data
	ldi R25,>_ram_data
	mov R30,R22
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R16
	.dbline 177
	ldi R18,1
	mov R30,R22
	clr R31
	add R30,R24
	adc R31,R25
	ldd R16,z+0
	xcall _LCD_write
	.dbline 178
L43:
	.dbline 174
	inc R22
L45:
	.dbline 174
	cpi R22,26
	brlo L42
	.dbline 179
; 	  	  {
; 		  ram_data[counter]=SPI_tx_rx(0xff);
; 		  LCD_write(ram_data[counter],1);        //test point
; 		  }  
; 	  MMC_flush(8);	  
	ldi R16,8
	xcall _MMC_flush
	.dbline -2
	.dbline 180
; 	 }			 
L38:
	adiw R28,5
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l lcd_add 6 c
	.dbsym r mmc_response 20 c
	.dbsym r counter 22 c
	.dbend
	.dbfunc e MMC_capactity _MMC_capactity fl
;        lcd_add -> <dead>
;   mmc_response -> R20
;        counter -> R22
	.even
_MMC_capactity::
	xcall push_gset2
	sbiw R28,5
	.dbline -1
	.dbline 185
; 	 
; /***********MMC_capactity();******************/
; unsigned long MMC_capactity(void);
; unsigned long MMC_capactity(void)
;      {
	.dbline 186
; 	  unsigned char counter,lcd_add,mmc_response=1;
	ldi R20,1
	.dbline 187
; 	  mmc_response=MMC_sendCmd(MMC_SEND_CSD,0,0,0,0);
	clr R2
	std y+4,R2
	std y+2,R2
	std y+0,R2
	clr R18
	ldi R16,9
	xcall _MMC_sendCmd
	mov R20,R16
	xjmp L48
L47:
	.dbline 189
	.dbline 190
	xcall _MMC_finish
	.dbline 191
	clr R2
	std y+4,R2
	std y+2,R2
	std y+0,R2
	clr R18
	ldi R16,10
	xcall _MMC_sendCmd
	mov R20,R16
	.dbline 192
	ldi R18,1
	xcall _LCD_write
	.dbline 193
	cbi 0x1b,6
	.dbline 195
L48:
	.dbline 188
; 	  while (mmc_response)                      //读到数据为0表示正常,就跳出
	tst R20
	brne L47
	.dbline 196
; 	  		{
; 			MMC_finish();
; 	  		mmc_response=MMC_sendCmd(MMC_SEND_CID,0,0,0,0);
; 			LCD_write(mmc_response,1);          //test point
; 			led1_on;        					 //test point
; //			prog_flag=1;    					  //错误标记
; 			}
; 	  led1_off;	  							     //test point
	sbi 0x1b,6
	.dbline 197
; 	  for (counter=0;counter<26;counter++)
	clr R22
	xjmp L53
L50:
	.dbline 198
	.dbline 199
	ldi R16,255
	xcall _SPI_tx_rx
	ldi R24,<_ram_data
	ldi R25,>_ram_data
	mov R30,R22
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R16
	.dbline 200
	ldi R18,1
	mov R30,R22
	clr R31
	add R30,R24
	adc R31,R25
	ldd R16,z+0
	xcall _LCD_write
	.dbline 201
L51:
	.dbline 197
	inc R22
L53:
	.dbline 197
	cpi R22,26
	brlo L50
	.dbline 202
; 	  	  {
; 		  ram_data[counter]=SPI_tx_rx(0xff);
; 		  LCD_write(ram_data[counter],1);        //test point
; 		  }  
; 	  MMC_flush(8);	  
	ldi R16,8
	xcall _MMC_flush
	.dbline -2
	.dbline 205
; 			
; 			
; 	 }					 
L46:
	adiw R28,5
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l lcd_add 6 c
	.dbsym r mmc_response 20 c
	.dbsym r counter 22 c
	.dbend
	.area bss(ram, con, rel)
	.dbfile G:\mega8\atmega16\mp3_7210\mmc.c
_ram_data::
	.blkb 512
	.dbsym e ram_data _ram_data A[512:512]c

⌨️ 快捷键说明

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