|
|
EC挂接8Mbit SST25VF080B的话,可参考和学习,其它的SPI FLASH雷同。- Software Driver. R1 k" m b0 e i* w4 q! t- u
1 _: C* v6 x2 k7 | ~- SST25VF080B 8 Mbit(1M x 8) Serial Flash Memory
: E9 \+ _! X# F' [# K/ e/ | - % L( f& J, ?" W, N. W, m T9 ]
- November 4th, 2005, Rev. 1.02 p5 e5 D! M7 H; w3 N/ t$ Q
- 3 Y* n- p4 l0 ?0 d3 m6 g
- ABOUT THE SOFTWARE* j/ m' A6 M; S$ m
- This application note provides software driver examples for SST25VF080B,
2 m8 e7 u# ?2 ], A: L3 J0 P - Serial Flash. Extensive comments are included in each routine to describe
x0 F8 C3 B' E9 i& ~ - the function of each routine. The interface coding uses polling method
; [2 s- N1 Z; a* c+ Y - rather than the SPI protocol to interface with these serial devices. The! m: ?: L" i. A( N/ j0 Y8 Y+ }
- functions are differentiated below in terms of the communication protocols
, m8 j" f2 N( {# k* d" m - (uses Mode 0) and specific device operation instructions. This code has been 5 x! j% `: J# N
- designed to compile using the Keil compiler.
6 O! j; c. i- V; S! j- K1 E3 p/ f( W5 X/ I
" I4 K3 e0 _, s, _* |5 ^5 m
8 z. i* L! @6 y2 C+ _- ABOUT THE SST25VF080B" [ X/ H4 _' a9 t2 Y; \
3 C1 ~& ^* Z R$ h% u) K- Companion product datasheets for the SST25VF080B should be reviewed in # ^) [! W8 n9 K# S0 `9 c
- conjunction with this application note for a complete understanding 6 L( B* F2 K( t9 H
- of the device./ S. Q) M4 m' f7 U5 d& s; p# Y1 U
- ' D, h0 e3 ~. ` t3 Y
2 \9 v$ c6 F0 {* ~: i- Device Communication Protocol(pinout related) functions:
4 J7 K' \) r! Q6 E/ f$ R
( m; E9 z# f2 n$ ] r4 e: B: \- Functions Function
/ E* m# I4 P( g" E6 K - ------------------------------------------------------------------
' `. u& X& Q! L E - init Initializes clock to set up mode 0.
1 }/ @1 e; b d7 M9 U - Send_Byte Sends one byte using SI pin to send and
/ e% r, A: P. C, G: `! e - shift out 1-bit per clock rising edge
$ H8 V; Y8 ]4 r) e8 b! C8 [ - Get_Byte Receives one byte using SO pin to receive and shift
7 g) a* c& T" |: ~ - in 1-bit per clock falling edge
9 A; r8 q- C% o0 b, Z; R: U - Poll_SO Used in the polling for RY/BY# of SO during AAI programming
3 T+ G- J1 F- x, C1 V: H - CE_High Sets Chip Enable pin of the serial flash to high
: W8 D6 h- B% F( O3 @# z9 U! _- o - CE_Low Clears Chip Enable of the serial flash to low
& l: x8 R; P# p9 j+ ? - Hold_Low Clears Hold pin to make serial flash hold5 T& E/ F6 `+ s
- Unhold Unholds the serial flash5 t) Q7 r% R; V. ~* ?
- WP_Low Clears WP pin to make serial flash write protected
& I$ ]) {9 ~' g' B - UnWP Disables write protection pin
, O5 d: r8 a; g) X: q/ P - ; I$ B4 c; F, n7 ?1 ]- F# Y
- Note: The pin names of the SST25VF080B are used in this application note. The associated test code% r- F m) K) }' D' W, Z2 f C
- will not compile unless these pinouts (SCK, SI, SO, SO, CE, WP, Hold) are pre-defined on your9 M+ L3 h6 f8 y1 ^3 o& V
- software which should reflect your hardware interfaced.
2 k% G! s. x/ d4 j
! l% k( ?5 `* F$ U2 y H. R- ( D3 m9 q" g( }! V9 A7 `
- Device Operation Instruction functions:
, @. e# q# e7 m) f
" h8 l9 r0 e2 v4 l6 S- Functions Function0 ~+ L1 q$ V1 g$ p/ Y# |
- ------------------------------------------------------------------8 L+ j/ @' y; r
- Read_Status_Register Reads the status register of the serial flash
, v3 @) `& O o2 j3 v - EWSR Enables the Write Status Register
% i( P1 s4 c0 p- ~ - WRSR Performs a write to the status register
2 n* @% @+ Y8 j3 i: \9 _- ? - WREN Write enables the serial flash
3 i1 g2 d4 t: O& l. E/ a - WRDI Write disables the serial flash
1 Z. ^8 L8 x* W2 [5 P - EBSY Enable SO to output RY/BY# status during AAI programming
* e+ A; B" G# W U$ d - DBSY Disable SO to output RY/BY# status during AAI programming$ s0 d- h% ^ M0 I
- Read_ID Reads the manufacturer ID and device ID
' c4 n$ ?3 `; O- E5 h. a" K - Jedec_ID_Read Reads the Jedec ID2 r. j( c9 h1 H/ m- a
- Read Reads one byte from the serial flash and returns byte(max of 25 MHz CLK frequency)4 p* W- u. s/ k) B
- Read_Cont Reads multiple bytes(max of 25 MHz CLK frequency), F6 ]3 K# p3 V) |6 g! s; }
- HighSpeed_Read Reads one byte from the serial flash and returns byte(max of 50 MHz CLK frequency)' a! k0 S( c) n; o
- HighSpeed_Read_Cont Reads multiple bytes(max of 50 MHz CLK frequency): B) T3 D$ D0 p: L7 }
- Byte_Program Program one byte to the serial flash7 T, i# {4 ^* Q) c
- Auto_Add_IncA Initial Auto Address Increment process" [! x+ |7 {0 L) t5 i# }
- Auto_Add_IncB Successive Auto_Address_Increment process after AAI initiation: E, f# a+ O6 S6 M4 h Y
- Auto_Add_IncA_EBSY Initial Auto Address Increment process with EBSY
) O4 j$ ~7 |+ h - Auto_Add_IncB_EBSY Successive Auto_Address_Increment process after AAI initiation with EBSY and WRDI/DBSY
y: t4 O: p' B, T9 a' K - Chip_Erase Erases entire serial flash
( m u3 T! Z$ f: o8 a9 p$ ~ - Sector_Erase Erases one sector (4 KB) of the serial flash
. r, W }. N4 [0 g7 F - Block_Erase_32K Erases 32 KByte block memory of the serial flash% o1 Q6 Z, e$ H% m. q* N
- Block_Erase_64K Erases 64 KByte block memory of the serial flash, k& ^# h: \+ k; l9 G# o
- Wait_Busy Polls status register until busy bit is low
6 p8 ]2 i$ p8 {- @1 c$ M. | - Wait_Busy_AAI Polls status register until busy bit is low for AAI programming8 o+ j" B9 n; u) |: D
- WREN_Check Checks to see if WEL is set4 p+ m0 S3 g- O6 w
- WREN_AAI_Check Checks to see if WEL and AAI mode is set; x% Z- o6 ~. n) l
4 z% r! t C1 Q' g& m5 Q& K
! j; w8 [) }- ]& S( G7 |5 e- ! u, H* ~( \; Q3 v: i
-
8 U- p3 b3 p9 V- K, T" _! \* q - "C" LANGUAGE DRIVERS D( t1 C1 N- ^' p+ I
- 8 ^" h! J/ C7 `+ o( G
- /********************************************************************/. v# c0 m. J5 K# C* j1 u |) l, {
- /* Copyright Silicon Storage Technology, Inc. (SST), 1994-2005 */: |. l e h. t/ N! n+ }4 s( h3 }
- /* Example "C" language Driver of SST25VF080B Serial Flash */. h) g' G( l# a5 h2 u& V0 N
- /* Conrado Canio, Silicon Storage Technology, Inc. */) E0 ]" ]- v1 i- b2 Y, C/ j. l, o
- /* */$ N0 C( }+ n* q ?+ M4 z% E( J
- /* Revision 1.0, November 4th, 2005 */ 7 R1 x* M! c/ H9 N3 H! k9 M
- /* */: L+ x( k( W0 p( T
- /* */: N7 q6 M. n( {7 m2 k' @
- /********************************************************************/
$ U5 ~3 r9 Q" @; v. o. t. Y' U
% |- |: U+ @' B: G' `- #include <stdio.h>/ U7 y2 S- w4 _
- #include <stdlib.h>
# @6 u( x( i5 a3 m
( |, i$ `9 ~/ j0 I- /* Function Prototypes */* V" K' s- ?# }/ g+ n0 B
8 Q, G) ]' `5 i B5 J) I- void init();/ e. a2 N( W; ]# Y7 M
- void Send_Byte(unsigned char out);
" [! Q J7 @# g2 P+ I - unsigned char Get_Byte();
1 O/ }) g* a- S& H, r$ e: f6 J& L - void Poll_SO();
2 P& I) P# G0 r - void CE_High();9 {7 |+ V. f3 N
- void CE_Low();
! j( a6 F6 Z r9 X6 B0 M - void Hold_Low();- t1 H: B, Z! Y! _* k" C( h
- void Unhold();# x* [2 a# h$ x4 \
- void WP_Low();4 G! H, g0 ?( H" c5 Q
- void UnWP();; e2 C7 N; L5 m' v8 G0 R7 s
- unsigned char Read_Status_Register();
4 \! C+ t/ Y0 b7 y7 l1 v9 ^ - void EWSR();8 X6 J1 a' K# M+ c, [2 L9 ]8 s$ \
- void WRSR(byte);
# F! n) s/ V& e" ` - void WREN();
4 P, }: L. x% p" v* Y1 l. N9 U - void WRDI();9 R' v4 z7 z2 e& O
- void EBSY();
: |9 ` t. d3 u% u4 v. H - void DBSY();' a" k2 ^. [% w% S. n d
- unsigned char Read_ID(ID_addr);2 i7 M! X' m" C
- unsigned long Jedec_ID_Read(); / C: E9 c! t7 }4 X
- unsigned char Read(unsigned long Dst);
* U9 ?3 m9 L1 q* g- S - void Read_Cont(unsigned long Dst, unsigned long no_bytes);
# T3 N% Q+ p. |- R+ _* @% l - unsigned char HighSpeed_Read(unsigned long Dst); 5 {& T) _: R" x" u
- void HighSpeed_Read_Cont(unsigned long Dst, unsigned long no_bytes);2 Z: r5 A) R" |: E2 Q" g6 {
- void Byte_Program(unsigned long Dst, unsigned char byte);
3 g5 {4 G$ k, T1 n) Z - void Auto_Add_IncA(unsigned long Dst, unsigned char byte1, unsigned char byte2);
7 g/ a2 b q4 O( S; F2 r5 R/ I - void Auto_Add_IncB(unsigned char byte1, unsigned char byte2);
3 t/ w- M ?! F9 `7 d - void Auto_Add_IncA_EBSY(unsigned long Dst, unsigned char byte1, unsigned char byte2);
4 S6 X, T1 r4 |% T - void Auto_Add_IncB_EBSY(unsigned char byte1, unsigned char byte2);5 y6 W/ A( _; ~; {7 t
- void Chip_Erase();) A) o% E q3 L/ Y J
- void Sector_Erase(unsigned long Dst);; ^3 O! g$ f) N) [
- void Block_Erase_32K(unsigned long Dst);# s3 c( C$ `' ~- l F
- void Block_Erase_64K(unsigned long Dst);
' X" s, y% l. N( i% t: b - void Wait_Busy();* E4 a9 F4 r; Y& N4 }0 E: K
- void Wait_Busy_AAI();9 v. ~$ j: {& J) r: \
- void WREN_Check();
8 n. ?0 ~% N7 N1 k' s - void WREN_AAI_Check();
( Q5 u- [2 q' C$ U! ] - & n; H' f$ v7 F2 I! P( |$ C4 u* o
- void Verify(unsigned char byte, unsigned char cor_byte);/ O2 x! N, ~/ O* d7 ]5 r l/ `& |$ Q
- ) ]" J4 ?1 l! X) H, [
- unsigned char idata upper_128[128]; /* global array to store read data */% M$ b) H; o5 Z' C, j N; L% I( I
- /* to upper RAM area from 80H - FFH */
: \7 n1 K/ z/ r" ]( g0 ]& \' q1 \
0 V- X/ y9 ^0 ^5 [' z: U$ r- /************************************************************************/ y8 R4 e: F5 h
- /* PROCEDURE: init */& N$ A# k- ]$ ~: c3 F
- /* */* ] T# \. ]9 E, C4 Q/ X2 F( B
- /* This procedure initializes the SCK to low. Must be called prior to */' ?: |+ h. Z$ F
- /* setting up mode 0. */
3 ^# G4 o& y6 O& M1 A* q: ]5 K a - /* */
I& ~ U$ p3 n/ L4 T7 Z( M - /* Input: */
$ j* r q: f' d) L% u7 j$ m- f/ F - /* None */
' P1 w! w q u9 @: d4 L - /* */
& H* _& T+ W' I7 W/ O" j7 r - /* Output: */ i) \& Q0 o0 o8 k' W& u/ X
- /* SCK */
D' r* l0 b: V( } - /************************************************************************/- t0 i: J5 O; ^, @' q
- void init()
# j$ l8 D8 Q" _! `) b5 G% x - {, f6 ?: o1 p9 o9 \
- SCK = 0; /* set clock to low initial state */
- c; _$ I1 w" F; H' [4 w! \ - }. X, d* A( t9 }1 m7 f
3 J" Z+ L+ C. W. ]) o3 h( E4 T- /************************************************************************/
& ~! [; b& n. m0 S% H* _ - /* PROCEDURE: Send_Byte */; \, u6 N U1 X- m8 @1 ?
- /* *// u# }2 i! y; Q `) E
- /* This procedure outputs a byte shifting out 1-bit per clock rising */6 r" a# I' R+ q! X0 j6 ?- i
- /* edge on the the SI pin(LSB 1st). */& C' q/ r( V/ X1 D! {
- /* */ E) h( r/ u S v2 w7 m J+ V
- /* Input: *// f( o+ ^: u+ j' T2 I# Y1 J! o
- /* out */
1 `- M6 K; u7 p# @# b/ E5 D - /* */
' }7 \& S) J- x1 C( H - /* Output: */
: Y3 a% d* o- \0 H8 ?% b3 f - /* SI */
; j3 ]7 h( Q$ B8 D8 Y! e* m% U - /************************************************************************/
% ? D$ w! E- p- r0 c - void Send_Byte(unsigned char out)
; z" g$ V$ h" q* J* {% X. Y - {
! \; I5 y0 Q9 Z: t t - U9 }& X9 B0 k4 t, x3 _
- unsigned char i = 0;
( | L9 j% L0 @4 L% i - for (i = 0; i < 8; i++)
$ m+ k1 d3 N8 `8 J# L [7 F1 V - {
0 A) G: G. L2 U7 c% K4 e! d6 f -
( {0 {" L& ?* E- [" g - if ((out & 0x80) == 0x80) /* check if MSB is high */' ]& ?( j3 {; {- r
- SI = 1;% a; {8 h/ {! i; j2 S* y& m
- else* U0 W! L3 U9 ^
- SI = 0; /* if not, set to low */
3 j7 N4 \% P. G6 s - SCK = 1; /* toggle clock high */) w9 C, r. N5 I! X+ T j
- out = (out << 1); /* shift 1 place for next bit */! d! X% k% }8 n+ J; Y2 z
- SCK = 0; /* toggle clock low */
( X2 D" f6 v+ B6 `7 O - }
* O% y6 v& X+ v* t% R8 o1 x! B - }' b* `5 T$ i. w) u( c
. Y# _. } T7 }- P. R- /************************************************************************/2 X4 g% j& f. |6 L* u6 S0 h) _
- /* PROCEDURE: Get_Byte */
+ V; h8 m0 z5 e; Q8 G - /* */
( r1 `- U+ [: l5 L2 y, o0 W - /* This procedure inputs a byte shifting in 1-bit per clock falling */3 F+ e1 S: k4 `( U3 L- s
- /* edge on the SO pin(LSB 1st). */& W: V Q( C% G& {8 B8 n) P
- /* */8 s9 T1 ~* b: g
- /* Input: */
3 n' z3 a2 E* r4 a! j - /* SO */9 A& K- M) l P! G
- /* */ N2 ]" y8 b! M; w0 Y; f" M, n7 s
- /* Output: */
; ^# J% I8 P9 M2 y. V - /* None */
" T. ]+ B4 K8 t5 s - /************************************************************************/
0 F/ n( U' s. o$ H - unsigned char Get_Byte()9 S7 z' B3 x+ g) v
- {
8 s& V1 R9 P* r# R$ t - unsigned char i = 0, in = 0, temp = 0;7 w k: M* a6 s& v
- for (i = 0; i < 8; i++)
" a8 o7 `- c5 h6 W0 ` - {! V; p* E1 F" B
- in = (in << 1); /* shift 1 place to the left or shift in 0 */
6 g% X% F/ Q$ g8 S - temp = SO; /* save input */- j8 q4 U: g7 C1 C% l. T
- SCK = 1; /* toggle clock high */9 K) T) Y. u8 M3 u" L+ ~
- if (temp == 1) /* check to see if bit is high */- k0 `5 D% j/ y% a
- in = in | 0x01; /* if high, make bit high */
2 V0 P" c# {$ O% U" Y
' H. R- Q6 h% y# ^6 W- SCK = 0; /* toggle clock low */4 O$ R% }8 }& N3 M- W8 L- F
- ( y$ I4 G" {# T7 i$ F& r. L; ~1 m
- }6 Z: D0 v2 j: U: @( u4 d9 e
- return in;2 z9 b) z- f5 X) ~& T
- }! Z4 a9 X+ `: W" y% m& |2 }- X; j
- 1 f# Z$ E; G6 u# y, g& ]
- /************************************************************************/& ~* H1 s4 m# P; _
- /* PROCEDURE: Poll_SO */3 z4 o* K( a' {2 ~' x
- /* */
8 X/ t# H% e4 D2 J - /* This procedure polls for the SO line during AAI programming */
3 R+ N+ ^+ J, o6 R4 J3 S3 n - /* waiting for SO to transition to 1 which will indicate AAI programming*/
1 s! }* g( P' M) X. z - /* is completed */* Z8 n% H& ?( `
- /* */0 t. G/ z7 K5 i# x4 y T
- /* Input: */
7 I+ s- }6 ]' Z9 O1 P, J& e6 v - /* SO */6 {) y2 {- |: u* p7 R- }, v
- /* */2 S+ L7 Y8 c+ Z- D
- /* Output: */
2 C" e- [9 B6 Z, U - /* None */
+ e3 \$ Z4 c7 L2 V - /************************************************************************/! [4 `2 R7 I4 g
- void Poll_SO(); N7 z2 O% j6 f# _& l+ s: y
- {% s# N' c: b$ f0 h9 Q, T
- unsigned char temp = 0;
6 i: L h! y0 m* L6 y* N - CE_Low();
) H7 C1 [) u X6 }+ K( K - while (temp == 0x00) /* waste time until not busy */
: {' |1 e- X0 w! P E - temp = SO;% l' g! N* g$ |6 r
- CE_High();, o9 p. H1 ]2 r" y1 X) m$ z
- }* h8 F- B- j/ E1 u. G" ^
- : l6 v, Q7 Y- d- Q4 P( Z" p
- /************************************************************************/
) N) j a$ @# h) l9 D0 |; r - /* PROCEDURE: CE_High */# L0 B7 T1 n D3 I5 ^- u
- /* */
# b }) ]+ a4 V9 `' j: J - /* This procedure set CE = High. */6 D& H+ P1 G6 K
- /* */* w* @1 J& v$ y7 Q/ l0 k7 Y
- /* Input: */
# ]9 o @9 _. m# s5 q - /* None */
( {) }' Y0 _# N- X( O - /* */* }. ]9 x' {+ o$ T! S2 h1 U. D- o0 M6 p
- /* Output: */
( u6 G" v/ f: c, H% }; \6 e - /* CE */
?4 o3 P9 c, T - /* */
, \9 w; V% U( o, {; d4 D - /************************************************************************/
& r& Y0 T1 i% K; K8 F7 w. `+ s - void CE_High()
* r ?% D' M1 a3 U Q1 I% z: ~ - {6 F; L0 J% \# E2 V1 |
- CE = 1; /* set CE high */
3 S( X2 m e+ j9 {9 c5 V - }
& D' _$ p( F& p' Y- [ G" M) ^5 B - 5 @: b- M S+ [/ q1 w0 l2 U7 t
- /************************************************************************/0 m! t& l" Y" w* g3 [* B
- /* PROCEDURE: CE_Low */, m6 ?; P" O' z- T7 r9 \6 d. w
- /* */
8 y" b/ t& d P - /* This procedure drives the CE of the device to low. */- L+ z2 u1 a; _8 Q9 [4 _0 h
- /* */, i$ T; l% l" S6 \0 s
- /* Input: */* _6 V+ X) e6 z
- /* None */* z0 T( J e! a0 V
- /* */
3 C3 p* Q( q2 t5 V. b: \) ]+ v - /* Output: */
2 {6 T, c8 o* H - /* CE */
9 H# P7 c' X$ \* w7 f - /* */
$ f& }0 }3 ^9 d4 u r$ Q - /************************************************************************/; D" O$ W+ r$ P$ Y( x! s M- B
- void CE_Low() ( d2 [( N1 n/ ]5 D
- {
8 b4 R: e; B) I4 }- ?9 t# z - CE = 0; /* clear CE low */
^2 g& G, N( X2 X2 \ - }
& [% \- |$ ^) E% i
9 e5 C; l+ N" w# Z2 R1 o- /************************************************************************/$ V* q7 V. @4 S" b
- /* PROCEDURE: Hold() */
' T# x+ F6 W# J7 U: W& i - /* */
7 T& j' ^* a& b$ z7 f - /* This procedure clears the Hold pin to low. */
4 {* X: A' R8 ]: Y! Z* t; r - /* */
+ P' h- ^) j% a6 e - /* Input: *// D7 @. \8 f2 f$ L8 N
- /* None */+ o8 f: V' k" u4 m# e6 X; z
- /* */
; x3 F6 b6 P$ w4 C0 B' \2 O" D; m - /* Output: */
) {9 i8 G; F( U" W - /* Hold */
+ s. f1 a7 @* ^: X. V8 v - /************************************************************************/- f/ c; ~8 b; m+ s" Q' s8 K
- void Hold_Low()
' V1 h, v2 `6 @ - {
7 R: ~ q7 U" N6 a- e- k - Hold = 0; /* clear Hold pin */8 h( H1 B/ N/ |9 ~" C- B
- }
: U9 u1 \$ L2 g - 0 }* i9 T+ q) p4 P9 s7 `7 h. A' k5 ?
- /************************************************************************/9 K, b3 s$ T! O+ j6 q: o
- /* PROCEDURE: Unhold() */( s& L/ d, B- z, G- h8 o6 W- ]
- /* */& V: o; D h, r) k6 G# X0 F$ X* Q( B
- /* This procedure sets the Hold pin to high. */% s; F' M2 c7 ~8 I
- /* */5 r5 I9 _9 v5 |7 A+ o5 U$ E
- /* Input: *// b# D; D0 N9 b5 a
- /* None */
9 f9 s/ J3 h( J& b0 G, v/ n - /* */
3 M( R8 D. Y" w - /* Output: */
" Y; w A+ Q+ t, v. ] - /* Hold */$ ]3 @/ {7 S% A8 @7 f
- /************************************************************************/
& i, c* v5 H J) ~. e- z - void Unhold()1 @/ b, J" A( X( Z" F) @ ^" w
- {
2 w! c; ~5 u- i5 Y* j9 j - Hold = 1; /* set Hold pin */
) A' J7 z, S" W5 j' w& j' k - }) i1 U/ ]8 B1 d; i W
: n+ s& Q! U/ X: m3 V! D" u- /************************************************************************/0 a! y- k; v9 z6 h
- /* PROCEDURE: WP() */8 I: t2 S% @5 k
- /* */
- h. |; C4 K5 t' N$ w7 A - /* This procedure clears the WP pin to low. */* X: X1 D7 d( m6 ~3 f y
- /* */
; J) R1 M: ~# e G- t | - /* Input: */' |' W- O$ \' q+ c2 N. [
- /* None */% K4 ]( Z6 Q& [/ Q
- /* */
3 Q5 E+ Y) Z' L. G j7 m' |( [ - /* Output: */' H5 p ?3 D" ~- g( |+ G
- /* WP */$ y9 ~( |# |- J6 v* F$ z6 B
- /************************************************************************/* _+ U8 z6 d0 A
- void WP_Low()
& T% O* m9 ~0 j& a3 c+ T0 E - {
2 b6 x- ? t \7 r - WP = 0; /* clear WP pin */+ z) Q% t8 G9 D k A9 o0 v& ]
- }
2 N& G" S+ R) p; k- Z- ?
8 O- S, E% X6 s0 ^1 ]( X- /************************************************************************/
# D/ U/ Z( A* u) { x- q( |( r - /* PROCEDURE: UnWP() */
?- g2 X$ D: }1 _ M - /* */ x' l$ D$ u, N. q6 H! `; T
- /* This procedure sets the WP pin to high. */; Y4 n. z" _) ~9 K3 N
- /* */
3 u( g3 \8 F V1 G - /* Input: */
{- s8 y1 o8 g; S' u0 p - /* None */
1 V1 E% U' v, H' b - /* */5 A, X: M( {3 e) J
- /* Output: */0 t7 ]2 } d- }
- /* WP */
" X2 z- o; O/ |- _0 e2 S! R6 I Z - /************************************************************************/
5 M3 h6 Z: v2 h. b, V0 |! G - void UnWP()" [* G& m. }' b3 ~
- {, ?+ n$ h _! Z$ m5 |
- WP = 1; /* set WP pin */
Q6 b" z, y8 `/ s - }
8 \' e }& r5 I" A! c* ^0 g - " x; M. l) d5 M' o T
- /************************************************************************/5 k2 q8 `2 Y8 ?6 o7 F
- /* PROCEDURE: Read_Status_Register */
" k! H( I7 F# k5 p$ v6 t - /* */
7 j* Y4 q' t$ x' w7 A - /* This procedure read the status register and returns the byte. */0 V D. K" A" t, P4 ?9 V( \% ?3 U
- /* */
- I0 L) R6 `! W4 N, d Q - /* Input: */' S% ~' w8 R, N0 k, P, K% d8 F
- /* None */
6 x# c8 r0 c, ^" |1 d' ` F - /* */* d( A- N- o. U: X. C" n' j/ f0 j
- /* Returns: */, E4 O# ^& t, K
- /* byte */1 z0 O' T2 @/ ?: C6 y! i
- /************************************************************************/
0 C$ z7 t2 c9 [$ O* T! F - unsigned char Read_Status_Register(). P4 |) v4 D" N
- { U: r. n; N6 A) Y* }9 i+ J
- unsigned char byte = 0;
. w+ Z. f5 f% j M+ {' k - CE_Low(); /* enable device */
2 s; x8 b( E5 }' v* K& ] - Send_Byte(0x05); /* send RDSR command */) [( r" |1 h3 r
- byte = Get_Byte(); /* receive byte */' u! m7 E8 X& y
- CE_High(); /* disable device */6 R/ \' a, p: v5 y0 A
- return byte;
2 N/ B) b& \- r# a* K; l0 w - }
; r3 }1 `1 D# z - 0 i7 X+ u$ Z$ U+ G0 S) B+ n3 O
- /************************************************************************/
2 ]3 W: U! m+ D) C1 a- A - /* PROCEDURE: EWSR */
# D: m) X q. O' ` k0 S0 c - /* */
1 }" F; H; j( p5 g! t1 A - /* This procedure Enables Write Status Register. */
4 q- a( o7 V4 w; c& ?; j9 Y - /* */
9 ^6 c; f0 v" J6 H4 u - /* Input: */
* u9 h5 @2 @( J3 Q2 b5 k* c o - /* None */
0 z/ Q- r& E9 R2 S/ S: S - /* */
6 J, i) R! R% o6 |, e - /* Returns: */: G* d! |& O4 `; |" L0 y) ?8 P
- /* Nothing */: }# b5 x/ }2 R
- /************************************************************************/
: k0 [- r8 V5 k, t( g$ ~! X - void EWSR()
- V7 l. v/ F' l8 {1 d( [3 ^ D* p+ q& p - {' A6 E: j3 t6 T* y3 p6 S6 u3 V
- CE_Low(); /* enable device */
0 i+ K6 _% Q& M+ K* q& C - Send_Byte(0x50); /* enable writing to the status register */- X% a3 O( O- H: H9 V: l. F
- CE_High(); /* disable device */8 v @5 y. a0 a4 l; H- s8 O t3 E
- }; f5 B0 E8 g* P2 l/ U. w
, b! `1 {0 O6 `- /************************************************************************/
9 d7 B9 c6 Z1 X5 i4 }- s" l% C. I - /* PROCEDURE: WRSR *// W- n8 U# }* F5 `: P# j3 X: \
- /* */
6 a3 R/ k# i) A" ~ - /* This procedure writes a byte to the Status Register. */; ^# k1 q8 y; e+ i) r: ^) L4 K5 U, Z
- /* */! T7 G4 u+ B S' t2 l8 N
- /* Input: */. p& X6 W; C6 Y* N, X+ Y/ q& r
- /* byte */ g- D' s9 c. y1 J3 D
- /* */; V1 d5 A" J) x% R$ i0 T L% D
- /* Returns: */
4 K5 ]' r- O' Z. l$ O! }6 z3 b6 N - /* Nothing */; k: } O/ d9 D9 |, n, P
- /************************************************************************/
% ^# M7 c* L" v* c- b6 S - void WRSR(byte)
! G4 N/ `+ A E1 ^6 Q1 Y+ H - {) o( G, w* e3 \( X9 B% Z# K
- CE_Low(); /* enable device */
w5 w& ~9 z" B - Send_Byte(0x01); /* select write to status register */3 T9 H7 t# K8 ?- W, O- T
- Send_Byte(byte); /* data that will change the status of BPx
# f8 O D! V) l! H5 r9 L - or BPL (only bits 2,3,4,5,7 can be written) */
: K2 }: b/ u* e2 D% Y1 T - CE_High(); /* disable the device */
* C* D; T5 \( D! f9 q3 t - }
5 u" ?1 Y3 f& ?- R0 N - + f: @( T! O% G9 Z2 R
- /************************************************************************/% a# b" h+ ]" Y/ g$ N! _
- /* PROCEDURE: WREN */
3 O, e3 }' L" _ - /* */ k4 F2 @8 [) O/ T. C
- /* This procedure enables the Write Enable Latch. It can also be used */
( U9 h3 E2 j. a - /* to Enables Write Status Register. */6 [# E8 a5 @5 ?6 S2 \- F# p
- /* */, K7 w/ H$ l# B) X& k
- /* Input: */
: i3 G* a2 _8 l! M( f" o( ~8 T5 B - /* None */
; U r; o1 F' Y B: e - /* */
9 N& o8 O3 g; B6 x9 @% N0 e5 q - /* Returns: */- t& G! m8 R$ D$ D' s, N( ~7 M' F
- /* Nothing */
) s, W2 T# j6 o6 X8 n$ d! U - /************************************************************************/, |4 _, z& } z) l2 O& W O8 ?% {
- void WREN()3 z R& K' o" _+ K4 q# [+ z
- {
! O) l# r3 \/ @# } - CE_Low(); /* enable device */, J' F% S. y3 N* _. X8 r8 K
- Send_Byte(0x06); /* send WREN command */
) @' g) g9 h7 v+ }6 @* T; [6 Q - CE_High(); /* disable device */
) z1 V4 b7 {2 l k$ e( e- j `5 m) l - }
- f7 d+ h! K) @7 s4 C - 5 m0 @- M# _$ J s0 k
- /************************************************************************/
( d4 p8 s: `6 E6 }2 E* i# A5 x5 P - /* PROCEDURE: WRDI */
& }* G% G4 t. T - /* */3 ~& r8 \: M- W1 z
- /* This procedure disables the Write Enable Latch. */
- x7 ?$ z. \3 n - /* */
4 i: p4 q0 m( g# @/ F% s' [2 s - /* Input: */
( w. u. K4 ]; P - /* None */
! S8 y6 u ~- s- O% w - /* */
, |, u, N- c: Z/ B7 `# E - /* Returns: */) d0 L: r' A/ |, T3 h
- /* Nothing */
. k) [) m3 y) {2 y |) I+ h! L - /************************************************************************/
/ x6 [$ B' Q8 b& n6 u- H$ g# o; G - void WRDI(). E: z+ i: n/ q
- {
# K! x, p/ ?9 l7 i - CE_Low(); /* enable device */: u* e' k6 j5 V
- Send_Byte(0x04); /* send WRDI command */
. ?" h3 ^4 s- X7 v4 c - CE_High(); /* disable device */
, h( h ?% h, v - }
! g# L' ]) { k! }) V - " ~8 U2 E! B& v6 K
- /************************************************************************/- K2 o; P; C. s5 d0 s: n2 E. e
- /* PROCEDURE: EBSY */4 v9 ~6 Q& @0 O
- /* */" l# v+ x2 [& i$ K
- /* This procedure enable SO to output RY/BY# status during AAI */' w" G2 h5 j. M5 A, i7 _6 w
- /* programming. */
" L9 W+ z; O' G1 N - /* */5 \+ k# q( Q4 _
- /* Input: */5 N5 L; n" y. D) z' Y+ r
- /* None */
, ~& C. p/ i' i4 v& d - /* */
3 Z" s+ ~" s# `/ E: W - /* Returns: */6 t6 `8 W0 f& ]% }0 L0 }0 _5 Q. v
- /* Nothing */
, S" ^1 B7 J. P8 N - /************************************************************************/
S6 s- z9 o- P - void EBSY()
& J% f5 X; m% _. U( r G& n8 n - {
; }" _8 B0 ~! ^, g$ B3 z) ~ - CE_Low(); /* enable device */5 ^; M( d! m |
- Send_Byte(0x70); /* send EBSY command */
; f1 p5 v2 g1 b# Z6 A - CE_High(); /* disable device */
$ W! _' l+ F" f8 N& \/ ^6 \ - }* S$ _( e% `1 z4 M+ k; E
- " R7 V' \* |3 F4 y" G+ r, t) ]
- /************************************************************************/
: o- k7 }2 t t- K - /* PROCEDURE: DBSY */1 W; [: R- E* t1 s& ?6 a
- /* */
. D$ A& N$ L4 s, O) J6 M - /* This procedure disable SO as output RY/BY# status signal during AAI */
( P. J; Y4 p: p7 ~$ o' E - /* programming. */
2 T! {7 |# q' l W5 V" [/ ? - /* */7 H- h: V. t' e+ `3 V$ F
- /* Input: */
" v, N- [2 x! U! O4 T1 g* ~ - /* None */3 i1 r' ^4 e8 s
- /* */
3 H6 g, |7 k: E5 {" G - /* Returns: */
9 S# W, a5 z5 z7 l; B; { - /* Nothing */
4 x1 G( d! Y- u; U - /************************************************************************/& g0 O$ b" o& h. K+ j- M
- void DBSY(). |# z: i* ~/ X: C
- {
+ ]. J# u; u: z0 o5 K - CE_Low(); /* enable device */7 r' @- N" g3 A: j! Z+ m+ W! ^% E
- Send_Byte(0x80); /* send DBSY command */# n" U. v1 ^$ a/ x7 `3 c
- CE_High(); /* disable device */" F* v. ^9 b# M3 _
- }- I8 [7 Z2 p! T# Z1 p% c; A- |* ^3 H
- , u% N# [: M' p
- /************************************************************************/# \1 v4 I: h; j" P" ?# ^2 P
- /* PROCEDURE: Read_ID */
Y% G6 J* c: i/ r - /* */
2 _2 z. F$ }1 P2 b5 f - /* This procedure Reads the manufacturer's ID and device ID. It will */% z/ B$ y( H$ _* Y3 a5 j
- /* use 90h or ABh as the command to read the ID (90h in this sample). */- `% y, E& n: z5 C, P N* D
- /* It is up to the user to give the last byte ID_addr to determine */1 s: K. e- t" G
- /* whether the device outputs manufacturer's ID first, or device ID */5 }& ^2 @, K- X% b
- /* first. Please see the product datasheet for details. Returns ID in */+ V2 Z. ^' ^$ J* ` a4 H
- /* variable byte. */" H0 V/ I, c4 l. g9 {" }
- /* */
( ?4 K7 E L V+ e* U3 ?3 w - /* Input: */
& U$ k1 E( @3 E) d- U- I - /* ID_addr */
( ]: M1 Q! g3 q) g- x - /* */4 W( u! F8 l; F- G2 f
- /* Returns: */" N+ O4 f; t6 i3 d0 A$ u( K
- /* byte: ID1(Manufacture's ID = BFh or Device ID = 8Eh) */
+ x! D9 A ~$ y; v @4 [ - /* */
. g: j1 Y, R6 A+ e/ k - /************************************************************************/
, N4 t) I% j9 R% z - unsigned char Read_ID(ID_addr)6 S% F A4 A- f1 i8 P1 ^& k
- {
4 z& m. }4 a, N+ I/ J8 Q: } - unsigned char byte;
; _% q& h* c$ @- u) }" I3 h5 Z - CE_Low(); /* enable device */6 y( ^/ J8 Z$ G0 d, z2 y
- Send_Byte(0x90); /* send read ID command (90h or ABh) */* w7 H4 O& @1 G# {# U+ p% L/ z
- Send_Byte(0x00); /* send address */, h V3 g0 Y* k2 H
- Send_Byte(0x00); /* send address */8 S8 |% N. P7 D1 a. s" Z Z$ Y
- Send_Byte(ID_addr); /* send address - either 00H or 01H */
; F% J4 Y1 g! Q6 d" D9 i4 o+ I - byte = Get_Byte(); /* receive byte */9 p0 `8 d" [8 u j& L" ?! F+ V
- CE_High(); /* disable device */4 Z9 r# B0 ?0 T. ~9 r
- return byte;
; R* p( c7 G4 d0 i - }
# j; Q5 Z. V. T" p1 P C
0 O' M5 j4 ~6 y. \- N" @- /************************************************************************/1 M* R6 n7 P+ }' x+ c- j
- /* PROCEDURE: Jedec_ID_Read */
$ F; \5 U Q( o- I3 L Q4 B6 H+ [ - /* */. f+ W& N- b7 P! ]6 J7 }& q
- /* This procedure Reads the manufacturer's ID (BFh), memory type (25h) */
' l6 a- D# I0 Y+ p6 P5 O' z - /* and device ID (8Eh). It will use 9Fh as the JEDEC ID command. */4 A$ \( L0 y y K+ j6 d
- /* Please see the product datasheet for details. */3 h; I0 d$ q7 X$ N7 s- d8 D7 k
- /* */, b8 ]: K8 {5 A8 I& H
- /* Input: */
9 \) I7 ~" K& _ - /* None */
# J; S$ t0 T/ ?+ b - /* */3 m b! j( Y! w7 H3 x
- /* Returns: */, G& H/ T& g& r
- /* IDs_Read:ID1(Manufacture's ID = BFh, Memory Type (25h), */' ?4 y e! g2 z1 K, W/ ?5 G! Z* Q
- /* and Device ID (8Eh) */5 y. Y1 @/ d4 y! T0 K3 c. ^2 B
- /* */
% `7 s, l4 A4 O1 J1 v# \ - /************************************************************************/9 h2 E* S3 q: z- \% U
- unsigned long Jedec_ID_Read()
$ T/ Q6 k% Z2 v5 O4 j; g& h - {
' p) q: ^' u% U7 ^+ U; N - unsigned long temp;+ k1 O' X+ v) U* w
- - g6 X# k& m# N; e4 v! @$ ^! Q
- temp = 0;
" W1 ^4 u z8 g* r - * `( @ p- H% f; [# q; L; X1 y5 c& H
- CE_Low(); /* enable device */
# d8 X: _- [ s# | E( }! s6 ~ - Send_Byte(0x9F); /* send JEDEC ID command (9Fh) */' G: h3 J2 Q% Y+ ~/ C( ^, E# C
- temp = (temp | Get_Byte()) << 8; /* receive byte */6 C7 B, @: r1 B4 D6 { N
- temp = (temp | Get_Byte()) << 8;
9 Z; M4 b H1 \, P1 }* _3 i. I0 a - temp = (temp | Get_Byte()); /* temp value = 0xBF258E */ I, H5 S4 y; k
- CE_High(); /* disable device */; \( K" L* D" z: O: r% X9 K6 Z
1 B; S6 u9 s/ j5 a7 E- return temp;
( [3 s) {2 f4 ^" s* p - }: G3 B/ ^' G2 [* @6 P
- ' _3 W! w- {5 I+ e: p
- /************************************************************************/" b* k: e' P! G# L2 Q
- /* PROCEDURE: Read */' r _9 x+ X+ J- k# F. [/ ^$ d/ ^
- /* */ / L3 L8 E! }- x
- /* This procedure reads one address of the device. It will return the */1 Q, `7 I2 b& C8 ?% H+ j4 }" P5 Q
- /* byte read in variable byte. */
5 Z* F: b1 ^* ` - /* */( s- E! p9 J: ?* p' Y
- /* */" P' |* ]; ]0 H
- /* */
' {' f' _+ o- t! U" `: T9 T9 U4 g; a - /* Input: */
# Y! U: c7 F7 n8 P: ~1 ~4 Y2 D4 j - /* Dst: Destination Address 000000H - 0FFFFFH */9 |1 v6 S$ X/ |8 ^) [; k
- /* */& o* O% L# e0 j l9 x
- /* */
I+ O; ]: ? W- P; g# r% Z - /* Returns: */0 o$ V: L1 U. m9 k# I- C
- /* byte */$ y8 k5 I1 Y) ]+ n( G" g
- /* */
7 w. q( z" h! c+ }3 O% M: P( a - /************************************************************************/3 D1 L$ N$ u& p" F5 Y( `
- unsigned char Read(unsigned long Dst) 9 X7 o# K, f S* Y3 u
- {( ]' P. e5 v9 u5 ?5 H+ w
- unsigned char byte = 0;
! d( V4 E4 D$ d; Y - 6 D- Q- R1 d0 d" s' y
- CE_Low(); /* enable device */
$ k+ W7 F7 ~. J+ |3 U- q - Send_Byte(0x03); /* read command */
3 N0 E" `# B5 o) S7 w. G7 ] - Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */# c3 @. k% S# ?8 b6 O% ~, a
- Send_Byte(((Dst & 0xFFFF) >> 8));
, J! m5 E# @$ t5 V - Send_Byte(Dst & 0xFF); b" ~3 G: s/ j: `2 g) [
- byte = Get_Byte();' G3 M* ~6 C0 u
- CE_High(); /* disable device */8 o' v! v6 b8 M" T0 e0 N8 d
- return byte; /* return one byte read */ \- L$ i5 ^1 ?/ Y" N; i
- }
6 z, B y0 U! G
# P1 Y) @- D \1 y6 @7 y- /************************************************************************/) `6 H5 |/ z! t1 L
- /* PROCEDURE: Read_Cont */; g* q% C, W* j* D
- /* */ 5 p3 |: ?1 ]* q% {' t, ]0 M) s
- /* This procedure reads multiple addresses of the device and stores */
$ _6 |8 O9 I4 Q# `' X; f& L - /* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*/: f j n0 B/ C! O* l& j$ C) R
- /* */! T: ]& G5 ~( g6 u, y& i) H2 Q9 w
- /* Input: */1 i9 n& b1 {+ o' l# J j
- /* Dst: Destination Address 000000H - 0FFFFFH */
4 c' z/ E1 E2 k - /* no_bytes Number of bytes to read (max = 128) */
" a6 t0 D8 ]0 l! C3 B2 t - /* */( N/ y; r% U8 U0 h4 P
- /* Returns: */" }$ W L( R* Q1 x4 ?" N6 {
- /* Nothing */
* D% O; t5 H U9 t - /* */. S+ ]! P& J' s# ?9 ~' ~
- /************************************************************************/
& H. v- ]& E9 z. M7 X- Q - void Read_Cont(unsigned long Dst, unsigned long no_bytes)4 e, V% J6 a% D) z
- {* Y& w( W; W. W' J
- unsigned long i = 0;
9 j2 p6 K+ R Q+ {# i& ` - CE_Low(); /* enable device */
: ?8 {- }9 K" g - Send_Byte(0x03); /* read command */. F: U5 E3 y6 [3 U' R
- Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
: t: N2 I1 Y) z" i - Send_Byte(((Dst & 0xFFFF) >> 8));% V, v3 @& G1 w& S( r
- Send_Byte(Dst & 0xFF);/ J6 A! u( `' n
- for (i = 0; i < no_bytes; i++) /* read until no_bytes is reached */7 P) l9 x1 k4 w' a
- {
: M* Y! e6 S- N' z - upper_128[i] = Get_Byte(); /* receive byte and store at address 80H - FFH */
; Z- \/ l! E- g+ J - }
m h$ ^: e- l/ `; O/ c - CE_High(); /* disable device */
0 y% S0 C9 h" M- D4 F - * K0 a- v$ ?% x0 h* f
- }. N- n8 l* S& ]+ U3 b
- ) {' }7 Z1 r. U. c' |$ A: ]5 W1 _
- /************************************************************************/5 \' I# F% ~8 [8 e7 I' \2 G1 b$ X
- /* PROCEDURE: HighSpeed_Read */
2 Z! O6 } B' p7 u - /* */
' O9 K# D8 ]' ~ - /* This procedure reads one address of the device. It will return the */
1 P2 E) F, [% |. k. e' b - /* byte read in variable byte. */+ L, v0 x0 S9 [1 z9 j
- /* */4 {( z% t4 p. |" U) n* {, d' T+ V
- /* */
8 \) M5 P% I2 J - /* */
+ x8 b5 K Y. A+ b, c- d) R, m5 j - /* Input: */
6 E, ?$ q. ^" _# i- b# | - /* Dst: Destination Address 000000H - 0FFFFFH */8 v( K* y! Y. M' I+ S
- /* */7 [; m: p0 h1 D' t
- /* */
) J0 A: f, r. z6 N5 t - /* Returns: */6 v, k1 R4 F" M- q
- /* byte */9 M9 {( K( g# u: f6 f! P
- /* */
. ^4 M0 A# r3 x k, q3 C! s( U3 @ - /************************************************************************/
; F% C7 m# D8 g - unsigned char HighSpeed_Read(unsigned long Dst)
/ E; i; Q; ]8 u( ^& N0 M3 L* q - {
/ e$ B- [! [: E4 [ - unsigned char byte = 0; 3 _7 U$ _+ o9 T, X
/ d7 r# c& G& X6 w9 y- CE_Low(); /* enable device */
G; H1 s: L3 q) l - Send_Byte(0x0B); /* read command */
8 z7 p- h8 z* i; ~5 E1 O - Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
+ X# z7 J( o; c( y6 f - Send_Byte(((Dst & 0xFFFF) >> 8));2 G$ Y; `8 M! Q
- Send_Byte(Dst & 0xFF);3 I5 a+ V W1 q9 @, |
- Send_Byte(0xFF); /*dummy byte*/
+ G0 R: x) [7 }' Y* n/ P$ I - byte = Get_Byte();3 z. t9 h; t. l8 t1 ~0 E' ~$ e
- CE_High(); /* disable device */( }6 q0 f1 ]6 x/ s
- return byte; /* return one byte read *// G. _, e' B; P+ W$ z% u/ i
- }
% O) ?3 k4 W$ E" Q+ x, u - ! q5 k/ X7 F" i( E2 m) |6 r% ]( j
- /************************************************************************/
( J6 Y( D7 W' T- _, V - /* PROCEDURE: HighSpeed_Read_Cont */4 g) K3 d3 o3 F
- /* */ 2 G7 Z/ H( o4 T+ u; ^# m2 h6 x$ f: F
- /* This procedure reads multiple addresses of the device and stores */
3 r3 l; j" B+ C6 }2 c- H4 J - /* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*/
- H- O( J& x0 M/ A/ c9 y2 ]) ~ - /* */
/ ?6 E/ J( L3 i" M0 c3 [ - /* Input: */
5 q( f4 A0 T: c* w0 F8 q - /* Dst: Destination Address 000000H - 0FFFFFH */
7 c: s/ w/ g/ C i! O - /* no_bytes Number of bytes to read (max = 128) */5 ]! ?4 [* z& G7 ]* [! ] {. y
- /* */
1 }' ?& o. n7 y- H. k7 K - /* Returns: */
5 l; O* v- P" C3 K& \ - /* Nothing */
g9 B2 W# p$ w O5 S/ O1 N - /* */3 L! _3 E; D, A' R* Y9 F
- /************************************************************************/
; S/ i3 N/ ]$ H - void HighSpeed_Read_Cont(unsigned long Dst, unsigned long no_bytes)
1 b. X# x: [/ i7 _; D: ] - {
- N: d; G% n: z5 Z# j/ A/ _) W - unsigned long i = 0;
D) N2 \: Z( z- \, a5 O. B - CE_Low(); /* enable device */
3 n. m0 }- Y! G1 f5 v3 t* e7 x - Send_Byte(0x0B); /* read command */
5 v: p E% H3 d1 y; ?! E - Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */! y! }6 y& V) Z: |0 u7 e7 f$ {
- Send_Byte(((Dst & 0xFFFF) >> 8)); P# I; C+ F* R" L! i4 C2 _
- Send_Byte(Dst & 0xFF);, T. W4 _8 j" e& A; P# A; l
- Send_Byte(0xFF); /*dummy byte*/; E) @% p( w/ R* M0 U/ e% _
- for (i = 0; i < no_bytes; i++) /* read until no_bytes is reached *// ^6 e8 e9 T; P2 x
- {
; ~8 `. O4 f. i3 T - upper_128[i] = Get_Byte(); /* receive byte and store at address 80H - FFH */, g0 E% ]5 C) o! ]1 }% c
- }
1 k5 k3 G' v/ ]1 N7 k" ] - CE_High(); /* disable device */% }$ |0 Y% ?% k
- }3 O+ v7 c# e- J" A/ j' Q4 I
; X: L( R, t% H; t2 Q4 d- /************************************************************************/
% Z/ p. ~1 [6 }- G% C- y* `) r - /* PROCEDURE: Byte_Program */' N6 Q+ B; [+ r6 v7 u" B, W3 U/ I
- /* */( m+ H2 |8 B x$ k! v
- /* This procedure programs one address of the device. */
. V! R* X' g$ s/ G" w; E8 i - /* Assumption: Address being programmed is already erased and is NOT */" \6 i2 C* Y2 N) D+ c, u, J, h
- /* block protected. */
9 ], [# g: n1 s1 I2 M$ q; z8 d5 b - /* */
! i% S+ z' V4 A0 C6 t- x- E - /* */
5 E+ m- N2 ?# @$ C* w - /* */
7 {( |) D" h8 e/ X. C5 H0 U - /* Input: */( n" v8 X; U+ b. n8 `5 v2 J
- /* Dst: Destination Address 000000H - 0FFFFFH */. J) {- e2 |" a
- /* byte: byte to be programmed */
$ A3 g+ Q* W: E1 ]& B, } - /* */+ H% {) ~3 [! }7 e
- /* */. r7 C0 h5 d* G5 E. y. p
- /* Returns: */$ r; j9 v6 t( P8 L: l& R
- /* Nothing *// h0 f/ U0 J Q0 a' ?" U1 K
- /* */
i# S0 F+ }% {: k - /************************************************************************/
- S; P. Y' B7 B( u% ~) e* {0 K! K - void Byte_Program(unsigned long Dst, unsigned char byte)9 ^, ~$ w' z# o' t: T- N; A
- {8 }9 ~* {2 X. A4 Y+ ?: O
- CE_Low(); /* enable device */
$ R# {5 h, j) y. q% [$ s7 a - Send_Byte(0x02); /* send Byte Program command */" U, T6 l7 I5 F+ G
- Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
. I- B& K' c/ ~ \# U( A - Send_Byte(((Dst & 0xFFFF) >> 8));0 [0 {7 {1 T% F w2 g7 {
- Send_Byte(Dst & 0xFF);
g, F1 p3 h' N# s2 y - Send_Byte(byte); /* send byte to be programmed */! K6 w2 _" ?$ c; ~5 K% j3 o8 W
- CE_High(); /* disable device */- V+ f' l" r7 C: U8 P
- }* k* C, o+ E: V9 G/ d: n& `# M4 O$ @
- 3 ~1 k E' F4 J0 r& c2 g
- /************************************************************************/* F4 I# q' p% @8 t4 f
- /* PROCEDURE: Auto_Add_IncA *// L6 Z! _" w( a: p7 c
- /* */
6 }8 L. C" l Y9 x! {- ~ - /* This procedure programs consecutive addresses of 2 bytes of data into*/; W% L5 v" e0 p0 [1 x: a
- /* the device: 1st data byte will be programmed into the initial */; t3 F" \- t& L* @" X5 ^0 S; o! |
- /* address [A23-A1] and with A0 = 0. The 2nd data byte will be be */& P7 m) H9 K; C: p
- /* programmed into initial address [A23-A1] and with A0 = 1. This */
" @, j5 J& b2 K& [ - /* is used to to start the AAI process. It should be followed by */; U: q7 p/ ]6 s4 U/ Y
- /* Auto_Add_IncB. */
; s3 I8 B2 p: V' R1 E - /* Assumption: Address being programmed is already erased and is NOT */
& b1 j( Y; q& u8 y" j d! H - /* block protected. */
S5 }1 N) k B1 O7 O$ d; t - /* */# V: |4 a+ O3 m! y, _
- /* */0 i3 W) R1 s) b# B( y3 U# K
- /* Note: Only RDSR command can be executed once in AAI mode with SO */
& M9 z" `. ~. r0 w - /* disable to output RY/BY# status. Use WRDI to exit AAI mode */0 S9 V+ v0 o. o% z) T2 u' S
- /* unless AAI is programming the last address or last address of */ r+ I' Y9 }) h" z9 m' ^
- /* unprotected block, which automatically exits AAI mode. */. L% m. I1 ~4 B8 T0 j
- /* */
& f5 {: H% k/ s3 H2 P' \& ~! c% x - /* Input: */
# \2 z3 x& x" a: v% V* f5 P1 z - /* Dst: Destination Address 000000H - 0FFFFFH */
, o% B, o( _7 [# B: `( s - /* byte1: 1st byte to be programmed */
) @* B/ W9 r7 d6 l) D4 K6 x/ @ - /* byte1: 2nd byte to be programmed */+ I. j) `% W! h2 G& |7 j
- /* */* {0 Z5 `, Y* e& N5 a
- /* Returns: */
- Q( H; C4 e2 l' Z9 d - /* Nothing */
) \6 g: O; ?; ]/ j) A8 ^ - /* */
. |7 j( I% n0 y; P$ F4 F+ R" N - /************************************************************************/) f9 l8 U; Q4 I! E
- void Auto_Add_IncA(unsigned long Dst, unsigned char byte1, unsigned char byte2)* ]: L( r! P& O& L2 w
- {. B6 T, S* O# x6 w6 I5 o, y
- CE_Low(); /* enable device */2 d, c5 w3 ~, L
- Send_Byte(0xAD); /* send AAI command */
. z2 Q! c; M% n6 @ - Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */, C. Y5 V' O( I9 ?+ |" t& g+ d3 l& `
- Send_Byte(((Dst & 0xFFFF) >> 8));6 U$ k5 X4 G# W t/ q
- Send_Byte(Dst & 0xFF);
' P) [, H* z% g5 M- c& R - Send_Byte(byte1); /* send 1st byte to be programmed */
" F y2 ?9 E) U6 W _8 Y - Send_Byte(byte2); /* send 2nd byte to be programmed */
7 E2 H1 @8 v/ M6 x0 i - CE_High(); /* disable device */- l7 m" j5 }* \& t5 @5 h e7 y
- }
2 n5 E2 w x4 X6 f4 |2 j7 B - % B3 ^+ ~# w6 o, |# Y
- /************************************************************************/
9 F! C. Q0 E. P. x; W' U - /* PROCEDURE: Auto_Add_IncB */
" W0 V& g) O3 Q8 Z0 C$ i2 T N - /* */. u5 H) x0 E# P: j; @
- /* This procedure programs consecutive addresses of 2 bytes of data into*/
: j. E: i3 e/ M* I- E; Z4 A0 [ - /* the device: 1st data byte will be programmed into the initial */
! g; d" Z) E0 V) a! M+ E - /* address [A23-A1] and with A0 = 0. The 2nd data byte will be be */
$ G/ s+ t( E. P4 u9 T; R/ j - /* programmed into initial address [A23-A1] and with A0 = 1. This */
; D: H' a( q, ^2 b - /* is used after Auto_Address_IncA. */
5 ?! a% {0 [9 D8 A6 { - /* Assumption: Address being programmed is already erased and is NOT */ V! E& f7 h6 k7 x- ?+ v
- /* block protected. */* y2 w# y6 I/ Z( v. s; \& c
- /* */
) H9 D5 A+ |& Y8 U' `3 }$ U - /* Note: Only WRDI and AAI command can be executed once in AAI mode */
* x5 D( e& N0 K - /* with SO enabled as RY/BY# status. When the device is busy */
9 ^+ g2 {8 g3 R, \ - /* asserting CE# will output the status of RY/BY# on SO. Use WRDI */0 e- y1 @: o+ `* t
- /* to exit AAI mode unless AAI is programming the last address or */0 d2 `( z( C6 v% z" h
- /* last address of unprotected block, which automatically exits */- @$ T$ ?. O7 j/ v! T& K
- /* AAI mode. */
3 W5 {6 ~) z) G% g0 \( o - /* */
4 t& v: F3 I$ E7 k+ k5 k: q - /* Input: */+ l" ^8 `$ K# ^) ^# W
- /* */
" d% y ^0 a- _ - /* byte1: 1st byte to be programmed */# _4 N" G0 A) E' O8 e# g3 R4 Y
- /* byte2: 2nd byte to be programmed */8 O. F8 f! O+ {# e
- /* */" r( z9 E6 {' q" R: k# j/ M$ Z8 ]
- /* */
9 O% ?3 Z2 E# Y1 W5 i - /* Returns: */
; N& y6 E/ }+ x, J8 J3 O! v6 N7 S - /* Nothing */
; ^5 W* N& o1 n2 ~% _# n; N - /* */: P; j; P) v/ _' C& ^+ x0 n0 ? C
- /************************************************************************/
" T/ ~, F% Q! j0 J7 E/ X, p) l - void Auto_Add_IncB(unsigned char byte1, unsigned char byte2)
+ l7 E3 c$ h# {6 z! s) x4 D - {6 [6 `, }* s4 b4 e
- CE_Low(); /* enable device *// s4 W1 f9 A1 E q
- Send_Byte(0xAD); /* send AAI command */
, B0 {% \" n4 T8 c! c - Send_Byte(byte1); /* send 1st byte to be programmed */4 ]; }! [% W: D, f2 S% J" h
- Send_Byte(byte2); /* send 2nd byte to be programmed */7 k) ^. M+ b0 a$ ^8 B5 Y
- CE_High(); /* disable device */
( _) `7 T. s# s - }
2 e$ G; i j" Q9 @7 Y' N
& ^9 ?9 t; f9 X0 D( k6 Q4 i1 N- /************************************************************************/3 j' I; R X) Z7 k3 P7 a! B
- /* PROCEDURE: Auto_Add_IncA_EBSY */; c! B U0 x: s
- /* */
* @5 d& ?& I c/ l) { - /* This procedure is the same as procedure Auto_Add_IncA except that it */4 G5 s W J- C9 h" b' \/ }0 R
- /* uses EBSY and Poll_SO functions to check for RY/BY. It programs */& K& W+ O2 h, `7 A2 H
- /* consecutive addresses of the device. The 1st data byte will be */
; C1 l9 _" r0 U( v - /* programmed into the initial address [A23-A1] and with A0 = 0. The */ F: o# [9 Q3 d% S; m2 ~& U# Q
- /* 2nd data byte will be programmed into initial address [A23-A1] and */+ i5 I5 G* N/ i$ F' F) G% s8 O
- /* with A0 = 1. This is used to to start the AAI process. It should */) B5 A/ f3 T( H, a# w
- /* be followed by Auto_Add_IncB_EBSY. */
3 I0 @8 K% ?6 i. l3 K, U - /* Assumption: Address being programmed is already erased and is NOT */) K, _; Y( @9 Q8 M% ] F( E
- /* block protected. */
% W0 M8 a" Q/ O; D: Q3 C - /* */" b0 |- O# c5 Q% X/ B7 H7 _
- /* *// t! n6 R: ^: f" ]
- /* Note: Only WRDI and AAI command can be executed once in AAI mode */
. K9 J! |. o: U; P" s: r- w. S - /* with SO enabled as RY/BY# status. When the device is busy */
% D: U9 m" f1 P, t - /* asserting CE# will output the status of RY/BY# on SO. Use WRDI */
1 O1 |- P1 W, G0 q. [& g - /* to exit AAI mode unless AAI is programming the last address or */- i7 r$ z$ O* f
- /* last address of unprotected block, which automatically exits */& }) r, P: f% ~1 ~
- /* AAI mode. */ d7 T# q4 I5 K' x
- /* */# T: w$ \$ B/ q4 R0 `
- /* Input: */# L5 w/ }) `* J. k( C3 X
- /* Dst: Destination Address 000000H - 0FFFFFH */
6 K" e1 E- h; G' g7 u* s' K+ o6 M - /* byte1: 1st byte to be programmed */' X6 s7 l4 K- v$ g0 M) }. b" ^9 U
- /* byte1: 2nd byte to be programmed */- N2 B( l+ c3 ?5 j j# ]" U) @
- /* */" e& P% O" r1 K) d% v% g
- /* Returns: */$ J+ g+ X3 [. K
- /* Nothing */
, G( R8 S# e& w F* r7 Y - /* */
8 L8 z, W0 U& j: ^; b$ x4 O - /************************************************************************/$ V& V( K9 b/ Y6 a: X
- void Auto_Add_IncA_EBSY(unsigned long Dst, unsigned char byte1, unsigned char byte2)9 [! A9 f6 s9 R- A( `9 `
- {
3 F( P% V& [' Q - EBSY(); /* enable RY/BY# status for SO in AAI */
2 w% y6 r/ f& A; ` _ p2 M! p2 l - ' M0 E: k# L# |) C: Y% s" w
- CE_Low(); /* enable device */
% R& c7 B. \ L* M4 `! i - Send_Byte(0xAD); /* send AAI command */
# g# _ E/ r9 i0 z; G - Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
' m7 c6 C$ M2 Y+ a+ F3 |% o - Send_Byte(((Dst & 0xFFFF) >> 8)); d4 n& m3 S. i! e
- Send_Byte(Dst & 0xFF);( l0 q* m0 G. W& ?
- Send_Byte(byte1); /* send 1st byte to be programmed */ 3 u3 h, |+ M% z9 G( H9 o6 E$ i
- Send_Byte(byte2); /* send 2nd byte to be programmed */& z3 N8 ^/ G' w3 ^. p! y1 ?8 |
- CE_High(); /* disable device */1 v. o9 i7 O) [! L) S7 F1 l
- + C8 `! R8 c- G- r. Q
- Poll_SO(); /* polls RY/BY# using SO line */
% ?6 o: w# q/ }5 Q6 e" A0 a1 @
& `& d, O6 |1 N( H" [" w- }
3 _& f( E+ `2 \& o) l4 T3 D# W - , N0 ?8 R7 i8 f
- /************************************************************************/
4 s' j0 N0 w3 I' Y9 ^5 J - /* PROCEDURE: Auto_Add_IncB_EBSY *// g6 s ~8 C4 S3 r5 s1 v
- /* */2 q" [5 x' T: F$ x8 x% A1 [% |5 p
- /* This procedure is the same as Auto_Add_IncB except that it uses */5 v3 c2 K# F$ v, n4 o2 O! t" `' f3 X- Z
- /* Poll_SO to poll for RY/BY#. It demonstrate on how to use DBSY after */* x/ I' W9 F) h. X% a5 F
- /* AAI programmming is completed. It programs consecutive addresses of */- U8 s* X A& u% O
- /* the device. The 1st data byte will be programmed into the initial */
2 W# q8 x' P; @, L! _) q - /* address [A23-A1] and with A0 = 0. The 2nd data byte will be */
9 x' X# n5 b% [: p. q! T; \6 b6 ~- Z - /* programmed into initial address [A23-A1] and with A0 = 1. This is */
: e. Q8 r" X5 s3 d7 F2 v - /* used after Auto_Address_IncA. */9 m+ c' d9 n& z. y4 B1 A
- /* Assumption: Address being programmed is already erased and is NOT */& F" }( _4 H) ?* D; A
- /* block protected. */
" K; s# X* n& J [: \' o, F0 |7 R9 i - /* */7 _- S8 M: Z- ^) A3 s
- /* Note: Only WRDI and AAI command can be executed once in AAI mode */
& `; i# d( U9 h% G - /* with SO enabled as RY/BY# status. When the device is busy, */8 q8 e6 U. E/ g1 P, w
- /* asserting CE# will output the status of RY/BY# on SO. Use WRDI */
; n; u4 g: }' H. }6 { - /* to exit AAI mode unless AAI is programming the last address or */; Z: H6 V& r! i1 c* ~
- /* last address of unprotected block, which automatically exits */2 G" J) }5 h) N7 w% E, ~
- /* AAI mode. */
; P6 h) a7 E) j! c6 C) M; S' N - /* */" ~& ?4 x" Z! t( e: j A0 ~& ^
- /* Input: */
8 t% G* Y" k1 x K+ O& F( I* h# w - /* */8 \" X3 o& m5 H f
- /* byte1: 1st byte to be programmed */
' C( q* ~- \; m5 k2 K( _ - /* byte2: 2nd byte to be programmed */5 K& p5 R# y$ M: [
- /* */& I7 o8 Y6 R9 L' K# m
- /* */# T7 S% z- S) y8 [8 B6 y
- /* Returns: */. v' E: e% u" M3 y3 @+ q$ P3 n' @
- /* Nothing */9 n/ A3 _. d2 I" h( L5 u9 ?. s3 Z
- /* */
1 o3 r+ K6 y# Q - /************************************************************************/. ~8 z) `9 L. G! A
- void Auto_Add_IncB_EBSY(unsigned char byte1, unsigned char byte2)
) r# l3 N5 V3 j5 i0 E+ p1 l - {6 c1 B, j; B. h# b6 n
- CE_Low(); /* enable device */
6 |8 M3 i1 z' L4 }+ E& a5 ] - Send_Byte(0xAD); /* send AAI command */
# R" ]: f N/ r5 J - Send_Byte(byte1); /* send 1st byte to be programmed */0 X2 C7 Y! z7 U p: Y, _1 M9 y
- Send_Byte(byte2); /* send 2nd byte to be programmed */. [" g1 w k% G1 L
- CE_High(); /* disable device */: I) w& R/ c! s
- ( r: o) p* `8 {; e' b# ?" t5 p7 |
- Poll_SO(); /* polls RY/BY# using SO line */
6 u; r5 l* H" W- l* g0 V
8 x8 P! K1 d, [- WRDI(); /* Exit AAI before executing DBSY */
/ K$ m& [) F, ]9 Y, M3 D - DBSY(); /* disable SO as RY/BY# output if in AAI */
' n( n3 K+ g# D* ?- \ - }7 P- V# t& |8 _$ w+ W
+ C8 X+ ?2 r# S6 s- /************************************************************************/
4 N+ ^# k$ q' I9 B1 r - /* PROCEDURE: Chip_Erase */
6 ` T4 U$ p( c. P) P7 ] - /* */& _# ~. S3 f" |6 H g' R$ q
- /* This procedure erases the entire Chip. */
' u, o" o9 M: h5 A+ G# p- S - /* */# G- U, f4 U3 A: L0 k$ \% [6 u
- /* Input: */
( f/ j5 C/ B3 S% h5 t - /* None */4 i4 A7 i B% W& S; @. B
- /* */, l; `5 Y1 s, A' ^2 W; a6 P8 D( A
- /* Returns: */
4 l( u8 A2 @) ?9 ?5 U' q - /* Nothing */3 v& g, b6 @+ _$ u1 i+ b- g
- /************************************************************************/3 J: Q* f) C2 l$ ?- C7 k
- void Chip_Erase()
: k/ h" p3 E5 _; |9 U - { ) Y) m9 a8 j# W2 _
- CE_Low(); /* enable device */( x3 B& s/ N2 e" G# x% T% y
- Send_Byte(0x60); /* send Chip Erase command (60h or C7h) */' L* z2 [+ C1 n6 J; M: ~5 ]
- CE_High(); /* disable device */5 }" c6 B B+ ?, G- F' Y" }) X- X" N
- }3 \9 X# I7 t3 u6 B
' D. T% E; t3 l. M& p% }- /************************************************************************/) D6 D2 T; o$ c- P6 K# F2 w
- /* PROCEDURE: Sector_Erase */
* S/ A9 j1 U2 P5 P& X - /* */
. \9 k3 o# P+ ~ D! M* } - /* This procedure Sector Erases the Chip. */, O. C9 n1 l7 F
- /* */# y1 R1 W" q9 B. D" W% {) \
- /* Input: */2 {3 M- I# O8 b2 \& S
- /* Dst: Destination Address 000000H - 0FFFFFH */' `) J- F1 S4 a8 }+ e- k1 `2 _
- /* */
" ~8 x J: b! K3 y - /* Returns: */4 {8 z. Z1 H) G; \ O; y; f! H
- /* Nothing */
4 \+ ~# \+ H' J2 J# [ - /************************************************************************/8 {+ V0 R/ ^. h/ {+ ]9 }9 I
- void Sector_Erase(unsigned long Dst)
" m6 u, u0 D% l, `1 X { - {: k1 r: D9 w8 j) V- r0 _
- * o8 ~# g! j% X+ _
- # b0 ]9 ]$ H0 [% K$ f
- CE_Low(); /* enable device */: \3 Q! N( X0 g* n* m
- Send_Byte(0x20); /* send Sector Erase command */
- q6 w! w/ r" x8 l' c - Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */) x( w4 t! H% f
- Send_Byte(((Dst & 0xFFFF) >> 8));: P; j' H1 e7 E& K }0 t
- Send_Byte(Dst & 0xFF);
b" X7 j' R" {/ P - CE_High(); /* disable device */7 u+ \$ U; g' j3 Q6 Z2 ]
- } 4 G, S6 p# t) t4 D. L! U/ P+ ~
- N0 S; s+ e, q4 y3 e; V# c: W" t
- /************************************************************************/8 \7 S3 r2 {4 O
- /* PROCEDURE: Block_Erase_32K */
@2 q1 _8 b; i; i% T: S- d - /* */
3 m! \8 H% t0 b - /* This procedure Block Erases 32 KByte of the Chip. */3 z3 U1 `1 d6 d% M& C9 U! Q. T
- /* */
: u* T% l" O: w - /* Input: */
0 B) C) q* p# w: m8 W3 [ - /* Dst: Destination Address 000000H - 0FFFFFH */
) n9 ~7 v) P" ^* ]0 C - /* */
7 H! W" i y/ \: K6 O! l" M5 U8 w - /* Returns: */
; _9 X9 q4 w C6 H+ H - /* Nothing */
1 y' x, X) o, l) v) l - /************************************************************************/
) ]( ], O3 \6 ~% g* q$ X! o - void Block_Erase_32K(unsigned long Dst)
4 J1 l# i( |/ r! R, f - {# c2 ^& f# F% d% M, ]
- CE_Low(); /* enable device */- @! \5 h: Y) n+ }( C
- Send_Byte(0x52); /* send 32 KByte Block Erase command */
$ F M0 l! g9 F0 Z3 S - Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */
( n9 |; M: o0 L) b - Send_Byte(((Dst & 0xFFFF) >> 8));( A# `; @; N% T
- Send_Byte(Dst & 0xFF);- a' G- @# ?, @$ w1 d
- CE_High(); /* disable device */
5 s/ l# j5 R h. {" d0 S; B5 e+ Q - }
- D7 k* C9 Y8 i; {; f - 6 [/ o! |0 S, i6 o6 G$ \9 ^' ^7 S, H$ D
- /************************************************************************/
0 z3 \ a& r1 u3 l, Q. l* h! V) D5 ^ - /* PROCEDURE: Block_Erase_64K */4 [% [6 V* _4 ~% a: }" `1 p
- /* */, I# f; @: m1 l {6 L" B
- /* This procedure Block Erases 64 KByte of the Chip. */+ J6 @/ P" a2 a$ B( P9 q9 D/ }
- /* */+ C6 s5 y1 }! Y5 ?
- /* Input: */
2 k4 c& I3 _, K9 D - /* Dst: Destination Address 000000H - 0FFFFFH */
4 E2 g1 k; S# b! E& q. ?: i4 I - /* */
& q1 @' O2 I9 o - /* Returns: */
$ B1 _$ G0 |$ R6 v6 i3 I - /* Nothing */4 d+ J" o: ^# `3 W4 |
- /************************************************************************/7 h3 r3 G1 ?; ^6 \7 A( j
- void Block_Erase_64K(unsigned long Dst)
! _2 Z. N' V1 Z7 D/ r; B* t+ Z - {, V# p" [, u* H: h3 Q t2 J1 f
- CE_Low(); /* enable device */
+ `0 v5 Q4 A+ t, h( K. W3 S. x$ ^ - Send_Byte(0xD8); /* send 64KByte Block Erase command */: ~5 @3 j! [0 a8 w7 E2 V* H
- Send_Byte(((Dst & 0xFFFFFF) >> 16)); /* send 3 address bytes */4 e2 l% ^1 C1 w7 T; @1 ~
- Send_Byte(((Dst & 0xFFFF) >> 8));
% n1 b2 U! Q% P7 d - Send_Byte(Dst & 0xFF);3 R* ~1 h7 e5 F' X
- CE_High(); /* disable device */
# h5 J8 ]. n2 p% ~- p1 B - }
: V4 D- f$ ^3 \7 {; l$ {( H' `
$ C; S/ U- {- M1 Q0 ?- /************************************************************************/
( Z# B1 B0 I, E - /* PROCEDURE: Wait_Busy */
3 z* X0 r* Y4 ?( v3 d a/ p - /* */4 A; Y: ?: L+ m3 J0 o, s; l8 I
- /* This procedure waits until device is no longer busy (can be used by */
4 c$ o5 Z+ N9 x! v - /* Byte-Program, Sector-Erase, Block-Erase, Chip-Erase). */
4 n8 A w+ `) |" ~. b( l - /* */
8 W2 u, h! c9 B& g1 z - /* Input: */
8 X) g; h" G. @ - /* None */
# Q& Z4 ]! @6 C9 \. ]& C - /* */% F2 z7 ]# A* c1 F# P
- /* Returns: */
+ o$ x$ d: ~# L- M - /* Nothing */ }! G$ k8 \% X2 q' c. a, d/ `; `
- /************************************************************************/
) @: {# C( Q* h4 e) ?0 l/ b! P' [( L - void Wait_Busy()% ?2 A7 U6 V4 {8 C
- {
7 Y* }: m/ ], q7 z" q - while (Read_Status_Register() == 0x03) /* waste time until not busy */+ j! i7 t9 Y, a1 N+ G
- Read_Status_Register();
8 P! X7 g, j/ L( m0 w - }
' k. K- X6 d V& D# d" v - ( x3 r" F% J3 E8 o
- /************************************************************************/$ f: D0 G7 X6 k9 B
- /* PROCEDURE: Wait_Busy_AAI */
8 A# C2 r- u' N( {3 K- y ?; d& M - /* */( f a1 B6 L) b k) {5 y$ Q% U
- /* This procedure waits until device is no longer busy for AAI mode. */
1 p4 M+ ^4 S p: f - /* */
: S' Y% r1 B9 Q' c8 U8 o* Q7 I - /* Input: */
' c& H3 k& G0 l2 R) _1 T$ M - /* None */
% \0 Q& g7 e# P5 {( X8 m7 q - /* */
5 i4 r! t4 R4 s( [6 ^ - /* Returns: */
1 k! F! e0 A" n - /* Nothing */
+ u0 i: ^* C4 \* \4 v" U - /************************************************************************/* Q8 G4 C! g. Y1 v
- void Wait_Busy_AAI(): W* R3 X0 v" }5 V# q- M
- {; P6 |; K; P" G: u5 J( J/ G4 h
- while (Read_Status_Register() == 0x43) /* waste time until not busy */
+ _! f* G) Z* `9 v. R' Q5 C - Read_Status_Register();
3 b3 y4 G8 V, L, L6 F6 z) W - }' b: D; t: i8 \2 u7 {6 }/ E# K# X
8 Y& {% ^! d9 H3 q! ?0 m- /************************************************************************/4 u6 Y' d2 l# Z
- /* PROCEDURE: WREN_Check */
" J' p6 _: \7 d8 t# I) ]( x - /* */
6 x( v f8 x s# o4 C8 Q - /* This procedure checks to see if WEL bit set before program/erase. */
0 J: E8 V" ^3 ]; m5 x6 R; d - /* */6 p" A' b3 C {2 B- f$ _% u% E
- /* Input: */9 `3 g8 c5 Q( q/ q; a
- /* None */& s/ Q- M) M7 t$ L6 y0 k# s
- /* */
: k6 }7 Z2 _% J9 e: I - /* Returns: */( v% p2 D# x m! ~2 @
- /* Nothing */* I* u% J% T& c5 j
- /************************************************************************/* ]5 \7 a3 U' c+ s \; f) p
- void WREN_Check()4 t/ T+ P q# X
- {
* @: |% ?0 ]7 j, \1 K' z - unsigned char byte;0 d& s' L/ y! e, I- D6 a0 s: c
- byte = Read_Status_Register(); /* read the status register */& A5 Y! W% [) M( T& |) w. ?3 a) A
- if (byte != 0x02) /* verify that WEL bit is set */; f4 f, L2 ^9 S- H# Z$ h2 X0 @4 E
- {
2 s* Q- V1 t$ X( E" L% n; a - while(1)
2 f, s3 K# G3 R. s7 O& V - /* add source code or statements for this file */
# F1 m# ?$ j% J4 k/ f7 x - /* to compile */3 f& d) U& E+ |! }: ?, d
- /* i.e. option: insert a display to view error on LED? */* N7 c7 k6 N$ S
- 1 Q2 ^5 ~6 h: @ M( S. ^
- }3 V" v2 O3 Y* \& b: g8 b
- }
$ \* A! _0 z9 c. b8 w0 I - ) i+ {8 V' v* C5 `! O
- /************************************************************************// d. \% P. i( w: M g) _4 ~. r
- /* PROCEDURE: WREN_AAI_Check */7 G( L' p' n8 y
- /* */
0 V$ B+ X/ v1 \$ R4 ~ - /* This procedure checks for AAI and WEL bit once in AAI mode. */7 G& c6 f* r# U+ C. d0 [4 R$ X
- /* */
" |* f% }( m& N' W E - /* Input: */
7 R0 y+ `1 S- R( } - /* None */, V; q3 V+ W: b; s
- /* */
2 l9 }6 [0 I" I) f/ q( p9 E# M - /* Returns: */
4 U2 U$ O1 ]$ j& P - /* Nothing */
8 b9 I$ v: Q& a C; T0 S( ] - /************************************************************************/+ _8 N3 [- g% p3 l0 D
- void WREN_AAI_Check()
& V% M; I% q5 v - {
6 U4 e; l% u7 d2 ^ K2 t - unsigned char byte;& `, w" ~, d. f1 V$ A
- byte = Read_Status_Register(); /* read the status register */( |; L2 J% R3 c4 _& }; B
- if (byte != 0x42) /* verify that AAI and WEL bit is set */
1 H: i" S* N$ N w4 p$ G - {
+ }9 N/ C# ~" V4 K - while(1)
, x( E' o4 @# b% ~ - /* add source code or statements for this file */
7 e8 v: Q" k" p. M - /* to compile */3 A) l; C. x3 b" ^- i3 E
- /* i.e. option: insert a display to view error on LED? */
6 e/ F, @5 |2 g0 i8 A9 Y% c% G
: P! o T2 ?$ R% o! I- }& R' W6 U5 t* c/ U- H
- }' W* h! ^; ^6 f5 E( o
- & @) |2 X& F% H0 h7 k, T' C0 b8 u
- /************************************************************************/
3 P7 c7 t2 ]. d. H+ X! M+ @; l - /* PROCEDURE: Verify */
6 g, N; R* V+ I - /* */
4 o: s* S5 `) S/ ?, e - /* This procedure checks to see if the correct byte has be read. */# d6 S2 l5 `* t- s0 {
- /* */1 G$ f, R4 v9 V7 a5 P
- /* Input: */0 P) K1 v; E8 w+ k9 h: t8 @8 V0 n' G
- /* byte: byte read */
9 F# D) E, i% J/ a4 h" x - /* cor_byte: correct_byte that should be read */7 J1 [: Y# f% l6 `# \" s9 ^
- /* */
: _" h/ W9 s9 C% |: F" E - /* Returns: */
# [" I$ L4 ~8 l - /* Nothing */% a7 n3 d/ f) G2 [ i
- /************************************************************************/
A+ l: n9 x4 e @+ s$ u - void Verify(unsigned char byte, unsigned char cor_byte)
6 X& R/ I& g5 h# `$ N. W) v - {
. P. b: A4 I# [! A9 w( S - if (byte != cor_byte)
* E8 n9 T/ g7 V- [( ^ - {% a3 x, C U" |! r$ O
- while(1); f" q. ]/ n) h) f# p2 n
- /* add source code or statement for this file */( Q) W- x% U1 ]- B, q2 o( T: Y( v
- /* to compile */
6 A! s/ R# `2 E0 S8 n7 [7 ]2 E - /* i.e. option: insert a display to view error on LED? */
/ n4 \! O3 _' ?% ]: R% w* j - % B+ Q v: P9 g$ e0 C- f8 w
- }* J% b- y7 c4 W( Q5 {
- }
& ?8 \; I1 o$ W
5 {$ H0 \0 w& M. y$ H0 B
, q4 @& \2 n! u3 t; a& [- int main()& Z3 C a9 u0 S! v; [* O% G9 {& u+ W
- {: Y7 t. ~$ {: C
- 9 j9 {5 ^9 d: U2 g- ~: g8 |* c
- return 0;
! {( w$ J" ^& N% f9 a/ e - }
复制代码 |
|