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