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