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