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