HAL.LST
资源名称:51-SD.rar [点击查看]
上传用户:jcsy2001
上传日期:2013-11-29
资源大小:201k
文件大小:10k
源码类别:
嵌入式/单片机编程
开发平台:
C/C++
- C51 COMPILER V8.02 HAL 04/29/2007 12:48:52 PAGE 1
- C51 COMPILER V8.02, COMPILATION OF MODULE HAL
- OBJECT MODULE PLACED IN HAL.OBJ
- COMPILER INVOKED BY: D:KeilC51BINC51.EXE HAL.C BROWSE DEBUG OBJECTEXTEND
- line level source
- 1 #include "common.h"
- 2 #include "HAL.H"
- 3
- 4 extern unsigned char xdata DBUF[BUFFER_LENGTH];
- 5 //============================================================
- 6 //往SD卡定一字节 www.mcusky.com
- 7 void SdWrite(unsigned char n)
- 8 {
- 9 1
- 10 1 unsigned char i;
- 11 1
- 12 1 for(i=8;i;i--)
- 13 1 {
- 14 2 SD_CLK=0;
- 15 2 SD_DI=(n&0x80);
- 16 2 n<<=1;
- 17 2 SD_CLK=1;
- 18 2 }
- 19 1 SD_DI=1;
- 20 1 }
- 21 //================================================================
- 22 //从SD卡读一字节 www.mcusky.com
- 23 unsigned char SdRead()
- 24 {
- 25 1 unsigned char n,i;
- 26 1 for(i=8;i;i--)
- 27 1 {
- 28 2 SD_CLK=0;
- 29 2 SD_CLK=1;
- 30 2 n<<=1;
- 31 2 if(SD_DO) n|=1;
- 32 2
- 33 2 }
- 34 1 return n;
- 35 1 }
- 36 //================================================================
- 37 //读SD卡响应 www.mcusky.com
- 38 unsigned char SdResponse()
- 39 {
- 40 1 unsigned char i=0,response;
- 41 1
- 42 1 while(i<=8)
- 43 1 {
- 44 2 response=SdRead();
- 45 2 if(response==0x00)
- 46 2 break;
- 47 2 if(response==0x01)
- 48 2 break;
- 49 2 i++;
- 50 2 }
- 51 1 return response;
- 52 1 }
- 53 //================================================================
- 54 void SdCommand(unsigned char command, unsigned long argument, unsigned char CRC)
- 55 {
- C51 COMPILER V8.02 HAL 04/29/2007 12:48:52 PAGE 2
- 56 1
- 57 1 SdWrite(command|0x40);
- 58 1 SdWrite(((unsigned char *)&argument)[0]);
- 59 1 SdWrite(((unsigned char *)&argument)[1]);
- 60 1 SdWrite(((unsigned char *)&argument)[2]);
- 61 1 SdWrite(((unsigned char *)&argument)[3]);
- 62 1 SdWrite(CRC);
- 63 1 }
- 64 //================================================================
- 65 unsigned char SdInit(void)
- 66 {
- 67 1 int delay=0, trials=0;
- 68 1 unsigned char i;
- 69 1 unsigned char response=0x01;
- 70 1
- 71 1 SD_CS=1;
- 72 1 for(i=0;i<=9;i++)
- 73 1 SdWrite(0xff);
- 74 1 SD_CS=0;
- 75 1
- 76 1 //Send Command 0 to put MMC in SPI mode
- 77 1 SdCommand(0x00,0,0x95);
- 78 1
- 79 1
- 80 1 response=SdResponse();
- 81 1
- 82 1 if(response!=0x01)
- 83 1 {
- 84 2 return 0;
- 85 2 }
- 86 1
- 87 1 while(response==0x01)
- 88 1 {
- 89 2 SD_CS=1;
- 90 2 SdWrite(0xff);
- 91 2 SD_CS=0;
- 92 2 SdCommand(0x01,0x00ffc000,0xff);
- 93 2 response=SdResponse();
- 94 2 }
- 95 1
- 96 1 SD_CS=1;
- 97 1 SdWrite(0xff);
- 98 1 return 1;
- 99 1 }
- 100 //================================================================
- 101 unsigned char SdWriteBlock(unsigned char *Block, unsigned long address)
- 102 {
- 103 1 unsigned char count;
- 104 1 unsigned char dataResp;
- 105 1 //Block size is 512 bytes exactly
- 106 1 //First Lower SS
- 107 1
- 108 1 SD_CS=0;
- 109 1 //Then send write command
- 110 1 SdCommand(0x18,address,0xff);
- 111 1
- 112 1 if(SdResponse()==00)
- 113 1 {
- 114 2 SdWrite(0xff);
- 115 2 SdWrite(0xff);
- 116 2 SdWrite(0xff);
- 117 2 //command was a success - now send data
- C51 COMPILER V8.02 HAL 04/29/2007 12:48:52 PAGE 3
- 118 2 //start with DATA TOKEN = 0xFE
- 119 2 SdWrite(0xfe);
- 120 2 //now send data
- 121 2 for(count=0;count<128;count++)
- 122 2 {
- 123 3 SdWrite(*Block++);
- 124 3 SdWrite(*Block++);
- 125 3 SdWrite(*Block++);
- 126 3 SdWrite(*Block++);
- 127 3 }
- 128 2 //data block sent - now send checksum
- 129 2 SdWrite(0xff);
- 130 2 SdWrite(0xff);
- 131 2 //Now read in the DATA RESPONSE token
- 132 2 dataResp=SdRead();
- 133 2 //Following the DATA RESPONSE token
- 134 2 //are a number of BUSY bytes
- 135 2 //a zero byte indicates the MMC is busy
- 136 2
- 137 2 while(SdRead()==0);
- 138 2
- 139 2 dataResp=dataResp&0x0f; //mask the high byte of the DATA RESPONSE token
- 140 2 SD_CS=1;
- 141 2 SdWrite(0xff);
- 142 2 if(dataResp==0x0b)
- 143 2 {
- 144 3 //printf("DATA WAS NOT ACCEPTED BY CARD -- CRC ERRORn");
- 145 3 return 0;
- 146 3 }
- 147 2 if(dataResp==0x05)
- 148 2 return 1;
- 149 2
- 150 2 //printf("Invalid data Response token.n");
- 151 2 return 0;
- 152 2 }
- 153 1 //printf("Command 0x18 (Write) was not received by the MMC.n");
- 154 1 return 0;
- 155 1 }
- 156 //=======================================================================
- 157 unsigned char SdReadBlock(unsigned char *Block, unsigned long address)
- 158 {
- 159 1 unsigned char count;
- 160 1 //Block size is 512 bytes exactly
- 161 1 //First Lower SS
- 162 1
- 163 1 // printf("MMC_read_blockn");
- 164 1
- 165 1 SD_CS=0;
- 166 1 //Then send write command
- 167 1 SdCommand(0x11,address,0xff);
- 168 1
- 169 1 if(SdResponse()==00)
- 170 1 {
- 171 2 //command was a success - now send data
- 172 2 //start with DATA TOKEN = 0xFE
- 173 2 while(SdRead()!=0xfe);
- 174 2
- 175 2 for(count=0;count<128;count++)
- 176 2 {
- 177 3 *Block++=SdRead();
- 178 3 *Block++=SdRead();
- 179 3 *Block++=SdRead();
- C51 COMPILER V8.02 HAL 04/29/2007 12:48:52 PAGE 4
- 180 3 *Block++=SdRead();
- 181 3 }
- 182 2 //data block sent - now send checksum
- 183 2 SdRead();
- 184 2 SdRead();
- 185 2 //Now read in the DATA RESPONSE token
- 186 2 SD_CS=1;
- 187 2 SdRead();
- 188 2 return 1;
- 189 2 }
- 190 1 // printf("Command 0x11 (Read) was not received by the MMC.n");
- 191 1 return 0;
- 192 1 }
- 193 //================================================================
- 194 void ComSendByte(unsigned char c)
- 195 {
- 196 1 SBUF=c;
- 197 1 while(!TI);
- 198 1 TI=0;
- 199 1 }
- 200 //================================================================
- 201 void DelayMs(unsigned char nFactor)
- 202 {
- 203 1 return;
- 204 1 /*
- 205 1 unsigned char i;
- 206 1 unsigned int j;
- 207 1
- 208 1 for(i=0; i<nFactor; i++)
- 209 1 {
- 210 1 for(j=0;j<1000;j++)
- 211 1 j=j;
- 212 1 }
- 213 1 */
- 214 1 }
- *** WARNING C280 IN LINE 201 OF HAL.C: 'nFactor': unreferenced local variable
- 215
- 216 unsigned int LSwapINT16(unsigned short dData1,unsigned short dData2)
- 217 {
- 218 1 unsigned int xdata dData;
- 219 1 dData = ((dData2<<8)&0xff00)|(dData1&0x00ff);
- 220 1 return dData;
- 221 1 }
- 222
- 223 unsigned long LSwapINT32(unsigned long dData1,unsigned long dData2,unsigned long dData3,unsigned long dDat
- -a4)
- 224 {
- 225 1 unsigned long xdata dData;
- 226 1 dData = ((dData4<<24)&0xff000000)|((dData3<<16)&0xff0000)|((dData2<<8)&0xff00)|(dData1&0xff);
- 227 1 return dData;
- 228 1 }
- 229
- MODULE INFORMATION: STATIC OVERLAYABLE
- CODE SIZE = 671 ----
- CONSTANT SIZE = ---- ----
- XDATA SIZE = ---- 6
- PDATA SIZE = ---- ----
- DATA SIZE = ---- 41
- IDATA SIZE = ---- ----
- BIT SIZE = ---- ----
- C51 COMPILER V8.02 HAL 04/29/2007 12:48:52 PAGE 5
- END OF MODULE INFORMATION.
- C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)