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