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