📄 sst_spi_w25x.lst
字号:
137 1 SPI_Send_Byte(0xFF); // dummy byte
138 1 for (i = 0; i < nBytes_128; i++) // read until no_bytes is reached
139 1 upper_128[i] = SPI_Get_Byte(); // receive byte and store at address 80H - FFH
140 1 W25X_CS = 1; // disable device
141 1 }
142 void SPI_Write_Byte(uint32 Dst_Addr, uchar byte)
143 { W25X_CS = 0; // enable device
144 1 SPI_Write_Enable(); // set WEL
145 1 SPI_Wait_Busy();
146 1 W25X_CS = 0;
147 1 SPI_Send_Byte(W25X_PageProgram); // send Byte Program command
148 1 SPI_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16)); // send 3 address bytes
149 1 SPI_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
150 1 SPI_Send_Byte(Dst_Addr & 0xFF);
151 1 SPI_Send_Byte(byte); // send byte to be programmed
152 1 W25X_CS = 1; // disable device
153 1 }
154 void SPI_Write_nBytes(uint32 Dst_Addr, uchar nBytes_128)
155 {
156 1 uchar i, byte;
157 1 W25X_CS = 0; /* enable device */
158 1 SPI_Write_Enable(); /* set WEL */
159 1 W25X_CS = 0;
160 1 SPI_Send_Byte(W25X_PageProgram); /* send Byte Program command */
161 1 SPI_Send_Byte(((Dst_Addr & 0xFFFFFF) >> 16)); /* send 3 address bytes */
162 1 SPI_Send_Byte(((Dst_Addr & 0xFFFF) >> 8));
163 1 SPI_Send_Byte(Dst_Addr & 0xFF);
164 1
165 1 for (i = 0; i < nBytes_128; i++)
166 1 {
167 2 byte = upper_128[i];
168 2 SPI_Send_Byte(byte); /* send byte to be programmed */
169 2 }
170 1 W25X_CS = 1; /* disable device */
171 1 }
172 void SPI_Erase_Chip()
173 {
174 1 W25X_CS = 0; // enable device
175 1 SPI_Write_Enable(); // set WEL
176 1 W25X_CS = 0;
177 1 SPI_Wait_Busy();
178 1 W25X_CS = 0;
179 1 SPI_Send_Byte(W25X_ChipErase); // send Chip Erase command
C51 COMPILER V7.50 SST_SPI_W25X 01/12/2009 23:18:17 PAGE 4
180 1 W25X_CS = 1; // disable device
181 1 }
182 void SPI_Erase_Sector(uint32 Dst_Addr)
183 { W25X_CS = 0; // enable device
184 1 SPI_Write_Enable(); // set WEL
185 1 W25X_CS = 0;
186 1 SPI_Send_Byte(W25X_SectorErase); // send Sector Erase command
187 1 SPI_Send_Byte((uchar)((Dst_Addr & 0xFFFFFF) >> 16));// send 3 address bytes
188 1 SPI_Send_Byte((uchar)((Dst_Addr & 0xFFFF) >> 8));
189 1 SPI_Send_Byte((uchar)Dst_Addr & 0xFF);
190 1 W25X_CS = 1; // disable device
191 1 }
192 void SPI_Wait_Busy()
193 { while (SPI_Read_StatusReg() == 0x03)
194 1 SPI_Read_StatusReg(); // waste time until not busy WEL & Busy bit all be 1 (0x03)
195 1 }
196 void SPI_PowerDown()
197 { W25X_CS = 0; // enable device
198 1 SPI_Send_Byte(W25X_PowerDown); // send W25X_PowerDown command 0xB9
199 1 W25X_CS = 1; // disable device
200 1 delay(6); // remain CS high for tPD = 3uS
201 1 }
202 void SPI_ReleasePowerDown()
203 { W25X_CS = 0; // enable device
204 1 SPI_Send_Byte(W25X_ReleasePowerDown); // send W25X_PowerDown command 0xAB
205 1 W25X_CS = 1; // disable device
206 1 delay(6); // remain CS high for tRES1 = 3uS
207 1 }
208
209
210
211 #ifdef SST_SPI
212 void SPI_init()
213 { P1 = 0xFF;
214 1 SPCR = 0x50;
215 1 }
216 void SPI_Send_Byte(uchar out)
217 { unsigned char temp;
218 1 SPDR = out;
219 1 do { temp = SPSR & 0x80; } while (temp != 0x80);
220 1 SPSR = SPSR & 0x7F;
221 1 }
222 uchar SPI_Get_Byte()
223 { unsigned char temp;
224 1 SPDR = 0x00;
225 1 do { temp = SPSR & 0x80; } while (temp != 0x80);
226 1 SPSR = SPSR & 0x7F;
227 1 return SPDR;
228 1 }
229 #endif
230
231 #ifndef SST_SPI
void SPI_init()
{ W25X_CLK = 0; // set clock to low initial state for SPI operation mode 0
// W25X_CLK = 1; // set clock to High initial state for SPI operation mode 3
// _hold = 1;
W25X_WP = 1;
W25X_CS = 1;
SPI_Write_Disable();
}
void SPI_Send_Byte(uchar out)
{ uchar i = 0;
C51 COMPILER V7.50 SST_SPI_W25X 01/12/2009 23:18:17 PAGE 5
for (i = 0; i < 8; i++)
{ if ((out & 0x80) == 0x80) // check if MSB is high
W25X_DI = 1;
else
W25X_DI = 0; // if not, set to low
W25X_CLK = 1; // toggle clock high
out = (out << 1); // shift 1 place for next bit
nop();nop();nop();nop();
W25X_CLK = 0; // toggle clock low
}
}
uchar SPI_Get_Byte()
{ uchar i = 0, in = 0, temp = 0;
for (i = 0; i < 8; i++)
{ in = (in << 1); // shift 1 place to the left or shift in 0
temp = W25X_DO; // save input
W25X_CLK = 1; // toggle clock high
if (temp == 1) // check to see if bit is high
in |= 0x01; // if high, make bit high
W25X_CLK = 0; // toggle clock low
}
return in;
}
#endif
266 //=================================================================================================
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 828 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 46
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -