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