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