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