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