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