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