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