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