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