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