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