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