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