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