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