?? f411_vr_sstflash.lst
字號(hào):
C51 COMPILER V7.06 F411_VR_SSTFLASH 02/18/2009 16:30:51 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE F411_VR_SSTFLASH
OBJECT MODULE PLACED IN F411_VR_SSTFlash.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE F411_VR_SSTFlash.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 //-----------------------------------------------------------------------------
2 // F411_VR_SSTFlash.c
3 //-----------------------------------------------------------------------------
4 // Copyright 2006 Silicon Laboratories, Inc.
5 // http://www.silabs.com
6 //
7 // Program Description:
8 //
9 // This file contains the interfacing functions to the SST Flash, allowing the
10 // user to Read memory, Write memory, and Erase memory.
11 //
12 // How To Use: See Readme.txt
13 //
14 // FID: 41X000010
15 // Target: C8051F411
16 // Tool chain: Keil C51 7.50 / Keil EVAL C51
17 // Silicon Laboratories IDE version 2.6
18 // Project Name: F411_VR
19 //
20 // Release 1.3
21 // -All changes by TP
22 // -02 Feb 2006
23 // -added Read_MEM_Init (duplicate of Read_MEM) to avoid
24 // the compiler warning (multiple calls to segment)
25 //
26 // Release 1.2
27 // -All changes by TP
28 // -21 Nov 2005
29 // -project version updated, no changes to this file.
30 //
31 // Release 1.1
32 // -All changes by TP
33 // -16 Aug 2004
34 // -added SPIF polling while sending the WREN command
35 //
36 // Release 1.0
37 // -Initial Revision (TP)
38 // -15 AUG 2004
39 //
40
41 //-----------------------------------------------------------------------------
42 // Includes
43 //-----------------------------------------------------------------------------
44 #include <c8051f410.h> // SFR declarations
45
46 //-----------------------------------------------------------------------------
47 // Global CONSTANTS
48 //-----------------------------------------------------------------------------
49 // SST Instruction Opcodes (as shown in the datasheet)
50 #define EWSR 0x50 // enable write status register
51 #define WRSR 0x01 // write status register
52 #define RDSR 0x05 // read status register
53 #define WREN 0x06 // write enable
54 #define BPROG 0x02 // byte program
55 #define READ 0x03 // read
C51 COMPILER V7.06 F411_VR_SSTFLASH 02/18/2009 16:30:51 PAGE 2
56 #define CERASE 0x60 // chip erase
57 #define READID 0x90 // chip ID
58
59 // Address definition
60 typedef union ADDRESS { // access an address as a
61 unsigned long ULong; // unsigned long variable or
62 unsigned char UByte[4]; // 4 unsigned byte variables
63 // [0] = A31-24, [1] = A23-16, [2] = A15-8, [3] = A7-0
64 } ADDRESS;
65
66 //-----------------------------------------------------------------------------
67 // Function PROTOTYPES
68 //-----------------------------------------------------------------------------
69 void SSTFlash_Init (void);
70
71 void Write_MEM (unsigned long address, unsigned char data_byte);
72 unsigned char Read_MEM (unsigned long address);
73 void Erase_MEM (void);
74 char ReadID_MEM (void);
75
76 //-----------------------------------------------------------------------------
77 // SSTFlash_Init
78 //-----------------------------------------------------------------------------
79 //
80 // Return Value : None
81 // Parameters : None
82 //
83 // Unprotect the memory so that all of memory may be written and read.
84 // NOTE: The SPI must be initialized before this function is called.
85 //
86 void SSTFlash_Init (void)
87 {
88 1 NSSMD0 = 0; // enable the flash
89 1
90 1 // send the enable write status register command
91 1 SPI0DAT = EWSR; // load the XMIT register
92 1 while (TXBMT != 1) // wait until EWSR command is moved into
93 1 { // the XMIT buffer
94 2 }
95 1 SPIF = 0;
96 1 while (SPIF != 1) // wait until the SPI finishes sending
97 1 { // the EWSR command to the flash
98 2 }
99 1 SPIF = 0;
100 1
101 1 NSSMD0 = 1; // allow the command to execute
102 1
103 1 NSSMD0 = 0; // enable the flash
104 1
105 1 // send the write status register command and clear the BP bits
106 1 SPI0DAT = WRSR; // load the XMIT register
107 1 while (TXBMT != 1) // wait until the XMIT register can
108 1 { // accept more data
109 2 }
110 1 SPI0DAT = 0x00; // set the block protection bits to 0
111 1 while (TXBMT != 1) // wait until the data is moved into
112 1 { // the XMIT buffer
113 2 }
114 1 SPIF = 0;
115 1 while (SPIF != 1) // wait until the SPI finishes sending
116 1 { // the data to the flash
117 2 }
C51 COMPILER V7.06 F411_VR_SSTFLASH 02/18/2009 16:30:51 PAGE 3
118 1 SPIF = 0;
119 1
120 1 NSSMD0 = 1; // allow the command to execute
121 1 }
122
123 //-----------------------------------------------------------------------------
124 // Write_MEM
125 //-----------------------------------------------------------------------------
126 //
127 // Return Value : None
128 // Parameters :
129 // 1) long address - address in the 512 kB external SST Flash
130 // range is postive values up to 2^19: 0 to 524287,
131 // or, 0 to 0x7FFFF
132 // 2) char data_byte - the data to be written to memory
133 // range is positive range of character: 0 to 255
134 //
135 // Write one byte of data to a 24-bit address in the SST Flash Memory using
136 // the SPI.
137 //
138 void Write_MEM (unsigned long address, unsigned char data_byte)
139 {
140 1 ADDRESS temp_addr;
141 1 temp_addr.ULong = address;
142 1
143 1 NSSMD0 = 0; // enable the flash
144 1
145 1 // send the write enable command
146 1 SPI0DAT = WREN; // load the XMIT register
147 1 while (TXBMT != 1) // wait until the command is moved into
148 1 { // the XMIT buffer
149 2 }
150 1 SPIF = 0;
151 1 while (SPIF != 1) // wait until the command reaches the
152 1 { // flash
153 2 }
154 1 SPIF = 0;
155 1
156 1 NSSMD0 = 1; // allow the WREN to execute
157 1
158 1 NSSMD0 = 0; // enable the flash
159 1
160 1 // send the byte-program command
161 1 SPI0DAT = BPROG; // load the XMIT register
162 1 while (TXBMT != 1) // wait until the command is moved into
163 1 { // the XMIT buffer
164 2 }
165 1 SPI0DAT = temp_addr.UByte[1]; // load the high byte of the address
166 1 while (TXBMT != 1) // wait until the addr is moved into
167 1 { // the XMIT buffer
168 2 }
169 1 SPI0DAT = temp_addr.UByte[2]; // load the middle byte of the address
170 1 while (TXBMT != 1) // wait until the addr is moved into
171 1 { // the XMIT buffer
172 2 }
173 1 SPI0DAT = temp_addr.UByte[3]; // load the low byte of the address
174 1 while (TXBMT != 1) // wait until the addr is moved into
175 1 { // the XMIT buffer
176 2 }
177 1 SPI0DAT = data_byte; // load the byte of data
178 1 while (TXBMT != 1) // wait until the data is moved into
179 1 { // the XMIT buffer
C51 COMPILER V7.06 F411_VR_SSTFLASH 02/18/2009 16:30:51 PAGE 4
180 2 }
181 1 SPIF = 0;
182 1 while (SPIF != 1) // wait until the last byte of the
183 1 { // write instruction reaches the flash
184 2 }
185 1 SPIF = 0;
186 1
187 1 NSSMD0 = 1; // allow the WR instruction to execute
188 1 }
189
190 //-----------------------------------------------------------------------------
191 // Read_MEM
192 //-----------------------------------------------------------------------------
193 //
194 // Return Value :
195 // 1) char data_byte - the data byte read from memory
196 // range is positive range of character: 0 to 255
197 // Parameters :
198 // 1) long address - address in the 512 kB external SST Flash
199 // range is postive values up to 2^19: 0 to 524287,
200 // or, 0 to 0x7FFFF
201 //
202 // Read one byte of data from a 24-bit address in the SST Flash Memory using
203 // the SPI.
204 //
205 unsigned char Read_MEM (unsigned long address)
206 {
207 1 ADDRESS temp_addr;
208 1 temp_addr.ULong = address;
209 1
210 1 NSSMD0 = 0; // enable the flash
211 1
212 1 // send the read instruction
213 1 SPI0DAT = READ; // load the XMIT register
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -