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