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