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