📄 at45db161d.lst
字号:
C51 COMPILER V7.09 AT45DB161D 09/16/2008 09:20:10 PAGE 1
C51 COMPILER V7.09, COMPILATION OF MODULE AT45DB161D
OBJECT MODULE PLACED IN .\output\at45db161d.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE usb\at45db161d.c LARGE BROWSE INCDIR(audio\;eeprom\;extendUART\;flash\;gps\
-;inter\;key\;mcu\;menu\;usb\;gprs\;main\;1wire\) DEBUG OBJECTEXTEND PRINT(.\output\at45db161d.lst) OBJECT(.\output\at45d
-b161d.obj)
line level source
1 /************************************************
2 *serial flash driver
3 *该驱动在读flash内容时不使用CS
4 *在写flash时需要使用CS
5 *NOTE:目前驱动只支持512Byte/Page
6 ************************************************/
7
8 #include "typedef.h"
9 #include "w77e532.h"
10 #include "spi.h"
11 #include "at45db161d.h"
12 #include "common_function.h"
13
14 //#define SPI_CS P1_3
15 extern Uchar volatile xdata D12_Y5;
16 extern idata Uchar D18CS;//D12_Y5的寄存器
17
18 /************cs = 0**************/
19 void spi_cson()
20 {
21 1 D18CS &= 0xfe;
22 1 D12_Y5 = D18CS;
23 1 }
24
25 /************cs = 1**************/
26 void spi_csoff()
27 {
28 1 D18CS |= 0x01;
29 1 D12_Y5 = D18CS;
30 1 }
31 /**********************
32 *在读flash时需要用到的初始化
33 **********************/
34 /*void at45_init_read()
35 {
36 spi_init();
37 }*/
38
39 /*****************************
40 *在写flash时需要用到的初始化
41 *******************************/
42 void at45_init_write()
43 {
44 1 spi_csoff();
45 1 spi_init();
46 1 }
47
48 /***************************
49 *本函数需要在命令已经输入的情况下在调用
50 ***************************/
51 void at45_readdataout(Byte nLen, Byte* pBuf)
52 {
53 1 Byte i;
C51 COMPILER V7.09 AT45DB161D 09/16/2008 09:20:10 PAGE 2
54 1 for (i=0; i<nLen; i++)
55 1 pBuf[i] = spi_read();
56 1 }
57
58 /***********************************
59 *读数据命令输入
60 *************************************/
61 /*void command_legacy_conread(Uint16 pageAddr, Uint16 byteAddr)
62 {
63 Byte addr[3];
64 Byte notCare;
65 Byte i;
66 for (i=0; i<3; i++)
67 addr[i] = 0;
68
69 //3 not care+ 12 page + 9 byte
70 pageAddr <<= 1;
71 addr[0] = ((Byte*)&pageAddr)[0];
72 addr[1] = ((Byte*)&pageAddr)[1]+((Byte*)&byteAddr)[0];
73 addr[2] = ((Byte*)&byteAddr)[1];
74
75 spi_write(READ_LEG_CONARRAY);
76 for (i=0; i<3; i++)
77 spi_write(addr[i]);
78 for (i=0; i<4; i++)
79 spi_write(notCare);
80 }*/
81
82 void command_high_conread(Uint16 pageAddr, Uint16 byteAddr)
83 {
84 1 Byte addr[3];
85 1 Byte notCare;
86 1 Byte i;
87 1 for (i=0; i<3; i++)
88 1 addr[i] = 0;
89 1
90 1 /******3 not care+ 12 page + 9 byte****************/
91 1 pageAddr <<= 1;
92 1 addr[0] = ((Byte*)&pageAddr)[0];
93 1 addr[1] = ((Byte*)&pageAddr)[1]+((Byte*)&byteAddr)[0];
94 1 addr[2] = ((Byte*)&byteAddr)[1];
95 1
96 1 spi_cson();
97 1 spi_write(READ_HIGH_CONARRAY);
98 1 for (i=0; i<3; i++)
99 1 spi_write(addr[i]);
100 1 spi_write(notCare);
101 1 }
102
103 void command_low_conread(Uint16 pageAddr, Uint16 byteAddr)
104 {
105 1 Byte addr[3];
106 1 Byte i;
107 1 for (i=0; i<3; i++)
108 1 addr[i] = 0;
109 1
110 1 /******3 not care+ 12 page + 9 byte****************/
111 1 pageAddr <<= 1;
112 1 addr[0] = ((Byte*)&pageAddr)[0];
113 1 addr[1] = ((Byte*)&pageAddr)[1]+((Byte*)&byteAddr)[0];
114 1 addr[2] = ((Byte*)&byteAddr)[1];
115 1
C51 COMPILER V7.09 AT45DB161D 09/16/2008 09:20:10 PAGE 3
116 1 spi_cson();
117 1 spi_write(READ_LOW_CONARRAY);
118 1 for (i=0; i<3; i++)
119 1 spi_write(addr[i]);
120 1 }
121
122 /***********************以下命令需要CS的支持*************/
123 /**************buffer write***************/
124 /*bufNum:1 表示要写buffer1; 2 表示要写buffer2
125 /*startAddr:要写的buf首地址
126 /*pBuf:要写入的内容
127 /*nLen:需要写入的长度
128 /******************************************/
129 /*******15+9**********/
130 void buffer_write(Byte bufNum, Uint16 startAddr, Uint16 nLen, Byte* pBuf)
131 {
132 1 Byte addr[3];
133 1 Byte command;
134 1 Uint16 i;
135 1 spi_csoff();//SPI_CS = 1;
136 1
137 1 for (i=0; i<3; i++)
138 1 addr[i] = 0;
139 1 addr[1] = ((Byte*)&startAddr)[0];
140 1 addr[2] = ((Byte*)&startAddr)[1];
141 1 if (1 == bufNum)
142 1 command = WRITE_BUF1;
143 1 else
144 1 command = WRITE_BUF2;
145 1
146 1 spi_cson();//SPI_CS = 0;
147 1 spi_write(command);
148 1 for (i=0; i<3; i++)
149 1 spi_write(addr[i]);
150 1 for (i=0; i<nLen; i++)
151 1 spi_write(pBuf[i]);
152 1 spi_csoff();//SPI_CS = 1;
153 1 SPI_CLK = 1;
154 1 }
155
156 void buffer_write_onepage(Byte bufNum, Byte* pBuf1, Byte* pBuf2, Byte* pBuf3, Byte* pBuf4)
157 {
158 1 Byte addr[3];
159 1 Byte command;
160 1 Uint16 i;
161 1 spi_csoff();//SPI_CS = 1;
162 1
163 1 for (i=0; i<3; i++)
164 1 addr[i] = 0;
165 1
166 1 if (1 == bufNum)
167 1 command = WRITE_BUF1;
168 1 else
169 1 command = WRITE_BUF2;
170 1
171 1 spi_cson();//SPI_CS = 0;
172 1 spi_write(command);
173 1 for (i=0; i<3; i++)
174 1 spi_write(addr[i]);
175 1 for (i=0; i<128; i++)
176 1 spi_write(pBuf1[i]);
177 1 for (i=0; i<128; i++)
C51 COMPILER V7.09 AT45DB161D 09/16/2008 09:20:10 PAGE 4
178 1 spi_write(pBuf2[i]);
179 1 for (i=0; i<128; i++)
180 1 spi_write(pBuf3[i]);
181 1 for (i=0; i<128; i++)
182 1 spi_write(pBuf4[i]);
183 1 spi_csoff();//SPI_CS = 1;
184 1 SPI_CLK = 1;
185 1 }
186
187 void buffer_to_mainPage_builtin(Byte bufNum, Uint16 pageAddr)
188 {
189 1 Byte addr[3];
190 1 Byte command;
191 1 Byte i;
192 1
193 1 for (i=0; i<3; i++)
194 1 addr[i] = 0;
195 1 pageAddr <<= 1;
196 1 spi_csoff();//SPI_CS = 1;
197 1
198 1 addr[0] = ((Byte*)&pageAddr)[0];
199 1 addr[1] = ((Byte*)&pageAddr)[1];
200 1 if (1 == bufNum)
201 1 command = PROGRAM_BUF1TOMAIN_IN;
202 1 else
203 1 command = PROGRAM_BUF2TOMAIN_IN;
204 1
205 1 spi_cson();//SPI_CS=0;
206 1 spi_write(command);
207 1 for (i=0; i<3; i++)
208 1 spi_write(addr[i]);
209 1 spi_csoff();//SPI_CS = 1;
210 1 SPI_CLK = 1;
211 1 //需要延迟17-40ms
212 1 delayMs(40);
213 1 }
214
215 void buffer_to_mainPage_noErase(Byte bufNum, Uint16 pageAddr)
216 {
217 1 Byte addr[3];
218 1 Byte command;
219 1 Byte i;
220 1
221 1 for (i=0; i<3; i++)
222 1 addr[i] = 0;
223 1 pageAddr <<= 1;
224 1 spi_csoff();//SPI_CS = 1;
225 1
226 1 addr[0] = ((Byte*)&pageAddr)[0];
227 1 addr[1] = ((Byte*)&pageAddr)[1];
228 1 if (1 == bufNum)
229 1 command = PROGRAM_BUF1TOMAIN_OUT;
230 1 else
231 1 command = PROGRAM_BUF2TOMAIN_OUT;
232 1
233 1 spi_cson();//SPI_CS=0;
234 1 spi_write(command);
235 1 for (i=0; i<3; i++)
236 1 spi_write(addr[i]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -