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