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