找回密码
 加入计匠网
搜索
热搜: BIOS ACPI CPU Windows
查看: 55768|回复: 13

[Software Driver]SST25VF080B 8 Mbit(1M x 8) Serial Flash Memory

[复制链接]
发表于 2007-11-13 11:07:18 | 显示全部楼层 |阅读模式
EC挂接8Mbit SST25VF080B的话,可参考和学习,其它的SPI FLASH雷同。
  1. Software Driver/ P6 H* e, [) I7 s1 U& X) K
  2. 3 w! K- O7 j$ i3 v1 C5 L
  3. SST25VF080B 8 Mbit(1M x 8) Serial Flash Memory
    9 ~7 I& N+ p4 z+ h7 w
  4. - [" v% r! ~/ I- ~% r( ]2 M2 b
  5. November 4th, 2005, Rev. 1.0) S% \* ~7 {9 h8 t" e* n: A2 j2 u

  6. 9 h- v$ S% @7 s, r( O; p0 F: F/ a' e: r
  7. ABOUT THE SOFTWARE
    - u. O/ U  Z7 _3 L
  8. This application note provides software driver examples for SST25VF080B,+ Y& D6 h# L0 w% t
  9. Serial Flash. Extensive comments are included in each routine to describe 3 [1 t. h. Y% I
  10. the function of each routine.  The interface coding uses polling method
    * I! L; H6 Q' O/ E! L
  11. rather than the SPI protocol to interface with these serial devices.  The, @1 L5 j4 c0 O! J! k8 @* C5 g9 n
  12. functions are differentiated below in terms of the communication protocols+ S* D" O5 p* B  N& A3 W; H4 Q# Q
  13. (uses Mode 0) and specific device operation instructions. This code has been   g! c. h2 ]' s1 P
  14. designed to compile using the Keil compiler.: J; d+ k' _( j' [

  15. $ G& C+ K) C; k
  16. : V. K2 ^0 ^# g
  17. ABOUT THE SST25VF080B
    2 W; z6 F9 y* W0 m! v9 _

  18. 2 k$ H* M7 T$ C, M& {6 x- o
  19. Companion product datasheets for the SST25VF080B should be reviewed in
    ; Q- d! z" J( D7 g  k5 b) j
  20. conjunction with this application note for a complete understanding
    5 M8 W5 z  r: ^, x) Q
  21. of the device.
    , P! }( s9 t3 E" N

  22. 4 S7 a; y1 q" I3 Z/ x
  23. , d! E0 k. w9 a6 `9 ~' I1 g' F
  24. Device Communication Protocol(pinout related) functions:) R% z' P5 z! q8 q% i

  25. 0 _- A) a3 Q0 Z( M& Z  F- Y0 H
  26. Functions                                    Function7 G* @4 b3 A8 G7 z: W! v
  27. ------------------------------------------------------------------
    2 {8 ~1 z# H, ~$ e  C0 b& ~" d2 `8 d* n
  28. init                                        Initializes clock to set up mode 0.$ a- T/ `! o0 ?+ H% e1 ]
  29. Send_Byte                                Sends one byte using SI pin to send and
    9 v2 P) c" j0 v4 A% ^
  30.                                                 shift out 1-bit per clock rising edge
    ) [+ ^/ W' |" ^  b$ }3 \
  31. Get_Byte                                Receives one byte using SO pin to receive and shift
    ! q1 D" C5 G4 o- r1 J: ~. X
  32.                                                 in 1-bit per clock falling edge8 z8 P; K* |# N7 i8 O# d4 k
  33. Poll_SO                                        Used in the polling for RY/BY# of SO during AAI programming
    # y! G! s" j% l1 y' \
  34. CE_High                                        Sets Chip Enable pin of the serial flash to high
    1 _4 Z% e9 ^# P0 i) H! v; ~6 a+ v
  35. CE_Low                                        Clears Chip Enable of the serial flash to low
    : Y  R8 }9 c+ e/ C1 A& P* m
  36. Hold_Low                                Clears Hold pin to make serial flash hold
    5 j9 I; R  j( V) ~/ e
  37. Unhold                                        Unholds the serial flash
    8 K0 s# j! ]' A8 X* j, J
  38. WP_Low                                        Clears WP pin to make serial flash write protected
    " m1 Y2 p6 T/ A& o. c+ N
  39. UnWP                                        Disables write protection pin6 k4 }# S. D& c; U

  40. / z, ?) l$ q1 }1 a% k
  41. Note:  The pin names of the SST25VF080B are used in this application note. The associated test code' Y" r, O$ r/ w
  42. will not compile unless these pinouts (SCK, SI, SO, SO, CE, WP, Hold) are pre-defined on your) B& u3 ^& [! V* }# \& i( g+ X: p
  43. software which should reflect your hardware interfaced.          2 r: m$ T/ w1 `& U7 [

  44. ) J# P. U4 b1 e  Y/ e  I9 q

  45.   v4 I3 j5 e* Z7 z3 p$ `9 Z, O' l/ o# a
  46. Device Operation Instruction functions:( I* P6 g; E: b6 V# k/ F& O% p

  47. ( d! t0 m/ x6 q4 l3 f
  48. Functions                                    Function$ A& y: ^1 Y- k  D+ O/ C
  49. ------------------------------------------------------------------& M& A2 N1 b" r1 G1 v) s3 _1 n# B
  50. Read_Status_Register        Reads the status register of the serial flash
    : _( R4 t; t7 ~7 a" O1 v
  51. EWSR                                        Enables the Write Status Register$ H2 K" J9 ~- h+ U1 h+ B
  52. WRSR                                        Performs a write to the status register
    0 w3 f- @( d9 Y
  53. WREN                                        Write enables the serial flash
    $ H0 \& K2 ?8 K! W
  54. WRDI                                        Write disables the serial flash/ V$ u, \( V: |
  55. EBSY                                        Enable SO to output RY/BY# status during AAI programming
    ; Q" J( ?# c* A4 A4 Q- y. D
  56. DBSY                                        Disable SO to output RY/BY# status during AAI programming
    * Z$ u% ^# n, k0 W2 ^
  57. Read_ID                                        Reads the manufacturer ID and device ID
    % W' d6 l" Y# ]) f
  58. Jedec_ID_Read                        Reads the Jedec ID
    : r; X/ b5 v1 G* ]5 x  ?
  59. Read                                        Reads one byte from the serial flash and returns byte(max of 25 MHz CLK frequency)
    & M  g  v5 o  _# F2 P$ u
  60. Read_Cont                                Reads multiple bytes(max of 25 MHz CLK frequency)6 G6 k4 P# _! y( V
  61. HighSpeed_Read                        Reads one byte from the serial flash and returns byte(max of 50 MHz CLK frequency)
    $ b2 F- y' z3 u" \4 D: X. h/ V
  62. HighSpeed_Read_Cont                Reads multiple bytes(max of 50 MHz CLK frequency)5 p$ c4 \) N  j1 c* J: F4 A
  63. Byte_Program                        Program one byte to the serial flash
    / t7 W- m: L2 X  C% |
  64. Auto_Add_IncA                        Initial Auto Address Increment process! c4 s+ V+ p+ T' w2 X. V+ L* q4 `
  65. Auto_Add_IncB                        Successive Auto_Address_Increment process after AAI initiation
    ! u% Q7 ]5 @; }" x) y4 U, {7 c
  66. Auto_Add_IncA_EBSY                Initial Auto Address Increment process with EBSY- C; z, w# ~" `
  67. Auto_Add_IncB_EBSY                Successive Auto_Address_Increment process after AAI initiation with EBSY and WRDI/DBSY
    & m2 @8 ^3 m7 O; U* l$ X0 z
  68. Chip_Erase                                Erases entire serial flash
    $ |; k# h+ J5 s! c8 }, O- g( p0 Y
  69. Sector_Erase                        Erases one sector (4 KB) of the serial flash1 c0 M* g- z" ?
  70. Block_Erase_32K                        Erases 32 KByte block memory of the serial flash
    # b9 o$ w/ `! t! E. l
  71. Block_Erase_64K                        Erases 64 KByte block memory of the serial flash
    1 o3 [/ R- ?$ S3 D( t
  72. Wait_Busy                                Polls status register until busy bit is low
    4 c) e9 Q: C, l/ c, n
  73. Wait_Busy_AAI                        Polls status register until busy bit is low for AAI programming
    " E' a  q. @: U7 U
  74. WREN_Check                                Checks to see if WEL is set- \# R0 P5 T' e8 k$ Z
  75. WREN_AAI_Check                        Checks to see if WEL and AAI mode is set0 Y7 G: i8 r$ O# H; D" x; P% p
  76.   w  K6 M+ H& C( B

  77. ) U' k; j0 \6 [
  78. 2 R3 ^; q1 b- E$ [! |3 X/ ]! c& X
  79.                                                                      3 j$ `* x. s# B) z6 u: D; x+ ^
  80. "C" LANGUAGE DRIVERS 4 e  U; p$ L8 s. S, g- T
  81. ; e/ f3 x" @# m5 Q! I3 r8 r5 T
  82. /********************************************************************/
    0 y, G) L+ n& ~( ]+ K: c7 I( ^
  83. /* Copyright Silicon Storage Technology, Inc. (SST), 1994-2005            */; T$ q6 \' |; e& i% P$ M
  84. /* Example "C" language Driver of SST25VF080B Serial Flash                        */
    $ R+ R& J  @0 Q4 O+ |7 g
  85. /* Conrado Canio, Silicon Storage Technology, Inc.                  */- d: {2 i4 J$ r7 u7 H, i
  86. /*                                                                  */
    , [2 q+ w! Q# ]
  87. /* Revision 1.0, November 4th, 2005                                                                          */   + D% J/ ^& |2 d1 O4 i
  88. /*                                                                  */
    * z! N9 O- \- _. Z/ d: G9 o$ Q
  89. /*                                                                                                                                        */$ R9 E7 F4 }* G# c
  90. /********************************************************************/
    , t4 E2 ^' S4 C

  91. 0 [3 y. W+ P1 D+ k# n
  92. #include <stdio.h>
    0 D3 {& e. G) h6 ?/ X
  93. #include <stdlib.h>
    . F5 W( L' m6 F& x, g& |$ K; O

  94. + T5 }8 n, h& E' x
  95. /* Function Prototypes */0 C8 {! H9 u" g0 K
  96. 2 d' ?. P9 T  ~8 O9 A* r9 B
  97. void init();  W* X0 h; H: R, I) @& G2 p6 R$ _
  98. void Send_Byte(unsigned char out);2 a8 `9 Q. d9 N5 R5 q2 V4 w, q
  99. unsigned char Get_Byte();" o/ ~. O' m" b# y
  100. void Poll_SO();
    1 ]% v: h) D3 u3 a9 Q
  101. void CE_High();
    ' k3 U: Z  P0 T$ H. p3 ]
  102. void CE_Low();( a% i* h9 G) y  Y& r( J
  103. void Hold_Low();. H& a' J! v9 q5 z: n
  104. void Unhold();
    2 T% F; v' n! ^; b) P
  105. void WP_Low();( W5 u+ j, N( [, a
  106. void UnWP();& s9 U6 J$ s' J+ d/ K
  107. unsigned char Read_Status_Register();/ I# j9 t3 b6 i% S
  108. void EWSR();7 \# I+ L7 M0 V+ s4 G
  109. void WRSR(byte);; o$ E  i  _6 p; ]. Z1 R
  110. void WREN();- @5 G# [- k5 f, y1 U# S
  111. void WRDI();
    9 x: U7 \% ]2 c* h
  112. void EBSY();
    + w$ B- j5 ^, h  Y6 |# y# {7 W" D( J: U
  113. void DBSY();% x9 {# V$ g) b0 B6 i! Y
  114. unsigned char Read_ID(ID_addr);/ k5 X6 t* d9 y( w0 j) f
  115. unsigned long Jedec_ID_Read(); 6 L: \. [) A% ], v' j$ }0 {: `8 P
  116. unsigned char Read(unsigned long Dst);
    0 d- c/ K, |# E  R, F& G: D
  117. void Read_Cont(unsigned long Dst, unsigned long no_bytes);3 x! A/ |6 l. S) m
  118. unsigned char HighSpeed_Read(unsigned long Dst); ( ~8 b1 u3 L& H
  119. void HighSpeed_Read_Cont(unsigned long Dst, unsigned long no_bytes);& ?" j% K! R+ j7 z( F
  120. void Byte_Program(unsigned long Dst, unsigned char byte);
    * V4 f- E& G: j  ^% s9 S& n
  121. void Auto_Add_IncA(unsigned long Dst, unsigned char byte1, unsigned char byte2);1 A$ ?( q& a! g, L% A& l
  122. void Auto_Add_IncB(unsigned char byte1, unsigned char byte2);
    5 O( L% h! [+ K/ {, {
  123. void Auto_Add_IncA_EBSY(unsigned long Dst, unsigned char byte1, unsigned char byte2);  G! m% O9 W: k) f
  124. void Auto_Add_IncB_EBSY(unsigned char byte1, unsigned char byte2);
    * i: b) p5 M! t6 q% U
  125. void Chip_Erase();! w# b% J4 V4 ~( F
  126. void Sector_Erase(unsigned long Dst);
    & F7 d5 i3 L; X/ W+ D0 [% C
  127. void Block_Erase_32K(unsigned long Dst);
    & X' Z8 @5 I$ x# V, A1 B" y
  128. void Block_Erase_64K(unsigned long Dst);
    4 N5 W+ W( H& d. v
  129. void Wait_Busy();
    ( u5 ~5 y  i2 D  D2 u0 k# o
  130. void Wait_Busy_AAI();  ]3 L) E" d/ p5 H/ o
  131. void WREN_Check();! @5 l& Y! M7 F8 _# Y# f/ t' m
  132. void WREN_AAI_Check();( R( {! C+ j, S* K. e: z
  133. ( |0 I8 W3 h$ q4 H3 b
  134. void Verify(unsigned char byte, unsigned char cor_byte);3 W; C. i, T/ o: w. K2 W" f

  135. 3 O7 d- {) X5 D2 x, \
  136. unsigned char idata upper_128[128];                /* global array to store read data */
    4 W7 n1 s- S: @0 |9 ]1 P1 c" j
  137.                                                                                 /* to upper RAM area from 80H - FFH */
    ! ]3 N/ O/ y# A! g) p( Q
  138. 4 i5 R' \8 p; g- c
  139. /************************************************************************/
    9 K7 R# m: j: v( p8 K, ^; n
  140. /* PROCEDURE: init                                                                                                                */
    ) A" c' @* B! X: t/ \
  141. /*                                                                                                                                                */
    & ]1 g  e3 y- B% a( a, I
  142. /* This procedure initializes the SCK to low. Must be called prior to         */
    % r8 i# r( o% z! {1 y  U
  143. /* setting up mode 0.                                                                                                        */( M8 k4 J( K& r# k/ Z* I
  144. /*                                                                                                                                                */
    2 F( ^+ i% ~" C3 O
  145. /* Input:                                                                                                                                */
    $ R- P0 y4 S  Z
  146. /*                None                                                                                                                        */
    : P7 ]6 b9 f! \0 H
  147. /*                                                                                                                                                */2 f4 Y$ J5 B: a' w) D4 ^$ c
  148. /* Output:                                                                                                                                */3 H8 n0 R1 X1 b; C% W; U- w
  149. /*                SCK                                                                                                                                */
    ! _; ~' O, h3 y( {( C$ ]- U
  150. /************************************************************************/
    " _( {' h  x- u
  151. void init()
    # H% \4 }+ B( @
  152. {) y# Z% ^; {# X1 b8 e
  153.         SCK = 0;        /* set clock to low initial state */
    2 e; e8 z, C5 t& I; z
  154. }
    ! n$ ~! u. f, F8 D7 C! B- t/ E

  155. 9 ]) H+ ]3 A8 w' W3 z+ n6 c2 _: ~+ c: j
  156. /************************************************************************/1 d6 D$ {6 w3 B4 ^% A; q0 w. d4 q  _5 {
  157. /* PROCEDURE: Send_Byte                                                                                                        */
    & S: V) x7 C8 j9 D
  158. /*                                                                                                                                                */
    2 c) {9 K" e5 z7 `7 [5 X, y
  159. /* This procedure outputs a byte shifting out 1-bit per clock rising        */! f; r) b' U' M2 V- @! _
  160. /* edge on the the SI pin(LSB 1st).                                                                                */8 q! u; _6 ~0 F2 T8 \- @6 B: M7 l
  161. /*                                                                                                                                                */
    + H+ o. S2 m& G2 e. {  h+ r! P" v: i
  162. /* Input:                                                                                                                                */
    0 V7 w& i; \% k
  163. /*                out                                                                                                                                */6 y4 n' m, U# Y, j3 u* W4 ~
  164. /*                                                                                                                                                */+ V* }, ^5 c1 e* I& y$ Z6 U/ q
  165. /* Output:                                                                                                                                */
    & g  G5 i8 B% A- O
  166. /*                SI                                                                                                                                */. j$ M8 F$ T- w( o! P
  167. /************************************************************************/& @/ Z9 K9 h4 C% c3 ]
  168. void Send_Byte(unsigned char out)
    ! s+ I7 f& q. w& F$ D- ^( p+ X
  169. {. K' ?6 M0 j" A$ G( E
  170.        
    * W  C; }' k! k0 l3 C3 a9 g4 ]
  171.         unsigned char i = 0;
    - Q3 Z: M" B5 |+ ?; U. p
  172.         for (i = 0; i < 8; i++)
    9 l: g: C6 k! @7 ]
  173.         {- j* y. O7 ~: Z8 S5 b' y
  174.                 , U9 _$ D2 f6 V8 t; v# t
  175.                 if ((out & 0x80) == 0x80)        /* check if MSB is high */
    3 \" U# h& w0 h7 Q& T
  176.                         SI = 1;
    $ {0 G9 h. F" j: G
  177.                 else
    " R' s- P0 P$ R9 k1 [* a3 T9 L7 o
  178.                         SI = 0;                                /* if not, set to low */) v( k3 n- [! D; n0 f  {
  179.                 SCK = 1;                                /* toggle clock high */
    ( P* A7 j. M7 s, ]+ m( [' N9 N
  180.                 out = (out << 1);                /* shift 1 place for next bit */* X4 W- |8 ]) Z
  181.                 SCK = 0;                                /* toggle clock low */
    % W" x( V: K1 a( m$ e
  182.         }
    6 r5 e/ u1 k$ x! V
  183. }/ Y0 \3 p% K" R5 G2 i, O8 ]: v

  184. : p8 _, |/ e9 |. J
  185. /************************************************************************/$ b4 n) R) O, q7 Z5 S/ g# ^; `/ X% t
  186. /* PROCEDURE: Get_Byte                                                                                                        */
    * T; |1 o8 L; O2 H2 X  I# _
  187. /*                                                                                                                                                */
    % B) v6 z- E- E( Z! B
  188. /* This procedure inputs a byte shifting in 1-bit per clock falling                */
    - N+ S. E/ a% u% \$ z8 O
  189. /* edge on the SO pin(LSB 1st).                                                                                        */
    5 b* V( }8 M* a. X- j
  190. /*                                                                                                                                                */
    6 v+ i' s4 T/ m" m& c0 _# b
  191. /* Input:                                                                                                                                */) j; l6 i7 c# u/ P
  192. /*                SO                                                                                                                                */
    & b$ C$ k) H0 W0 [5 ?; G7 V: m
  193. /*                                                                                                                                                */
    4 X$ ~* \: j: |0 u
  194. /* Output:                                                                                                                                */
    & Q/ C0 \+ _- _7 }2 K4 x) w2 O
  195. /*                None                                                                                                                        */
    # {+ [) I0 ~# T6 E2 r8 O: p( {
  196. /************************************************************************/2 ?4 X( N! e4 C/ r# e( f
  197. unsigned char Get_Byte()1 F0 t; e2 ]$ ]* @3 H* l
  198. {
    $ g6 g' J6 J! r+ f# C: H
  199.         unsigned char i = 0, in = 0, temp = 0;; i$ ?$ w8 C/ X% Y: u# O
  200.         for (i = 0; i < 8; i++)6 A& ?+ E) r, |' R
  201.         {
    8 ]2 R/ r/ b4 ]* h; M! j0 U
  202.                 in = (in << 1);                /* shift 1 place to the left or shift in 0 */2 ~) U3 m! O+ h
  203.                 temp = SO;                        /* save input */3 e; Z% E6 a  U; P4 R
  204.                 SCK = 1;                        /* toggle clock high */5 [3 c3 N! y, b) U/ j( ]2 N
  205.                 if (temp == 1)                        /* check to see if bit is high */
    : J+ U, v1 k3 j
  206.                         in = in | 0x01;                /* if high, make bit high */
    ; Y  |0 r' Q2 c" Y+ p# i; X0 P
  207. 4 q& j8 v! i5 z) J) V4 ?7 s
  208.                 SCK = 0;                        /* toggle clock low */- g, j3 ~6 e7 r3 B: ]# ?" b

  209. ( J$ b8 w9 F1 L
  210.         }( b5 W- I: a+ o% S! I, W
  211.         return in;5 k) T" \. h  A9 a2 K
  212. }7 z2 o' G2 l! J, d

  213. ) b  s+ `4 R# L" V' ^
  214. /************************************************************************/9 x' [8 b0 E1 X! Y* g  z
  215. /* PROCEDURE: Poll_SO                                                                                                        */+ P$ A8 z' \5 U; a$ L9 h# _
  216. /*                                                                                                                                                */+ Y% z1 r8 c. B- S! f
  217. /* This procedure polls for the SO line during AAI programming                  */
    - D6 w2 Q) t8 z$ c/ Q* A5 j
  218. /* waiting for SO to transition to 1 which will indicate AAI programming*/
    . K$ \# d. O3 T5 c4 R, y
  219. /* is completed                                                                                                                        */! Z6 {0 E& Z2 g; b" i; ^- g
  220. /*                                                                                                                                                */
    . M) q- d) f% y" a
  221. /* Input:                                                                                                                                */
    * [! N4 w3 F) h  @' G: m! g
  222. /*                SO                                                                                                                                */% ]0 u" u; l$ f- H% A
  223. /*                                                                                                                                                */- ~  K1 W( \' f# {+ A6 @) {
  224. /* Output:                                                                                                                                */
    " i+ I2 ~! O' I
  225. /*                None                                                                                                                        */
    3 T. R- i" c9 R  n
  226. /************************************************************************/' {9 V9 S7 Z8 n# ~4 w5 t2 ~9 ?& b# X3 T
  227. void Poll_SO()3 \# G4 G# B+ T% l8 d
  228. {
    * I  d0 a; x4 s& B8 }4 u
  229.         unsigned char temp = 0;4 ^1 b6 Y$ [' X
  230.         CE_Low();) C3 u! y, E: B+ {) M
  231.     while (temp == 0x00)        /* waste time until not busy */
    ' }" D, C& O9 x7 Y
  232.                 temp = SO;' s; Q& I9 p7 d, G& C# ?: h
  233.         CE_High();9 L, i+ _1 K# z
  234. }
    & O: i8 s1 @& H9 q2 L$ \

  235.   z' {: J. \5 F- V: M% i
  236. /************************************************************************/. p! j- K4 b% a' h
  237. /* PROCEDURE: CE_High                                                                                                        */: N( r, @1 _" h6 v: [2 ]3 r
  238. /*                                                                                                                                                */
    ) S# O- P* g$ R- ]/ K. |. K
  239. /* This procedure set CE = High.                                                                                */* E& @( Q& e$ v: ~2 H
  240. /*                                                                                                                                                */
    ( l  }+ V0 o5 b
  241. /* Input:                                                                                                                                */: P6 r0 \( U, y. F
  242. /*                None                                                                                                                        */" ^8 N+ N; M3 N8 u
  243. /*                                                                                                                                                */4 E+ R' A3 ~6 v' a6 Q6 H
  244. /* Output:                                                                                                                                */
    . w8 D+ a7 ^1 n9 a0 w6 g( U
  245. /*                CE                                                                                                                                */1 A9 B% ^. M1 A/ g& o. G
  246. /*                                                                                                                                                */2 }- A& q: P2 r2 l9 h" ]# d6 f
  247. /************************************************************************/. l  W8 k. M9 B+ P$ ?
  248. void CE_High() ! M2 }& _/ I; t, A$ x/ y
  249. {
    8 E3 _; w: V0 ]* p8 i
  250.         CE = 1;                                /* set CE high */  X. v6 Z' X; t9 C) Z3 y
  251. }$ H8 ]. }& [; D+ V- K# ]

  252. / x1 r; x* ?5 d3 T  e* N' S; ~) w
  253. /************************************************************************/
    0 u& S( q  ^0 P3 s: V* E! U: v
  254. /* PROCEDURE: CE_Low                                                                                                        */; y' i  B& S6 g- M! B
  255. /*                                                                                                                                                */: d. U2 d  Z9 K/ f4 r  \* d+ j. I
  256. /* This procedure drives the CE of the device to low.                                          */; {6 d( R! s. K0 l  i3 I- Z
  257. /*                                                                                                                                                */$ T& m, E: N0 U/ ^) o
  258. /* Input:                                                                                                                                */
    . h* B, ~1 g# ]4 }! e/ W
  259. /*                None                                                                                                                        */
    - W; i: o6 |& A% N! _& D
  260. /*                                                                                                                                                */
    - H7 Y' `4 N1 l$ {3 g5 A
  261. /* Output:                                                                                                                                */
    / q3 [) z$ S7 L
  262. /*                CE                                                                                                                                */
    3 P1 s4 ]: A4 T  G
  263. /*                                                                                                                                                */
    # G4 Q* B+ S! f$ z: _
  264. /************************************************************************/
    3 g1 G# v# v  N/ y) G& d
  265. void CE_Low()
    ! F$ y& M5 e! G7 Y
  266. {        / E$ @8 N" |3 O( s) H
  267.         CE = 0;                                /* clear CE low */+ z2 D: X" ?& C& j
  268. }( ?! _' B4 {9 \1 W7 U2 Q

  269. 9 T- `$ s! V+ |8 y! |
  270. /************************************************************************/
    / r4 A6 K0 R) B
  271. /* PROCEDURE: Hold()                                                                                                        */6 C$ s* X" Z! C
  272. /*                                                                                                                                                */- E7 N" J. `- [3 C, Y! v# X$ s
  273. /* This procedure clears the Hold pin to low.                                                        */
    $ d7 t5 r- |% z) X2 y8 k
  274. /*                                                                                                                                                */4 Y% I: \- u) n7 A
  275. /* Input:                                                                                                                                */
    ' T% R; \  I) M. A0 {
  276. /*                None                                                                                                                        */3 e, E1 L3 {- O3 B& C
  277. /*                                                                                                                                                */& I  s# D3 x* N( U4 @6 p( P
  278. /* Output:                                                                                                                                */8 B7 y0 D& Y# B) D
  279. /*                Hold                                                                                                                        */5 U! z7 K6 t. P: D  v
  280. /************************************************************************/; u9 X  i6 m7 l/ M& e3 Q/ C. y0 H2 x
  281. void Hold_Low()
    8 m/ t& v" I) z  U# R3 l
  282. {
    & m" E7 \: E( D5 E
  283.         Hold = 0;                        /* clear Hold pin */
    - l; x! S3 F  ]. ~  u
  284. }$ b) P. s! @8 h( D7 g
  285. 7 k3 C$ R2 f9 s8 i/ l+ P4 j
  286. /************************************************************************/" {; \6 o* g. R* a3 z
  287. /* PROCEDURE: Unhold()                                                                                                        */2 G. X0 ^9 l7 L- y4 t! \9 L
  288. /*                                                                                                                                                */
    & {8 [& E( t4 B8 i) n) ?* I# `! r. f
  289. /* This procedure sets the Hold pin to high.                                                        */
    / c% y( t  r! F7 T0 X( L  m
  290. /*                                                                                                                                                */7 X* y! c+ X; B, P. b
  291. /* Input:                                                                                                                                *// E* U, W. d1 Y, N0 W
  292. /*                None                                                                                                                        */
    + H7 m, Z; D& X2 e4 C& c" i4 T
  293. /*                                                                                                                                                */
    , l  C( Z2 p( z" f
  294. /* Output:                                                                                                                                */$ T9 p( C& J  a( [
  295. /*                Hold                                                                                                                        */
    1 R# g% q. J5 S+ l6 [) J6 v; v. I/ S; s4 K
  296. /************************************************************************/
    ! e' B! C8 H7 }# Y8 Q3 O& N
  297. void Unhold()& O* X* A" n9 M1 _6 M4 G: d7 e9 J7 k
  298. {
    1 \# S+ s# {- t6 g0 v
  299.         Hold = 1;                        /* set Hold pin */
    2 b9 X- \& ?  m* I9 b
  300. }% ?4 G; M( u" ~7 @$ p

  301. / X+ c$ i; R" {
  302. /************************************************************************/
    0 s- U$ R6 v& d$ c5 Q: G
  303. /* PROCEDURE: WP()                                                                                                                */
    ) B0 H0 n7 V8 i# p- W" q& H. M$ W8 n7 Y
  304. /*                                                                                                                                                */
    2 ~- b2 h7 i% Q* E4 W: K
  305. /* This procedure clears the WP pin to low.                                                                */* _$ {0 V" Y7 G
  306. /*                                                                                                                                                */1 G" ?- u7 i& J! O) P3 Z
  307. /* Input:                                                                                                                                */
    + v* ^2 f- O; |  Q
  308. /*                None                                                                                                                        */* T2 w& G! F. `" Z# V4 V0 \5 l  `" T
  309. /*                                                                                                                                                */" O; T4 s% s2 N% l/ H1 c) a  B
  310. /* Output:                                                                                                                                */
    . m  W* T/ t# Z- h" ?; n! Z
  311. /*                WP                                                                                                                                */( T+ |- K% R. q* `" J2 F7 m6 j
  312. /************************************************************************/
    " g$ p" N- o) I5 O: l- o
  313. void WP_Low()
    : w( d* E) I9 G1 k1 D1 [) m5 v$ ]7 o
  314. {
    ; F$ U) f$ L7 Z, C5 L2 C  S* c$ U, Z
  315.         WP = 0;                                /* clear WP pin */
    " Q. |% }' P& C, }/ H
  316. }
    0 N' J; H" ^, m: a4 K8 ?
  317. # \" g8 Y: U+ A6 |, I- i% u
  318. /************************************************************************/% ~, L3 [# X  V- _7 W
  319. /* PROCEDURE: UnWP()                                                                                                        */
    : T6 ]; R6 _; i# E; R1 m; L
  320. /*                                                                                                                                                */
    5 A3 p3 n4 e9 ?- \: O
  321. /* This procedure sets the WP pin to high.                                                                */7 d; I1 X: m, o  n( t. m0 }
  322. /*                                                                                                                                                */0 J3 L% K% G' b, |/ M
  323. /* Input:                                                                                                                                */) O" g5 O/ O; A& V- e
  324. /*                None                                                                                                                        */
    4 g2 H$ u" T% n. t' h- ~7 y" Y
  325. /*                                                                                                                                                */
    ' E9 F/ V, [  F1 ]% K. m: P7 g
  326. /* Output:                                                                                                                                *// {+ R5 x* Z( ?+ x3 J, X4 G1 o
  327. /*                WP                                                                                                                                */
    5 V1 Q. s( H2 h+ z6 l( k3 V
  328. /************************************************************************/
    3 ]& g3 c* e0 p- C: s; w. I
  329. void UnWP()$ q# c3 k! m. _7 l# T. G
  330. {2 B/ q7 c$ }# J. d' ?! f( A$ p. q6 C0 H. d
  331.         WP = 1;                                /* set WP pin */2 E) e0 R; u  ]! D( d% Y6 F
  332. }4 E7 n9 k' S. I* O8 d8 j+ t$ ^6 a

  333. & [9 `$ }/ i+ m, b
  334. /************************************************************************/
    8 a: m/ |2 j3 `6 r
  335. /* PROCEDURE: Read_Status_Register                                                                                */  i/ q) l2 z; ^8 \: @/ i
  336. /*                                                                                                                                                */8 k0 c; ~2 o- T
  337. /* This procedure read the status register and returns the byte.                */
    : X& W7 `8 ~1 a  x5 J
  338. /*                                                                                                                                                */
    6 q+ F# T7 j. N1 W6 T; _* F
  339. /* Input:                                                                                                                                */
    & R; S; n4 d3 p+ O, M
  340. /*                None                                                                                                                        */, y) s8 {. h0 ~7 c% ?
  341. /*                                                                                                                                                */
    9 ~7 t) D7 \; ]
  342. /* Returns:                                                                                                                                */
    4 d2 [4 d: l& Z
  343. /*                byte                                                                                                                        */
    & M& h; T. `3 {8 |; h( W
  344. /************************************************************************/
    1 f! p# W5 s8 {: S% u
  345. unsigned char Read_Status_Register()" E6 U% ]2 ?1 c0 }) R7 t9 j% m
  346. {
    . p9 K) ?) D* z3 T3 U+ e" f
  347.         unsigned char byte = 0;: T: @# k3 c/ v# g
  348.         CE_Low();                                /* enable device */
    + F, g; E$ j/ D* |  w
  349.         Send_Byte(0x05);                /* send RDSR command */
    : O$ i1 G+ n, s  y& s" _
  350.         byte = Get_Byte();                /* receive byte */
    * X' l9 E: I+ Z; R1 b- M
  351.         CE_High();                                /* disable device */, ~  [/ b; Y1 P+ n
  352.         return byte;
    . P* w* K! S1 i' }$ r
  353. }" C/ A& A: h& p6 I
  354. : ~! J5 D+ K+ K
  355. /************************************************************************/9 D- C3 ^7 @9 i7 A2 j  o3 I9 @! n
  356. /* PROCEDURE: EWSR                                                                                                                */, A, j0 P9 u8 K) i
  357. /*                                                                                                                                                */' J4 n6 }' X: k6 {# T- Q
  358. /* This procedure Enables Write Status Register.                                                  */$ J5 X% f1 Z5 G9 t
  359. /*                                                                                                                                                */3 [/ y, ?# u  g+ K9 A3 n- C2 i, |
  360. /* Input:                                                                                                                                */
    7 u9 z1 ~- d- i
  361. /*                None                                                                                                                        */! `9 W" D* D8 K3 P/ H! J0 b
  362. /*                                                                                                                                                */! M8 j! M; v$ `  ?4 u. L; n
  363. /* Returns:                                                                                                                                */. R. d2 G! j& C$ G
  364. /*                Nothing                                                                                                                        */
    ( u, }5 H4 a% H: }
  365. /************************************************************************/
    ! D9 j4 z* F9 f5 J* E: Z. _
  366. void EWSR()
    : L& y0 K* q( B7 j
  367. {1 A3 W6 Z7 a, p0 N) P
  368.         CE_Low();                                /* enable device */! I9 ]( l' L8 M) c* p6 V
  369.         Send_Byte(0x50);                /* enable writing to the status register */' v/ k, @6 k2 L
  370.         CE_High();                                /* disable device */; I4 c! _7 s9 {6 e- D5 l- s4 f3 K
  371. }
    # D' D; K4 `) D" m* J* L
  372. 3 s& s  A( ^* a1 P% j0 t& u( u
  373. /************************************************************************/& P" z, V' W6 }- {) i. l
  374. /* PROCEDURE: WRSR                                                                                                                */
    + t" W, ]3 {$ r( A6 ^
  375. /*                                                                                                                                                */
    , V0 y: r$ W/ j; J" m2 l+ [7 Z1 j
  376. /* This procedure writes a byte to the Status Register.                                        */: S& [0 X! Q) P1 y- g9 q  c" _) U
  377. /*                                                                                                                                                */
    # U/ A# |7 x& T" C0 W+ M0 a
  378. /* Input:                                                                                                                                */
    " W) x, p$ [( g& T. _
  379. /*                byte                                                                                                                        */
    " w7 v! Q% I0 M3 K) D
  380. /*                                                                                                                                                */! @  n1 {+ D; B" |
  381. /* Returns:                                                                                                                                */1 f1 S% }- ]' J( `3 j5 O$ v
  382. /*                Nothing                                                                                                                        */0 L, K- e  J( [1 g" \
  383. /************************************************************************/% `8 a+ s5 p. v1 Z
  384. void WRSR(byte)
    5 d+ k* X  A! }: ~! A: ?+ q
  385. {% Q3 C8 W" a3 z* i3 n& U! y
  386.         CE_Low();                                /* enable device */
    0 z% M. e! o, m, ~4 |- _
  387.         Send_Byte(0x01);                /* select write to status register */2 _4 T3 a3 J6 ?
  388.         Send_Byte(byte);                /* data that will change the status of BPx 0 ~( i: b" }2 G, l
  389.                                                                 or BPL (only bits 2,3,4,5,7 can be written) */; U' r2 V+ ^: h  e
  390.         CE_High();                                /* disable the device */1 D' S  }; d9 ~  y5 |
  391. }6 E2 A9 B" X# N, c7 Q. @$ [! b

  392. 5 U9 J9 P) \# O7 g. G% ?5 {
  393. /************************************************************************/
    $ _) ^$ @) J  k7 ~2 O$ d( @  l. ]
  394. /* PROCEDURE: WREN                                                                                                                */
    + D- {7 d" i# ]( x) w4 h; R, X
  395. /*                                                                                                                                                */
    ' u4 j- X3 N9 _9 w4 p7 V
  396. /* This procedure enables the Write Enable Latch.  It can also be used         */
    1 `# p1 S; {- O2 n4 d- D
  397. /* to Enables Write Status Register.                                                                        */
    / O5 p& ^# `3 c! p$ h& d% x$ ^
  398. /*                                                                                                                                                */
    4 b$ F/ u' f' n& \! \
  399. /* Input:                                                                                                                                */% j  B! u( J( ~; O& A; i# m5 ?* j: L( u( x2 n
  400. /*                None                                                                                                                        */
    & }+ b9 L1 C( W
  401. /*                                                                                                                                                */
    3 Y. y# v( K; r
  402. /* Returns:                                                                                                                                */- n; \+ V& E: j7 `/ E
  403. /*                Nothing                                                                                                                        */6 ]- A) @! @. X, S
  404. /************************************************************************/
    ! {# k3 Y1 |+ @
  405. void WREN()8 p) O) [( H% C7 I' d
  406. {% U  x8 C$ u1 O. _6 R3 \7 o" N/ W
  407.         CE_Low();                                /* enable device */
    % o* D( G% S2 V, L0 [  ^3 j) @
  408.         Send_Byte(0x06);                /* send WREN command */
    / p& q- y3 [( T' d: [
  409.         CE_High();                                /* disable device */2 G" X* N% |8 c7 z9 ?, Y
  410. }6 k2 ~9 ?6 a  b: C: h1 C
  411. ; u( X* j+ w! q- [* K+ \  N9 T% V
  412. /************************************************************************/
    % L4 l5 m# v9 q1 l% W6 }8 T) K
  413. /* PROCEDURE: WRDI                                                                                                                */
    9 O+ x9 e& F7 C9 O: x
  414. /*                                                                                                                                                */2 a: t: p6 w- `$ Q9 [$ H
  415. /* This procedure disables the Write Enable Latch.                                                */; e7 W, [+ A% R0 @2 X0 j& r: r
  416. /*                                                                                                                                                */! `* _3 F1 _* ?5 R
  417. /* Input:                                                                                                                                */! m& K/ j, y$ ^  |  B7 D$ X0 H$ {" w
  418. /*                None                                                                                                                        */
    ' U) A1 v- p: M# y' w1 p
  419. /*                                                                                                                                                */
    ; p) F7 k( |6 {# d
  420. /* Returns:                                                                                                                                */
    9 _+ w  X4 [+ @0 w
  421. /*                Nothing                                                                                                                        */, G" `) R3 p7 z! ~/ v% G, b
  422. /************************************************************************/5 x# p3 g- l. n5 _
  423. void WRDI(). S- {6 b7 j: P5 }4 |$ [$ s) i
  424. {
    2 y: C# B" j$ @9 F+ `: G) x+ ~' ]
  425.         CE_Low();                                /* enable device */" T8 e- R# b. ~+ ^
  426.         Send_Byte(0x04);                /* send WRDI command */
      ^  v4 U+ e/ a
  427.         CE_High();                                /* disable device */8 i" G; o& ^2 q  U  B
  428. }
    ! d7 K& C& |9 v5 V" R
  429.   E+ Z0 v' {  q
  430. /************************************************************************/
    ! O& S  l  m; j3 u) ?. e' ?
  431. /* PROCEDURE: EBSY                                                                                                                */
    1 N$ Z& {  l. z1 |8 A* E
  432. /*                                                                                                                                                */9 h* ?# X7 M( q
  433. /* This procedure enable SO to output RY/BY# status during AAI                         */
    7 f8 W6 {2 V3 z# |
  434. /* programming.                                                                                                                        */4 n" f( @' v% A4 e% _' s/ c
  435. /*                                                                                                                                                */- a9 ]* n6 e* d
  436. /* Input:                                                                                                                                */; D% H. ?2 D  K$ S: E% `4 l
  437. /*                None                                                                                                                        */, d9 V! x/ U/ E2 U% u: d
  438. /*                                                                                                                                                */3 F. ^8 \7 M0 ]! u+ F. \
  439. /* Returns:                                                                                                                                */4 l. }6 K( {" P. y; b6 O
  440. /*                Nothing                                                                                                                        */3 n. m- f( P8 d7 U3 f" c
  441. /************************************************************************/
    0 X/ H, M1 m# R) W! p& i% d
  442. void EBSY()0 D) }% X; \2 Y8 M1 J7 b& J
  443. {" @5 Z+ W, Y. n( {
  444.         CE_Low();                                /* enable device */# s3 @" g) @6 m! S
  445.         Send_Byte(0x70);                /* send EBSY command */
    0 H7 M# _" {5 h8 U9 I4 x1 @! h: {
  446.         CE_High();                                /* disable device */( N1 I9 @# d  h- |6 f5 l
  447. }$ }! [% Y! n3 M) v
  448. + G5 r* h/ z1 q' A
  449. /************************************************************************/
    4 Y$ M: }* s- K, h- T% E
  450. /* PROCEDURE: DBSY                                                                                                                */; `7 ~  f+ P/ x: S8 K8 {: I& w
  451. /*                                                                                                                                                */. E" }/ W) ~% e& e# d2 _
  452. /* This procedure disable SO as output RY/BY# status signal during AAI        */' ~2 {# P& g( l+ h7 L
  453. /* programming.                                                                                                                        */
    # V: O/ J3 e, Z/ X' y2 T" f+ F7 Z
  454. /*                                                                                                                                                */
    ) u+ J: X: C* s1 g" P6 X) v/ E
  455. /* Input:                                                                                                                                */
    ) J6 P' @* V4 ?
  456. /*                None                                                                                                                        */
    & g  b+ d3 v- Z. w6 m: j
  457. /*                                                                                                                                                */7 y7 |4 x1 L# \7 `; \/ d  v
  458. /* Returns:                                                                                                                                */
    ; Z& }8 u4 G3 D/ V
  459. /*                Nothing                                                                                                                        */
      z. Y' |8 k3 e/ e
  460. /************************************************************************/
    - h$ C3 b2 g# j
  461. void DBSY()3 b& M5 ]' t+ c# X3 q! N5 `+ @
  462. {
    , l! f: {8 l# \8 h" f" n
  463.         CE_Low();                                /* enable device */
    0 ?% J: k% g9 Q3 Z( z( A/ y- Z
  464.         Send_Byte(0x80);                /* send DBSY command */) ~& K7 K, K9 p. l
  465.         CE_High();                                /* disable device */
    ; u1 E+ m/ c) L: G) \
  466. }/ P  d+ O( g; ^; u" i

  467. % g; u2 f0 ?$ W1 i3 T
  468. /************************************************************************/
    # q4 r- w, v, y' J0 ]8 w
  469. /* PROCEDURE: Read_ID                                                                                                        */- A5 I" y# Z, e) M
  470. /*                                                                                                                                                */
    9 c* w) O3 X' o4 n8 O7 F
  471. /* This procedure Reads the manufacturer's ID and device ID.  It will         */
    ) H7 X' [& d1 R6 h9 I$ e! T
  472. /* use 90h or ABh as the command to read the ID (90h in this sample).   */
    2 F# V# ~6 Q- k) X- ~
  473. /* It is up to the user to give the last byte ID_addr to determine      */
    ( u8 u3 a; K1 w0 F) k
  474. /* whether the device outputs manufacturer's ID first, or device ID         */
      N" L: ^2 X1 V: ?- O( `
  475. /* first.  Please see the product datasheet for details.  Returns ID in */
    3 E: L# D8 \+ o  |7 Y
  476. /* variable byte.                                                                                                                */8 i# b; S! o! P3 t2 [1 {, K
  477. /*                                                                                                                                                */
    4 x* N9 _" i* Z! n
  478. /* Input:                                                                                                                                */
    " L' L* I) p9 D" d8 E
  479. /*                ID_addr                                                                                                                        */# [$ u# }2 w2 K5 ^) I
  480. /*                                                                                                                                                */# a3 d: ^7 t3 S8 F9 U( E
  481. /* Returns:                                                                                                                                */
    ; M9 z  d9 e, e9 t3 Y! n
  482. /*                byte:        ID1(Manufacture's ID = BFh or Device ID = 8Eh)                        */
    3 p# V, I$ f" l+ C1 ?8 N/ A
  483. /*                                                                                                                                                */! l& q: S* ^( X% U
  484. /************************************************************************/
    ! Y* |$ Q: V$ m- a- ^6 W
  485. unsigned char Read_ID(ID_addr)% L0 r- a& W3 f- }' u7 R
  486. {
    # X1 V7 |( I# i1 \3 i
  487.         unsigned char byte;
    ) i' t7 H% y$ E/ ^
  488.         CE_Low();                                /* enable device */$ R' M2 j, Y: [' u+ d% {5 Z
  489.         Send_Byte(0x90);                /* send read ID command (90h or ABh) */
    ( H0 \) \( j: C
  490.     Send_Byte(0x00);                /* send address */
    , ~# w. T) y3 h$ `1 ^
  491.         Send_Byte(0x00);                /* send address */
    2 F3 w) Z6 C. j( ^7 D  m
  492.         Send_Byte(ID_addr);                /* send address - either 00H or 01H */2 U' X; \! ~+ v3 e3 z
  493.         byte = Get_Byte();                /* receive byte */
    8 K# u" G; N+ O  E/ m; c" o
  494.         CE_High();                                /* disable device */
    ( h* N1 ~0 A# g/ p7 L2 b9 J
  495.         return byte;
      B. N8 F0 O8 C: l9 `! Z+ u. W
  496. }( s9 C& A- F3 X3 y7 A2 j: Q
  497. ; `. M3 w" W- M" S) K  u
  498. /************************************************************************/
    ( t/ S2 Q" |7 x- {3 N
  499. /* PROCEDURE: Jedec_ID_Read                                                                                                */
    0 Y8 m6 s- c: z+ J1 b1 l4 s
  500. /*                                                                                                                                                */
    9 ^5 U. q1 I( l! ]0 B8 f; j
  501. /* This procedure Reads the manufacturer's ID (BFh), memory type (25h)  */6 l* T" w8 m$ q2 k
  502. /* and device ID (8Eh).  It will use 9Fh as the JEDEC ID command.            */( C; S1 s" p" b5 F9 ]8 U* p
  503. /* Please see the product datasheet for details.                                                  */
    % Q' P5 y, s* R* p
  504. /*                                                                                                                                                */
    , c, a5 D& K) A, K
  505. /* Input:                                                                                                                                */
    6 Q% m( T: ~$ A" [3 a1 G
  506. /*                None                                                                                                                        */
    - a8 _9 J$ i1 P& ^) X
  507. /*                                                                                                                                                */
    ( m' k, J( n1 `- z! w/ U; o$ B& j
  508. /* Returns:                                                                                                                                */9 o( q, M( T/ I
  509. /*                IDs_Read:ID1(Manufacture's ID = BFh, Memory Type (25h),                        */
    ! B& u2 Z/ Q0 E
  510. /*                 and Device ID (8Eh)                                                                                        */2 D+ _1 I! U" R8 ^6 J
  511. /*                                                                                                                                                */
    0 c% j. _- }! J7 V5 Y+ O
  512. /************************************************************************/8 z% q. M$ G8 r7 Q$ Q
  513. unsigned long Jedec_ID_Read()
    & Y. y* @0 r+ H" ]7 {2 D7 r( J
  514. {
    + N7 ]! G& s0 I" b. w6 k
  515.         unsigned long temp;
    7 c) t: }. O1 m1 q! h9 L
  516.        
    ) ]# }& y6 b4 c# T+ V
  517.         temp = 0;9 y0 \9 c' z1 \+ h

  518. 4 b! U) b5 @, |# ]
  519.         CE_Low();                                        /* enable device */
    * A# V8 z! f. E4 z- k8 N
  520.         Send_Byte(0x9F);                        /* send JEDEC ID command (9Fh) */
    6 Y) P' Y  }% B( F2 B
  521.     temp = (temp | Get_Byte()) << 8;        /* receive byte */- t& D& e0 K+ K5 Q$ {8 X* Y
  522.         temp = (temp | Get_Byte()) << 8;       
    2 o1 Q- s2 G$ ~% U+ Y: |
  523.         temp = (temp | Get_Byte());                 /* temp value = 0xBF258E */
    * W5 D% Q, w4 h7 [
  524.         CE_High();                                                        /* disable device */
    , O; s# ]3 s) s: v" Q+ t# P; G
  525. ) Z' Q& P4 Q0 ^# P  f' ^) |0 o& ~5 M
  526.         return temp;
    " O. s/ _2 ?: V- p* M
  527. }/ S4 F: }; y) C& Z3 l
  528. * m" M& A- h6 \" m' T7 j/ y
  529. /************************************************************************/
    6 u7 d4 }) k" r6 C
  530. /* PROCEDURE:        Read                                                                                                        */9 W  ~4 W! n, M6 k8 b  j" A
  531. /*                                                                                                                                                */               
    # i7 H, ~# }: ^, q$ W
  532. /* This procedure reads one address of the device.  It will return the         */! K8 S, |. A! E
  533. /* byte read in variable byte.                                                                                        */
    ! \- U; K( H& _# m0 m* F* v9 r6 u' \: }6 G
  534. /*                                                                                                                                                */+ M2 w% t% ^: O  Q  s3 O) n5 ~/ {
  535. /*                                                                                                                                                */
    6 q& o. j6 j& y) f% W6 m/ g
  536. /*                                                                                                                                                */
    & {& H% e1 _0 y
  537. /* Input:                                                                                                                                */" s( Z' R) S2 Z% [2 `
  538. /*                Dst:        Destination Address 000000H - 0FFFFFH                                        */
    , x7 I0 s4 G& L8 q1 V6 G
  539. /*                                                                                                                                      */9 s6 W* Y: L) X( x) @8 r
  540. /*                                                                                                                                                */
    9 |, U) s9 X  p# }/ a
  541. /* Returns:                                                                                                                                */  k% q9 ~) M- R& g  B+ W! \
  542. /*                byte                                                                                                                        */
    * k3 @: q+ V* W
  543. /*                                                                                                                                                */
    2 n% W7 K; }/ Z
  544. /************************************************************************/$ h% L3 |0 w: A! @3 B& f
  545. unsigned char Read(unsigned long Dst) / p& H) C& r4 `- Q7 H! W
  546. {
    1 N. G6 ?! \6 N9 v$ U5 @' l/ g
  547.         unsigned char byte = 0;        + ?, t1 O& C! \- G7 K
  548. 6 w: i' y) u1 y
  549.         CE_Low();                                /* enable device */
    . ^9 ~( V  H# M9 e' u9 ?
  550.         Send_Byte(0x03);                 /* read command */4 C  g, g+ o! Z0 m
  551.         Send_Byte(((Dst & 0xFFFFFF) >> 16));        /* send 3 address bytes */
    % T( Z. P( j) ]; F! q
  552.         Send_Byte(((Dst & 0xFFFF) >> 8));$ _2 s3 u& P; e5 B( r" L6 i/ x  {
  553.         Send_Byte(Dst & 0xFF);$ G  G7 R1 d0 ~% H* ?: v. N) V8 R# F& e
  554.         byte = Get_Byte();
    # H' f* H# H0 A5 R+ V* ~6 m3 Q7 {
  555.         CE_High();                                /* disable device */
    1 P% U5 i9 P$ v5 X. x
  556.         return byte;                        /* return one byte read */. W& t6 K* I+ @7 `* k  P' ^& J5 j
  557. }& X+ K2 v- K: H: ]4 {" e

  558. 2 x; l: Z: u% B& T( @" i7 C5 ?# f
  559. /************************************************************************/4 f6 L' c: h% H9 _
  560. /* PROCEDURE:        Read_Cont                                                                                                */
    + a) O. Y! k8 j% G0 ]. W
  561. /*                                                                                                                                                */               
    + y( Y9 S- }/ S0 X- z4 S
  562. /* This procedure reads multiple addresses of the device and stores                */
    6 y# H' f( G, o& \3 p+ v
  563. /* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*/2 u' t4 B5 f. b8 d
  564. /*                                                                                                                                                */
    ; i* X6 y! i  s% ^1 ]' _
  565. /* Input:                                                                                                                                */
    # \$ P' Y- Z* w9 W
  566. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */
    + \* g# m" W9 t$ m
  567. /*      no_bytes        Number of bytes to read        (max = 128)                                        */
    $ b7 V2 b; E- K: P1 Z
  568. /*                                                                                                                                                */" U: Y2 z6 m) d) t* J: {! V8 m
  569. /* Returns:                                                                                                                                */* Q2 J; [# ^0 n, U3 f
  570. /*                Nothing                                                                                                                        */
    % ^4 g' E( t5 g: q: ^
  571. /*                                                                                                                                                */
    ! C$ e% D8 T$ g+ T! d
  572. /************************************************************************/
    ( n9 J( D% e! L& w$ t
  573. void Read_Cont(unsigned long Dst, unsigned long no_bytes)
    ; u0 @4 r3 J7 g, C; {
  574. {
    ) B0 X! V) u  t% C* J
  575.         unsigned long i = 0;3 p) k% ^7 r& C) S
  576.         CE_Low();                                        /* enable device */+ M/ z7 Q, n. R' {! N; E
  577.         Send_Byte(0x03);                         /* read command */
    7 k4 |( d1 A5 p1 s5 W/ N
  578.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */4 S+ @  Z% H4 D  p
  579.         Send_Byte(((Dst & 0xFFFF) >> 8));. b2 Z5 ?( [2 h
  580.         Send_Byte(Dst & 0xFF);- q0 [6 i& M: K. W+ x( i% w. X# o: p$ r
  581.         for (i = 0; i < no_bytes; i++)                /* read until no_bytes is reached */7 n7 U' K" Z6 R* m2 V& t' N) U9 g
  582.         {
    $ i; d7 e1 |% I5 m- \1 N, b! L
  583.                 upper_128[i] = Get_Byte();        /* receive byte and store at address 80H - FFH */" B6 b* E' a; X- l
  584.         }1 z* v) ?) {3 Q% G: _
  585.         CE_High();                                        /* disable device */1 K" A: E, b. u- G0 ^5 x
  586. # f& X( H" c3 T; K# d% ~, z. h! c
  587. }, T$ \# k- l: N! x3 P- |! |% `

  588. # x& m4 @3 S8 ~3 D/ s
  589. /************************************************************************/
    7 E6 a9 l: @" G0 q5 |# b, O
  590. /* PROCEDURE:        HighSpeed_Read                                                                                        */! y! _; M( g! U" o/ T
  591. /*                                                                                                                                                */                & _7 B* A+ T. i
  592. /* This procedure reads one address of the device.  It will return the         */; A) `$ p# E1 j* i$ t8 F0 n
  593. /* byte read in variable byte.                                                                                        */
    & J& P7 N. j# G" a" n# t; w* U$ L
  594. /*                                                                                                                                                */) U5 X4 v4 [$ I
  595. /*                                                                                                                                                */
    * I( P$ ?/ r, K, ]
  596. /*                                                                                                                                                */
    ; s: x8 C. e$ b4 Q5 K
  597. /* Input:                                                                                                                                */
    / X3 v" Z" R* k: I
  598. /*                Dst:        Destination Address 000000H - 0FFFFFH                                        */
    / N. |! H% w7 g* B/ M+ `0 D
  599. /*                                                                                                                                      */9 J& l* C" J5 s6 V6 i
  600. /*                                                                                                                                                */3 D. n* ~( Y# W: w' H, `
  601. /* Returns:                                                                                                                                */
    0 N9 P, `' [: c+ i* T2 G" I
  602. /*                byte                                                                                                                        */9 O5 }9 A& T. {4 g* x4 o* ]
  603. /*                                                                                                                                                */
    * G. L' Q* ]2 B, {! h0 H. G
  604. /************************************************************************/
    & ~( x( e3 e( X0 S
  605. unsigned char HighSpeed_Read(unsigned long Dst) ' v' ^+ T& p6 T
  606. {
    ( U9 \" _% y4 g  b: R
  607.         unsigned char byte = 0;       
    7 t( \; V3 X# ~! J

  608. ( g" `+ x* {* V# P
  609.         CE_Low();                                /* enable device */
    4 D. n8 j# |& L9 e! [- e8 S: ]. n1 o4 Z
  610.         Send_Byte(0x0B);                 /* read command */
      M3 H% I* @1 b9 U) t. E
  611.         Send_Byte(((Dst & 0xFFFFFF) >> 16));        /* send 3 address bytes *// Z7 `$ u- A$ K. a' @
  612.         Send_Byte(((Dst & 0xFFFF) >> 8));: ?  v+ \) s( j3 @! Q0 I6 a
  613.         Send_Byte(Dst & 0xFF);
    ( k; Y4 z. y4 q% u# @( U4 M3 _: G
  614.         Send_Byte(0xFF);                /*dummy byte*/
    ! A+ ^# X4 l3 `( ]3 q# F
  615.         byte = Get_Byte();
    & q. B* X6 X; O' N
  616.         CE_High();                                /* disable device */" b& [+ e6 \! F: Y# D3 ]8 z! j
  617.         return byte;                        /* return one byte read */
    ( `) b, l' g7 `9 o; W
  618. }
    5 r. v2 o8 n$ r5 [8 V, w

  619. " Q& I4 d* }9 k& A6 Y- m* J. e, D
  620. /************************************************************************/8 ~, R2 |9 k: V, b8 }% _
  621. /* PROCEDURE:        HighSpeed_Read_Cont                                                                                */
    ! H/ o! l& ^2 ?  k5 M
  622. /*                                                                                                                                                */               
    9 m# ~  [/ w! C) B( {! |. V) n
  623. /* This procedure reads multiple addresses of the device and stores                */
    # l' b5 {, I% N' u5 v* S
  624. /* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*/! D% r! `! C' S
  625. /*                                                                                                                                                */
    3 F) p2 q- y7 h. Q$ v
  626. /* Input:                                                                                                                                */
    8 a7 y' Y+ ~5 P+ j, G
  627. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */
    , E; a% w0 e' ?2 O; z% P+ Z
  628. /*      no_bytes        Number of bytes to read        (max = 128)                                        */9 R7 `5 R' w& p9 c
  629. /*                                                                                                                                                */2 t2 Y' q7 ]& @. V9 d% d4 @
  630. /* Returns:                                                                                                                                */
    ' @$ E" \2 G7 P
  631. /*                Nothing                                                                                                                        */! o9 N& H8 |* ~
  632. /*                                                                                                                                                */& @% [0 c, N# [
  633. /************************************************************************/- Q1 h0 S8 P& ?/ d+ g
  634. void HighSpeed_Read_Cont(unsigned long Dst, unsigned long no_bytes)
    ) x# L  _" f- J/ x/ L& w
  635. {' q1 t6 ]+ N) E$ N+ d- s
  636.         unsigned long i = 0;5 Y$ I5 d  r" e" y2 A
  637.         CE_Low();                                        /* enable device */
      Q: S" o! K1 y' s0 t* i
  638.         Send_Byte(0x0B);                         /* read command */! K3 k/ h0 }  {+ N, v* g
  639.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */
    2 u, |3 k; b2 `
  640.         Send_Byte(((Dst & 0xFFFF) >> 8));
    ! ]1 w) y6 G7 x. T) d! ]. m8 X
  641.         Send_Byte(Dst & 0xFF);, Z2 `6 R7 p( M8 Y. E3 ?' j
  642.         Send_Byte(0xFF);                        /*dummy byte*/
    % i! N/ C3 Z6 _, }0 u$ O
  643.         for (i = 0; i < no_bytes; i++)                /* read until no_bytes is reached */
    ( p0 j* B$ ]  `% F
  644.         {9 x' }; y/ \( G3 I& D1 H% \; ], G
  645.                 upper_128[i] = Get_Byte();        /* receive byte and store at address 80H - FFH */
    $ X& _  s  B. Q! }
  646.         }  r4 a4 A; p5 ^7 l* b6 R& i
  647.         CE_High();                                /* disable device */1 P6 e. N9 X  E/ |0 E
  648. }
    1 t4 R8 h0 p! O# z. T$ h& B* V
  649. % K9 G# h% [0 b! J
  650. /************************************************************************/
    " r7 h. I4 w4 c& c
  651. /* PROCEDURE:        Byte_Program                                                                                        */
    , n; X. E+ L% j/ N/ E" A
  652. /*                                                                                                                                                */
    . F& s7 w2 c. }3 E9 t8 X
  653. /* This procedure programs one address of the device.                                        */
    ( F/ i) N2 c. F1 m
  654. /* Assumption:  Address being programmed is already erased and is NOT        */
    " l( X/ G9 j0 Y
  655. /* block protected.                                                                                                                */' \' @8 B: ^( t. x' S/ n( L
  656. /*                                                                                                                                                */
    7 }; ^, [2 h) u; {
  657. /*                                                                                                                                                */
    ( u! w/ z8 Z$ u) ?9 F
  658. /*                                                                                                                                                */* U" `3 z' t7 X# ^7 W# u4 g
  659. /* Input:                                                                                                                                */
    2 O1 _( z2 E& x; ?) Z2 g$ c" M/ K
  660. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */
    # Y8 u( Q! i, Q- |
  661. /*                byte:                byte to be programmed                                                                */" g3 \1 R% }; J0 N3 k) \
  662. /*                                                                                                                                      */. {6 ?7 A5 g* H- O/ B! L2 D
  663. /*                                                                                                                                                */
    & l2 ?/ ?: o, [7 r- j( K! E
  664. /* Returns:                                                                                                                                */0 S& L6 e" E+ R+ g1 S
  665. /*                Nothing                                                                                                                        */7 W! K0 j2 R# C0 y) U
  666. /*                                                                                                                                                */
    " t# `* d+ p& Q/ o
  667. /************************************************************************/, B1 j5 G$ j3 |8 s2 Y
  668. void Byte_Program(unsigned long Dst, unsigned char byte)
    ( N/ B- d  c, S8 ]$ G
  669. {
    % j7 N6 O  s* s$ t  x# x+ X
  670.         CE_Low();                                        /* enable device */" A7 a1 A, w/ F$ u4 R
  671.         Send_Byte(0x02);                         /* send Byte Program command */% k8 N4 Y8 T1 f4 U4 [8 q; d- x
  672.         Send_Byte(((Dst & 0xFFFFFF) >> 16));        /* send 3 address bytes */3 D. o3 U/ @) J  b( d
  673.         Send_Byte(((Dst & 0xFFFF) >> 8));  z. d: J  g2 a& p- t9 J
  674.         Send_Byte(Dst & 0xFF);" K8 k" w0 K, d+ z: Y# O
  675.         Send_Byte(byte);                        /* send byte to be programmed */2 Y- {, _# I8 ?1 M
  676.         CE_High();                                        /* disable device */- t; w* Z" h0 J( H# h7 h9 t
  677. }/ u, T0 Y' K" x  Q  H& x
  678. ! z" G) k; `% ~6 z$ W1 x3 M
  679. /************************************************************************/
      A# ^4 q  D, _" O3 Y2 D9 V
  680. /* PROCEDURE:        Auto_Add_IncA                                                                                        */
    - N* v1 d4 I. V, l* M
  681. /*                                                                                                                                                */) H" [$ Z) t% H( _
  682. /* This procedure programs consecutive addresses of 2 bytes of data into*/
    1 {+ e5 I$ u7 M
  683. /* the device:  1st data byte will be programmed into the initial                 */
    - I  R3 J% S( F
  684. /* address [A23-A1] and with A0 = 0.  The 2nd data byte will be be                 */$ r" X. M+ ?: U+ t* T
  685. /* programmed into initial address [A23-A1] and with A0  = 1.  This          */) B8 C% D! ]+ F
  686. /* is used to to start the AAI process.  It should be followed by                 */9 ?& a7 q! ^- C& P
  687. /* Auto_Add_IncB.                                                                                                                */. H0 U4 Q1 ]+ A0 R7 q) ]
  688. /* Assumption:  Address being programmed is already erased and is NOT        */
    - ^/ E: i! V" z+ _5 s( \# Z! Z
  689. /*                                block protected.                                                                                */
    ) ?' u) C7 y7 z, i( {% Z
  690. /*                                                                                                                                                */
    % H" M# h5 Y7 _& z+ K$ K
  691. /*                                                                                                                                                */
    % m& J5 P2 B* K& y8 O- m# G
  692. /* Note: Only RDSR command can be executed once in AAI mode with SO          */5 O7 |$ c' }/ v; P8 N. F7 a
  693. /*          disable to output RY/BY# status.  Use WRDI to exit AAI mode                 */( _# r; w5 x/ v6 _) n. U
  694. /*         unless AAI is programming the last address or last address of                */
    ) W6 v$ B3 r) i7 L1 G
  695. /*          unprotected block, which automatically exits AAI mode.                                */
    5 E1 }3 M( Q4 K+ c" A, C
  696. /*                                                                                                                                                */6 i; J: e  s9 v: L' ~
  697. /* Input:                                                                                                                                */+ E4 y" N8 b3 \' U7 e
  698. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */
    2 J* @3 {3 S5 n( w* |1 t0 F, U
  699. /*                byte1:                1st byte to be programmed                                                        */$ D+ b! J" N  i" r, g8 @( h7 L4 j0 [
  700. /*      byte1:                2nd byte to be programmed                                                        */3 q; L5 r( D: O+ |
  701. /*                                                                                                                                                */
    ; ?6 l2 l8 o0 z$ T9 o/ k4 \+ ]
  702. /* Returns:                                                                                                                                */: d( K4 R  q4 ]! q  }) ~
  703. /*                Nothing                                                                                                                        */
    % [- l9 Q( A1 P$ v: W9 w
  704. /*                                                                                                                                                */* ?( Z1 t6 t: F" w8 c. p
  705. /************************************************************************/; t5 m: J: h6 K, ]' E) S; y
  706. void Auto_Add_IncA(unsigned long Dst, unsigned char byte1, unsigned char byte2)- V6 q& w7 b3 R0 M$ w  L2 s' B
  707. {* G2 F! t* `3 `+ Y; F7 S  `
  708.         CE_Low();                                        /* enable device */; ?& k2 A! H' v1 R5 _$ [
  709.         Send_Byte(0xAD);                        /* send AAI command */: \8 _  R9 I; `# o
  710.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */
    6 d9 P9 B! }/ Z3 t; @8 v
  711.         Send_Byte(((Dst & 0xFFFF) >> 8));7 a; |8 [* o6 t( p
  712.         Send_Byte(Dst & 0xFF);
    * c) y& W! L. Y
  713.         Send_Byte(byte1);                        /* send 1st byte to be programmed */        * i; r8 c4 F' R: U9 d
  714.         Send_Byte(byte2);                        /* send 2nd byte to be programmed */# _' y' q0 e( a; Q, ?- Y
  715.         CE_High();                                        /* disable device */- U. l) H+ J4 t5 g" ^7 e
  716. }
    / A0 v! E0 @4 ~. e

  717. ( e5 Q' C$ q9 ?# d
  718. /************************************************************************/
    5 y. O3 L8 U9 q7 q- X+ o
  719. /* PROCEDURE:        Auto_Add_IncB                                                                                        */
    ! h" T; ]8 v7 K) J+ k5 z5 O
  720. /*                                                                                                                                                */
    . K. |( E! G- Z7 F! B3 ?& l
  721. /* This procedure programs consecutive addresses of 2 bytes of data into*/% B- }9 I9 {+ k2 J0 }4 H$ w5 b% U
  722. /* the device:  1st data byte will be programmed into the initial                 */
    2 t, t+ Z0 }$ r' b8 s# E
  723. /* address [A23-A1] and with A0 = 0.  The 2nd data byte will be be                 */0 T2 u5 J% P6 z& _
  724. /* programmed into initial address [A23-A1] and with A0  = 1.    This          */
    3 q6 Q; X9 q, c; w& F
  725. /* is used after Auto_Address_IncA.                                                                                */
    0 X: R; ?3 @" O( ^! I6 l' R3 Z
  726. /* Assumption:  Address being programmed is already erased and is NOT        */( s) _5 k! M6 `0 Q. q2 v, z
  727. /*                                block protected.                                                                                */
    $ u' `# L2 ^: n. o$ r8 ~6 V9 ^; V
  728. /*                                                                                                                                                */
    4 }: l& |' m7 g/ i# I9 O9 J
  729. /* Note: Only WRDI and AAI command can be executed once in AAI mode         */
    & c  O, z- {7 q
  730. /*         with SO enabled as RY/BY# status.  When the device is busy                 */" \& t* K  [* G0 L, ^2 @7 N! _- b7 f$ p
  731. /*         asserting CE# will output the status of RY/BY# on SO.  Use WRDI        */5 K" D7 \5 r0 {' ^
  732. /*          to exit AAI mode unless AAI is programming the last address or                */
    0 [" b3 r, ]$ p) b: s
  733. /*         last address of unprotected block, which automatically exits                 */
    % y# e* i8 w- @. b. ?; v9 ]3 s/ M
  734. /*         AAI mode.                                                                                                                        */
    6 X: U- \) R) H
  735. /*                                                                                                                                                */. L$ O( Y/ N) n) o
  736. /* Input:                                                                                                                                */5 D1 P9 y% I& I. U6 u
  737. /*                                                                                                                                                */
    : y) Y% V8 h& R7 e! `2 \
  738. /*                byte1:                1st byte to be programmed                                                        */+ }' N/ H$ C4 ]! T5 K+ r
  739. /*                byte2:                2nd byte to be programmed                                                        */
    7 L! O( Z; F* l( @0 S' \, N) \
  740. /*                                                                                                                                      *// n& R! S3 k% B7 I# ^( I& s4 `
  741. /*                                                                                                                                                */
    ' e2 d; D! [6 o! j2 e5 t8 {, N
  742. /* Returns:                                                                                                                                */
    # y& O' t, i8 n7 L7 S
  743. /*                Nothing                                                                                                                        */# Y& j' M* n3 t
  744. /*                                                                                                                                                */' |: N! b, k- k9 V
  745. /************************************************************************/; e2 V1 D# J3 m; {: B0 P
  746. void Auto_Add_IncB(unsigned char byte1, unsigned char byte2)6 q; e. R; A0 u* [
  747. {. {. Y1 H+ J8 V
  748.         CE_Low();                                        /* enable device */* @( l4 q- K/ K4 j6 f) g! N: H( X
  749.         Send_Byte(0xAD);                        /* send AAI command */9 b( N  B1 f' k. f# o: U
  750.         Send_Byte(byte1);                        /* send 1st byte to be programmed */2 k* V8 ?) X" |2 }
  751.         Send_Byte(byte2);                        /* send 2nd byte to be programmed */
      Z+ ]1 L. q1 `+ m
  752.         CE_High();                                        /* disable device */3 f: p) ^# Z4 Z8 e. o% j% T
  753. }
    + ?$ L1 U$ d/ Q1 s/ D) ]

  754. " i: W( i7 q  \1 a
  755. /************************************************************************/8 S0 d9 k, ]- T1 i
  756. /* PROCEDURE:        Auto_Add_IncA_EBSY                                                                                */
    9 ^) z. ?! e# g) L2 ?+ c/ ^
  757. /*                                                                                                                                                */& h% h: V5 Q: X6 o
  758. /* This procedure is the same as procedure Auto_Add_IncA except that it */$ E8 _, O$ x! _* X9 x9 j
  759. /* uses EBSY and Poll_SO functions to check for RY/BY. It programs                 */% [8 Y6 d' u6 H2 M; |$ }( e
  760. /* consecutive addresses of the device.  The 1st data byte will be                 */. n4 r! q8 m4 X% a
  761. /* programmed into the initial address [A23-A1] and with A0 = 0.  The         */' c9 w, b- ^/ _, T4 @% A
  762. /* 2nd data byte will be programmed into initial address [A23-A1] and         */9 r* I  K. k1 R" m. {
  763. /* with A0  = 1.  This is used to to start the AAI process.  It should  */  `9 N0 n) B; J5 K/ E
  764. /* be followed by Auto_Add_IncB_EBSY.                                                                        */
    6 i& C1 b. j! X/ A9 C" f
  765. /* Assumption:  Address being programmed is already erased and is NOT        */, k8 f& \0 v6 t# |& s
  766. /*                                block protected.                                                                                */9 Y% O" w, x+ R
  767. /*                                                                                                                                                */% h; e! \' C" ^% i! k/ d# q
  768. /*                                                                                                                                                */
    9 M7 C+ C, y. L' q2 R) ^
  769. /* Note: Only WRDI and AAI command can be executed once in AAI mode         */0 f# x8 ~, k. F* ~* \
  770. /*         with SO enabled as RY/BY# status.  When the device is busy                 */. G" C4 x; e/ \2 w/ Y7 b' g' J4 E
  771. /*         asserting CE# will output the status of RY/BY# on SO.  Use WRDI        */3 U. ~( t0 S9 e
  772. /*          to exit AAI mode unless AAI is programming the last address or                */' @, F& ^. y/ c+ Q9 g) T0 s3 @1 a- x
  773. /*         last address of unprotected block, which automatically exits                 */
    % u' \' ~, k$ |* }  @: @
  774. /*         AAI mode.                                                                                                                        */! g  i8 `) k+ B( d0 `( S' O6 A
  775. /*                                                                                                                                                */
    * b  L& p& m- a. E4 z7 |$ [
  776. /* Input:                                                                                                                                */
    4 j  I9 M' q/ O) I) q, [
  777. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */# d0 j- a& q; L% f3 z5 E3 _
  778. /*                byte1:                1st byte to be programmed                                                        */
    9 n) q+ }& p* {% T0 f. b* v. y
  779. /*      byte1:                2nd byte to be programmed                                                        */6 z9 S8 y$ ^) ^' T
  780. /*                                                                                                                                                */0 n! _( J) _6 v7 F. D1 ^
  781. /* Returns:                                                                                                                                */
      p) L1 n4 j: Q
  782. /*                Nothing                                                                                                                        */5 ]# R, U/ ~  Z
  783. /*                                                                                                                                                */9 ~# S2 u) b& X! ^8 n. I( u
  784. /************************************************************************/& F$ X; P" N; t1 X: I
  785. void Auto_Add_IncA_EBSY(unsigned long Dst, unsigned char byte1, unsigned char byte2)
    " X3 P& U' J9 ?( _
  786. {
    " R- v9 H$ E7 z: t9 f& P$ H7 d
  787.         EBSY();                                                /* enable RY/BY# status for SO in AAI */        7 V% d! L+ Y% m- D; O- {0 {/ G  U
  788. : Q2 l6 t! u. o/ j9 `
  789.         CE_Low();                                        /* enable device */; r' I, U+ m  d/ y2 _* W# r
  790.         Send_Byte(0xAD);                        /* send AAI command */
    # }4 w6 ^4 n* T6 ], c
  791.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */  Q1 P: e9 R* [2 a& a+ Y
  792.         Send_Byte(((Dst & 0xFFFF) >> 8));
    + ?! E7 T# u6 s  ?7 ?
  793.         Send_Byte(Dst & 0xFF);8 T' a- V4 l$ L2 g" f" e" N, C
  794.         Send_Byte(byte1);                        /* send 1st byte to be programmed */        ' Y6 V. A5 J) c) x
  795.         Send_Byte(byte2);                        /* send 2nd byte to be programmed */9 @$ j2 i, q7 @- E, K( l6 @, I- s
  796.         CE_High();                                        /* disable device */
    : Q( q' {& `( `" m1 l5 z/ R. E
  797.         ! C/ p8 Y5 r9 k  Y; m: E$ L
  798.         Poll_SO();                                        /* polls RY/BY# using SO line */- f* Q8 b) z" B. O" `+ t
  799. , i2 U; [. ]4 q2 U
  800. }8 y) `5 B; \4 `( a9 K2 n

  801. ) u/ U! r9 Z5 u/ l
  802. /************************************************************************/
    5 L/ H+ T/ q$ K9 H1 q- a
  803. /* PROCEDURE:        Auto_Add_IncB_EBSY                                                                                */! V: L5 n# I) u! p. O' Y  ]# t
  804. /*                                                                                                                                                */: P0 T" v! {) A7 _3 `. m# f
  805. /* This procedure is the same as Auto_Add_IncB except that it uses                 */
    9 z/ Z, C) ^0 I7 r: X0 s8 q; g
  806. /* Poll_SO to poll for RY/BY#.  It demonstrate on how to use DBSY after        */
    , F6 w9 @/ S* w( ?
  807. /* AAI programmming is completed.  It programs consecutive addresses of */% k2 N- P& g3 a
  808. /* the device.  The 1st data byte will be programmed into the initial   */
    : ?) s9 g- Q$ d% R: j
  809. /* address [A23-A1] and with A0 = 0.  The 2nd data byte will be                        */* r( C! L! z1 j
  810. /* programmed into initial address [A23-A1] and with A0  = 1.  This is         */4 R: K& K! x! D
  811. /* used after Auto_Address_IncA.                                                                                */$ x0 ]1 ^. H; ]. R
  812. /* Assumption:  Address being programmed is already erased and is NOT        */, @& |' Z  O; C  b# L
  813. /*                                block protected.                                                                                */
    1 B. g. ?& f; d) a8 A9 Q! ^
  814. /*                                                                                                                                                */: i8 f" Z2 K6 f6 |: Q+ R
  815. /* Note: Only WRDI and AAI command can be executed once in AAI mode         */" E* c  o3 Q$ l* k
  816. /*         with SO enabled as RY/BY# status.  When the device is busy,                 */
    ) h9 Y2 P, `5 X% ?5 E6 `; S6 u
  817. /*         asserting CE# will output the status of RY/BY# on SO.  Use WRDI        */
    6 M- L" q# {( {5 X' @
  818. /*          to exit AAI mode unless AAI is programming the last address or                */0 Y- t' K; E6 ~/ u. A
  819. /*         last address of unprotected block, which automatically exits                 */
    3 p! f1 s5 C& ^9 E$ F" r8 S# W  ~4 R
  820. /*         AAI mode.                                                                                                                        */% d: h; ?4 w2 J, p5 o
  821. /*                                                                                                                                                */
    , K+ ^6 G$ l9 o+ s: C
  822. /* Input:                                                                                                                                */  ~" M4 N' P% A) I* d4 D
  823. /*                                                                                                                                                */( _# |2 ~7 b8 o
  824. /*                byte1:                1st byte to be programmed                                                        */
    " s7 X6 I; {, {; O9 X
  825. /*                byte2:                2nd byte to be programmed                                                        */
    * B5 N  e% d. r4 Q' C3 I
  826. /*                                                                                                                                      */7 I) j$ O# F: }5 w% u5 V0 p
  827. /*                                                                                                                                                */4 u* s" X) B3 I* k
  828. /* Returns:                                                                                                                                */
    / p4 s( }7 \2 P. h9 T4 S
  829. /*                Nothing                                                                                                                        */9 p6 q3 J$ C. i3 y2 j7 p
  830. /*                                                                                                                                                */
    " r: u. u, y) ^" K5 J7 M
  831. /************************************************************************/
    9 a! t& t/ D7 |! [
  832. void Auto_Add_IncB_EBSY(unsigned char byte1, unsigned char byte2)
    / G- ~2 S4 q0 L1 B1 j) U0 G* Q
  833. {
    4 m% G* u9 x. f
  834.         CE_Low();                                /* enable device */, T8 r4 O% H" ?/ r1 e
  835.         Send_Byte(0xAD);                /* send AAI command */4 i: y" ^. m# S+ E/ H, p
  836.         Send_Byte(byte1);                /* send 1st byte to be programmed */
    $ p/ V' e  U3 g
  837.         Send_Byte(byte2);                /* send 2nd byte to be programmed */2 \7 a8 `3 ?4 @/ M/ c, y
  838.         CE_High();                                /* disable device */% T' S, C) [, M- I: O

  839. + t: c$ t5 C+ s: t% ^3 }
  840.         Poll_SO();                                /* polls RY/BY# using SO line */
      X- v/ e9 W6 c
  841. 9 Z4 V3 {3 Z/ O5 O' r/ k8 k
  842.         WRDI();                                 /* Exit AAI before executing DBSY */3 r  i1 C" L% \# i% t
  843.         DBSY();                                        /* disable SO as RY/BY# output if in AAI */
    $ i0 n9 \1 U  a2 N
  844. }
    ; g6 W0 ]' ^* z5 L) `: g1 q
  845. ! i. `1 Q& B! h9 I
  846. /************************************************************************/) ]2 P! ~  P1 |3 @0 E
  847. /* PROCEDURE: Chip_Erase                                                                                                */
    " d( Q5 p& x  k" t# O+ p
  848. /*                                                                                                                                                */
    " l# Z4 N8 m' t% @4 p
  849. /* This procedure erases the entire Chip.                                                                */
    ; M/ D, M# Y( D
  850. /*                                                                                                                                                */
    - D- a/ y( A! I5 `3 b, d8 X+ T  E
  851. /* Input:                                                                                                                                */* z% i5 Z0 T/ c( l4 ^9 n- R- l. ^
  852. /*                None                                                                                                                        */
    1 E- c% @3 X& P  ~* |7 b- T2 ?! g0 @
  853. /*                                                                                                                                                */
    % k6 {* h: ^" n$ ^/ M" x7 _% |- ^
  854. /* Returns:                                                                                                                                */0 k! A+ A" p! M( {
  855. /*                Nothing                                                                                                                        */9 @* [. F5 I4 B
  856. /************************************************************************/
    1 t) o* |- }9 g' j+ |$ r- B
  857. void Chip_Erase()
    + i1 K' T$ M: Q7 {7 f9 Q" i8 ~1 c
  858. {                                               
    : H4 n4 V$ o. D
  859.         CE_Low();                                /* enable device */& F7 Q) @1 N$ b1 O
  860.         Send_Byte(0x60);                /* send Chip Erase command (60h or C7h) */
    ! j- B0 _- ?: D, j' G, k3 @7 C
  861.         CE_High();                                /* disable device */0 {+ B% m& D8 f2 S3 p
  862. }% G" Z$ J$ _- U1 D- A

  863. 0 J' _3 N/ v# p1 e8 Y) t5 v; Q
  864. /************************************************************************/
    9 A; O8 l4 C3 h  [4 r/ |0 Z5 T; d
  865. /* PROCEDURE: Sector_Erase                                                                                                */
    ( b% p' b9 s) i( P
  866. /*                                                                                                                                                */
    # u  m. {3 R) w+ r0 ~, e6 D5 g. y
  867. /* This procedure Sector Erases the Chip.                                                                */+ O& W. V0 ~2 T; C
  868. /*                                                                                                                                                */3 X4 P1 d  H. P" _1 `9 f: |
  869. /* Input:                                                                                                                                *// R( }3 ~% }* r
  870. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */$ q4 R( T5 x* q8 _
  871. /*                                                                                                                                                */0 O' O* Z. }5 |
  872. /* Returns:                                                                                                                                */' q7 S+ f9 [0 @  ]! e" Q! U
  873. /*                Nothing                                                                                                                        */
    : q' F8 X7 `( ]* i) Y
  874. /************************************************************************/
    ( q3 f  z) X: Z  d/ v0 o& G: c
  875. void Sector_Erase(unsigned long Dst)( X: H, H6 {+ U  W9 {5 I1 c6 B7 L& V
  876. {
    ) q  t' p  P, v4 s

  877. + }: }2 [% J2 R- I* T: @3 l! D6 G& P
  878. / U8 Z! |1 z7 S, ?0 G8 Y$ }/ d
  879.         CE_Low();                                        /* enable device */: C* a' ~% w9 b, h, Y5 t
  880.         Send_Byte(0x20);                        /* send Sector Erase command */5 _  O" x! F& S0 S' T
  881.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */. E1 `2 T1 M/ O
  882.         Send_Byte(((Dst & 0xFFFF) >> 8));6 n) Z# h) R+ r* Z+ a1 ~; ^, L
  883.         Send_Byte(Dst & 0xFF);
    . K( Q5 T; w4 ]. b' p0 l% R
  884.         CE_High();                                        /* disable device */
    3 {, }; v; t  |8 W
  885. }       
    4 a6 i. n: s9 z. X1 U
  886. 2 j) ?7 g' [# B) L5 N( k& l
  887. /************************************************************************/
    , i+ w! |2 D9 O0 p! b' |
  888. /* PROCEDURE: Block_Erase_32K                                                                                        */
      t, n% K% j3 ^$ q( A. f' V% I+ h: X
  889. /*                                                                                                                                                */
    $ ]8 n: C4 m2 O) V* E% b
  890. /* This procedure Block Erases 32 KByte of the Chip.                                        */
    3 [! l8 o! M. j; q+ u& d
  891. /*                                                                                                                                                */
    2 ]. q- Z; G6 g2 w
  892. /* Input:                                                                                                                                */
    : e0 b9 O- X- M7 w0 f: d
  893. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */
    + H* B( L, E" j
  894. /*                                                                                                                                                */, W% M8 s( X% k2 @" q  D
  895. /* Returns:                                                                                                                                */
    # M% F. G) P: `. s, I* I1 S) A
  896. /*                Nothing                                                                                                                        */
    , o% G/ [, g- J$ k
  897. /************************************************************************/
    $ Z/ z. B: P, n$ K0 Z  U7 N
  898. void Block_Erase_32K(unsigned long Dst)
    " o2 A4 g, i. {! x/ _& p. t- ]
  899. {
    # ]/ @+ J; m* |  p/ B! }- ]
  900.         CE_Low();                                        /* enable device */
    . h* x- ^$ T6 k- a3 P, {
  901.         Send_Byte(0x52);                        /* send 32 KByte Block Erase command */9 C6 G: |$ @* `) T9 o5 H# G: x! U
  902.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */
    $ Y, J% _6 ?0 b7 r2 H
  903.         Send_Byte(((Dst & 0xFFFF) >> 8));1 u% i  Q4 q* D* M( i& H% A$ K
  904.         Send_Byte(Dst & 0xFF);
    6 v" h) I* o% u3 }
  905.         CE_High();                                        /* disable device */
    - t. z3 Y& K( c, J- U5 T
  906. }; d' i7 _, x' [! ?! W  n8 }
  907. 5 \9 f8 [) P9 L# }
  908. /************************************************************************/
    % x  ?$ J9 I8 W4 Z6 Z3 K7 c
  909. /* PROCEDURE: Block_Erase_64K                                                                                        */
    ! ]" O. _- B! {/ w" a# z
  910. /*                                                                                                                                                */1 K9 R& `7 Q+ G8 K3 D
  911. /* This procedure Block Erases 64 KByte of the Chip.                                        */8 L! G. w1 m; ^" G" h/ G3 Q
  912. /*                                                                                                                                                */
    1 R3 f$ E# i; z' _$ {/ Y# t
  913. /* Input:                                                                                                                                */
    * J+ M7 N$ j% X+ `8 u
  914. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */
    1 C- S; h8 k# j, }; r7 O
  915. /*                                                                                                                                                */
    ( _0 h' t2 O" u$ j
  916. /* Returns:                                                                                                                                */
    & d+ U. @8 X  r  A' ?! X* R
  917. /*                Nothing                                                                                                                        */
    6 ?( M- ?6 J1 Q" R
  918. /************************************************************************/1 {  N/ p6 _1 b. E- L2 i
  919. void Block_Erase_64K(unsigned long Dst)/ C: [" ~* }3 A$ j, _
  920. {
    2 n! e) {, |7 ]' A- l2 j( A( Z0 O' l
  921.         CE_Low();                                        /* enable device */3 v& z  u3 A3 ^7 N
  922.         Send_Byte(0xD8);                        /* send 64KByte Block Erase command */
    - O' V- \0 G/ C# e! T# n
  923.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */
    ! L4 a+ H6 \( Y' q9 Z2 _8 y
  924.         Send_Byte(((Dst & 0xFFFF) >> 8));
    ' o  g! T$ w, K3 z- t
  925.         Send_Byte(Dst & 0xFF);- F1 G) Z- z" K
  926.         CE_High();                                        /* disable device */
    4 w7 {( S* x, Z, L$ d* a
  927. }+ {# G0 B# o# S5 @

  928. 2 c& f4 g3 j# `% Y
  929. /************************************************************************/
    ! N+ }' }' c/ \! q
  930. /* PROCEDURE: Wait_Busy                                                                                                        */
    7 }2 `0 N% a( S( r4 _0 F
  931. /*                                                                                                                                                */
    6 l, b4 k! t. q1 U
  932. /* This procedure waits until device is no longer busy (can be used by        */
    " C3 A+ K% w$ U4 [' {# R
  933. /* Byte-Program, Sector-Erase, Block-Erase, Chip-Erase).                                */! I$ V$ I3 V( i. t
  934. /*                                                                                                                                                */; e7 r% X% h* {' J. q% E% p  V% Y: F
  935. /* Input:                                                                                                                                */* _2 j4 F& \: j- O; t; O0 {
  936. /*                None                                                                                                                        */( j! _- f# s4 @5 w; d
  937. /*                                                                                                                                                */
    6 v) A. ^  O  Q8 R8 Q4 o
  938. /* Returns:                                                                                                                                */9 S3 |' [8 I5 z% F
  939. /*                Nothing                                                                                                                        */
    " J$ ?" ~3 n* ^: v* J+ V
  940. /************************************************************************/
    * \# d, P( i* w( T7 |2 \3 G
  941. void Wait_Busy()4 A5 H( Q2 i! ], v. {! `
  942. {! @5 ?8 b- D1 {3 b
  943.         while (Read_Status_Register() == 0x03)        /* waste time until not busy */
    ' j# o$ O: ]8 ]. _8 ^
  944.                 Read_Status_Register();
    0 x) E8 D: |2 r6 _5 }# V% e. h8 H: O
  945. }
    ( }" v$ d: a" K" K
  946. $ k# r+ K% j! w; }- p  F
  947. /************************************************************************/4 J' Y$ }" Z- e- [7 {5 I
  948. /* PROCEDURE: Wait_Busy_AAI                                                                                                */3 H5 s+ ^6 }6 |6 i& ]
  949. /*                                                                                                                                                */
    ; I% j* G: z$ u! t
  950. /* This procedure waits until device is no longer busy for AAI mode.        */
    - a! M# a, Z: P
  951. /*                                                                                                                                                */& J; J" {2 D: L3 H3 G& |
  952. /* Input:                                                                                                                                */4 `  ~1 b. F3 N& ?- B; F! j' Q2 G
  953. /*                None                                                                                                                        */4 k. q3 C) w8 a" t
  954. /*                                                                                                                                                */: X' {+ ^9 G# ?- L3 t! H- r7 n
  955. /* Returns:                                                                                                                                */7 e  `; g) |" g7 q) t7 C3 d) n
  956. /*                Nothing                                                                                                                        */
    4 f) ?+ L$ V0 f! S, x  e
  957. /************************************************************************/2 ~) g, j% ]+ `/ r
  958. void Wait_Busy_AAI()3 [; m/ R% X' O7 z; g" S9 \
  959. {, i6 e, b9 x# {( T8 Y
  960.         while (Read_Status_Register() == 0x43)        /* waste time until not busy */3 m3 N6 f5 r+ A: [
  961.                 Read_Status_Register();
    ! B7 ^. w& A# |
  962. }$ ^: A: D9 e) U9 k

  963. * }- \# X2 s3 T2 p4 E, S9 c
  964. /************************************************************************/4 t+ `8 ]1 B; O0 \/ m1 M7 L
  965. /* PROCEDURE: WREN_Check                                                                                                */0 k( U5 l" Y4 G# K  X) a& N
  966. /*                                                                                                                                                */
    6 E- z* M9 `1 Y; p
  967. /* This procedure checks to see if WEL bit set before program/erase.        */4 ^( u" `  ~) a. J: I2 d
  968. /*                                                                                                                                                */. k! k" _, P, a. M
  969. /* Input:                                                                                                                                */
    ! ~4 ?; U6 ]. u' t( U% Y
  970. /*                None                                                                                                                        */
    5 M9 N* U" p' ~) L9 i& m
  971. /*                                                                                                                                                */
    % W7 R9 e5 R; {9 `; J5 H
  972. /* Returns:                                                                                                                                */
    3 J1 Q9 B, d" n% p. j& w3 D
  973. /*                Nothing                                                                                                                        */1 R; r% \( L6 P- |
  974. /************************************************************************/$ c6 w/ X% V% u8 Q7 [) T
  975. void WREN_Check()
    ' r; M5 }$ L6 i% q0 C! I
  976. {. [! F/ w$ U4 x
  977.         unsigned char byte;
    8 n2 |4 C$ |; X  S5 A( b, B0 [
  978.         byte = Read_Status_Register();        /* read the status register */
    % ?0 ~' o' U/ m) d- B
  979.         if (byte != 0x02)                /* verify that WEL bit is set */
      C" Z7 U( m" ^: b' v) @
  980.         {9 w/ m& @3 M3 t) m, b
  981.                 while(1)
    ! \% C$ e/ V8 L# W9 p( m! B; v
  982.                         /* add source code or statements for this file */' }( `5 a3 F" ^
  983.                         /* to compile                                  */. P, r+ A6 F/ }' |
  984.                         /* i.e. option: insert a display to view error on LED? */" s7 T. |1 g/ s
  985.                  / c) S+ V0 D/ C7 m- a
  986.         }
    7 K; O) I# J  ]) b2 y
  987. }
    # o& W0 I* g/ w4 D8 o  x  t% H: I

  988. * l- N* o* Q0 v2 V/ _+ j" @
  989. /************************************************************************/
    # F/ X7 ^' r4 J# Z
  990. /* PROCEDURE: WREN_AAI_Check                                                                                        */: J, X( p/ q& B- q
  991. /*                                                                                                                                                */
    + m# Q+ J6 \! G) Q6 g( o1 X
  992. /* This procedure checks for AAI and WEL bit once in AAI mode.                        */, I9 \8 p8 N0 U3 ~' N# ^
  993. /*                                                                                                                                                */& ~" u" d" M1 f% z; ?  _2 |
  994. /* Input:                                                                                                                                */3 [  z! ^0 s$ n4 z7 T
  995. /*                None                                                                                                                        */
    ! r/ u5 u4 O. r5 m3 q
  996. /*                                                                                                                                                */
    6 V4 `% |' h6 |
  997. /* Returns:                                                                                                                                */
    * |7 k2 M! v* L
  998. /*                Nothing                                                                                                                        */. s8 z/ L6 z0 z
  999. /************************************************************************/3 o2 F: k" t% W+ a$ z& n
  1000. void WREN_AAI_Check()
    , l: a: D5 ]* k4 F
  1001. {
    1 j: q; I# R9 D
  1002.         unsigned char byte;
    ! H( @9 q  i( N# w, j6 u
  1003.         byte = Read_Status_Register();        /* read the status register */
    4 n5 q+ Z) f' W
  1004.         if (byte != 0x42)                /* verify that AAI and WEL bit is set */! a% H* x* Y' m6 }$ x
  1005.         {
    * Q  b0 S* t0 A
  1006.                 while(1)                + i$ |( j4 g. Y( {! F- b5 N1 j
  1007.                         /* add source code or statements for this file */5 q8 E, O# `7 N2 \2 P
  1008.                         /* to compile                                  */
    ( o* f8 n: }; L% E  B5 |. E" d
  1009.                         /* i.e. option: insert a display to view error on LED? */
    ( z+ T1 `2 |6 S0 A. o/ a

  1010. 5 R. n7 D" Z9 _- s  K' V
  1011.         }
    , I# }# C- G5 f! W7 o. u; C
  1012. }
    ' D" S  T8 F6 j- e

  1013. 6 j" o- J, Y; o/ H6 y/ B5 }3 m
  1014. /************************************************************************/
    0 k: V7 D4 ], j; a
  1015. /* PROCEDURE: Verify                                                                                                        */8 f8 [% H3 s( [7 ?* x
  1016. /*                                                                                                                                                */
    " `% y; X7 c5 H4 Y6 ~: D
  1017. /* This procedure checks to see if the correct byte has be read.                */
    4 ?  u/ i/ S4 Z1 X0 x6 d0 |! t8 y
  1018. /*                                                                                                                                                */# C1 v5 N9 N9 x$ t: Q
  1019. /* Input:                                                                                                                                */" j( r6 m& @- C- ?
  1020. /*                byte:                byte read                                                                                        */" ?7 A8 l2 f" u9 F& D
  1021. /*                cor_byte:        correct_byte that should be read                                        */
    * d8 F$ G: l1 U0 `
  1022. /*                                                                                                                                                */
    % j5 x' N( O9 s3 B' f" Q" I8 k; A
  1023. /* Returns:                                                                                                                                */. S5 M: B# ~* ?+ g- q+ C2 P% c3 h
  1024. /*                Nothing                                                                                                                        */' G; c, U7 \% e" D: \' j9 g2 |
  1025. /************************************************************************/
    . v  b. `8 C, M. \* o
  1026. void Verify(unsigned char byte, unsigned char cor_byte)% g9 {' {1 ^3 C1 u7 D- k
  1027. {
      B. N. Y  u* d: l  \# c+ a
  1028.         if (byte != cor_byte)
    # w8 ]2 a, O' {! a
  1029.         {5 S2 H, j+ Q. d0 M" K
  1030.                 while(1)" c/ |: v9 g' V* }
  1031.                         /* add source code or statement for this file */) s! z: {! m% {- {; \) J6 x
  1032.                         /* to compile                                  */
    # g1 Z3 N6 q/ T4 c. j' w
  1033.                         /* i.e. option: insert a display to view error on LED? */
    - W2 J! g2 J& ?" ?" d4 O. p0 |
  1034.                
    7 U1 w; z* o# ~- W8 j1 A
  1035.         }
    * {+ M9 R# [/ \3 P& t
  1036. }
    - D9 }/ ~/ _% C/ x1 t( s+ R& D: k, K( z" Y

  1037. 8 r$ M. o3 {; w0 A7 u  G
  1038. . Z2 m0 W1 F  @: s, u6 L% `6 G
  1039. int main()2 C1 _5 K7 J3 A5 `7 O
  1040. {
    6 Q7 r% _' H5 n6 k
  1041. ( f: D1 Z7 m' l) G* ]1 O! @8 Z" K
  1042. return 0;8 m- H2 J, L4 q- |8 S9 p. n
  1043. }
复制代码
发表于 2007-12-11 18:30:23 | 显示全部楼层
老大:
) Z( E  ~* z5 G  G( M) m8 r1 w$ ]   main()0 O& _  w# J8 Q4 W; m+ f
   里面怎么是空的呢?. b( z  R! N4 D: P( q
   发一份给我吧  |( v4 y+ \% Z$ w) s
mail:luyijun2005@hotmail.com5 x0 k8 x4 J( |& k
咯。。。。
回复

使用道具 举报

 楼主| 发表于 2007-12-11 19:37:35 | 显示全部楼层
本部分就是如此,它提供的是方法,并不是给你拿来编译的.你要main函数能用来干什么? 为什么不看看 Byte_Program...等函数?
回复

使用道具 举报

发表于 2008-1-8 17:42:00 | 显示全部楼层
如获至宝!请问哪里能找到SPI的官方spec(我不是指flash的datasheet)?网上只能找到些片断...管理员是否可以上传spi spec至本站?
回复

使用道具 举报

发表于 2008-1-8 17:42:29 | 显示全部楼层
另外请问:EC使用SPI flash的时候,EC firmware是直接在flash上运行吗?还是dump到EC内部的ram运行?直接在flash上运行会不会速度不够快?因为SPI是串行的,还要过转换才能得到指令阿,然后MCU才能执行。
- t: p+ e1 r! s: J% {% b
, R. G6 h- M! |$ G[ 本帖最后由 screw 于 2008-1-8 17:46 编辑 ]
回复

使用道具 举报

发表于 2008-1-10 09:20:46 | 显示全部楼层
感觉有些冷清啊。不知道现在OEM一般使用多大的flash?
回复

使用道具 举报

 楼主| 发表于 2008-1-10 17:30:38 | 显示全部楼层
每个FLASHROM的SPI协义部分几乎都在自己的DataSheet(DS)里有。
. l( {+ I2 {0 p5 V$ d; uEC的代码在哪跑,你看DS的说明,每个EC都不同的。
; H; x+ L+ B7 M% y" {% n% AOEM用多大的FLASH,是由OEM决定的。或者你去各计算机厂商的网站上看看他们BIOS下载的文件有多大不就知道了?5 K4 L3 }/ H0 d8 D' s  a0 Q- R
上面几个问题是你没看任何东西而白问。# {. N) w* M( z. u3 O9 E

! q" _) X! W4 I  ?( E至于冷清,那是一定的。中国大陆本来就没多少静下心来做技术的。请问一下,你有静下心来看过spec了么?hoho...
回复

使用道具 举报

发表于 2008-1-11 18:49:08 | 显示全部楼层
该怎么说呢,我是抱着很诚恳的态度来问问题的。上面我问出来的问题都是经过认真思考才问的。您站上贴出来的跟EC有关的spec我都看多,而且是很多遍(ACPI不是全部章节都看,因为我是hw)。EC的spec我也看多很多家,因为我们要做EC chip。楼主“上面几个问题是你没看任何东西而白问。”“请问一下,你有静下心来看过spec了么?”这个结论未免武断。
. T5 h1 R3 b8 n6 Y! l9 D$ k. ~7 q
5 Q6 g! v% O  K. _关于SPI flash对SPI接口的定义,我当然知道各家spec里面都有提到,但是我要知道如何才是通用的,我们不是只要支持一款就可以。所以我才会问SPI是否有官方spec。您也知道,做产品是一定要符合工业标准的!
5 M* Y7 |/ o* l9 S: y. K. B& b( R$ t
关于EC firmware在哪里运行,除了ns有用内部flash的以外,基本都说是在flash上直接跑,并行的flash不会有问题,但是串行的flash速度可能就是问题,因此我会问到“EC firmware是直接在flash上运行吗?还是dump到EC内部的ram运行?直接在flash上运行会不会速度不够快?因为SPI是串行的,还要过转换才能得到指令阿,然后MCU才能执行。”
; t( j/ H2 Q! H1 d0 d6 g; M  a
6 M7 p# n2 w3 `0 Y! C  a关于flash的大小,我当然知道是OEM定义,所以我才问“OEM一般使用多大的flash?”。因为我猜想您应该在BIOS厂家做过,所以想问一下。何况Flash的大小跟BIOS code的大小不一定等价啊...8 o* b/ w/ Z; J* {2 @& x
. Q: s  y7 W9 l" F3 ]4 Y* q
不管怎么说,多谢。
回复

使用道具 举报

发表于 2008-1-11 18:55:40 | 显示全部楼层
我是很希望能在这里跟懂EC的人多交流的...国内弄EC的似乎不是太多
回复

使用道具 举报

发表于 2009-7-3 12:14:41 | 显示全部楼层
楼上这位前辈与我目前遇到的问题一样
5 L; g" h/ |3 N0 h7 c( i3 y, [似乎要把SPI能support 到最大,这EC chip应该有好卖点
9 O. _- z" t( S1 i/ LBIOS功能要不要强大,也就决定了SPI Flach的大小3 ]4 t- h' Q1 a
我是这么想的~让OEM去决定要挂多大!7 p. P3 m8 v9 A1 R; z( k
如果我司有BIOS工程师就好了~哈; [4 Q& Z* M  y. _( X( o
WPCE775应该算很新的东西,来看它支持到多大?! y* R  J; p4 c4 E0 {. b3 T
$ s9 j) t. O7 g3 q9 D5 C$ L/ V
另外,我觉得好多人都说会抢BUS,那肯定EC也是经过SPI 去fetch code来执行,但应该不用解到内存,因为8051的内存只做128byte+ z2 T5 B( i" K; J; o4 E6 X8 Q
其它2K byte是放在SPI flash上(ENE),不会多花时间去存放,然后再decode一次执行代码.+ O' x, x! R. t2 Q

1 r  ~; r; C' o& V6 g; m5 s* r这份driver收下~希望以后有用到0 O! d9 h7 ~1 a7 a' {
谢谢bini大大0 m0 U3 x! {2 ]2 M3 G

; }0 a7 o/ D- K' ]0 J7 U很新很新的新手,如有错误请指正 (准备看第二家的EC SPEC)
回复

使用道具 举报

发表于 2009-7-18 15:16:34 | 显示全部楼层
我也有份汇编的DOS下的烧写代码,SST 1MB的 flash可以用。我不知道为什么AFUDOS为什么不能工作,AMI好象没有发送94 CMD下来,AFUDOS直接就说不支持。搞的下BIOS非要自己写个程序,烦的很啊。
回复

使用道具 举报

发表于 2009-8-13 10:59:30 | 显示全部楼层
前端时间小弟也在windows系统下写了一个并口到SST25VF080B的烧写程序......
回复

使用道具 举报

发表于 2009-8-17 16:47:36 | 显示全部楼层

这个函数看不懂Poll_SO()

void Poll_SO()8 |1 L3 k2 K6 v3 B2 o; k' Z
{, |5 R  |, Y4 h0 Z. }: w* p) ]
        unsigned char temp = 0;
# r3 I3 |1 g# W; V, j        CE_Low();4 U9 r2 y, B: y( l" C& B
    while (temp == 0x00)        /* waste time until not busy */
' C: s# b& H4 G/ f; b3 ?                temp = SO;' ~$ a) ?$ c% U
        CE_High();3 b" k) o, v3 {( R: p) X0 L) g
}
回复

使用道具 举报

发表于 2009-8-17 17:00:56 | 显示全部楼层
void Send_Byte(unsigned char out)
8 q2 M) T4 {( _2 X3 [{7 w% W& F7 H- y4 L' O3 f
        $ ?' {. l  Q8 Z, E/ v
        unsigned char i = 0;$ k. z! k% ]$ Y# g, r
        for (i = 0; i < 8; i++)
+ h+ V* r) A" ?8 g6 X3 S4 Q0 l        {
: V7 s( v3 s  o" F  M0 J- u               
- M  D7 c% n6 c% y+ R% c% M( H                if ((out & 0x80) == 0x80)        /* check if MSB is high */! o9 g" p! t( A# H1 ]; \' `
                        SI = 1;
* u! ?  y" f% u, ?0 ?                else
: }; L+ v* {$ |. k                        SI = 0;                                /* if not, set to low */) U/ Z. {  O* c( r: Q9 r
问              SCK = 1;                                /* toggle clock high */# r' ?' B" B9 G# o
   题            out = (out << 1);                /* shift 1 place for next bit */' O' z. S/ U) m8 j" F
                SCK = 0;                                /* toggle clock low */
  u# [" Q1 M( P; x        }  z% }& ^0 H" @
}- `" P* ]9 A, w! _6 E8 _* q7 n
如果将SCK = 1; out = (out << 1); 调换。会因sck置位时间过短,而出现问题吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

Archiver|手机版|小黑屋|计匠网

GMT+8, 2026-11-22 05:07 , Processed in 0.102874 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表