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