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