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