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