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