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