找回密码
 加入计匠网
搜索
热搜: BIOS ACPI CPU Windows
查看: 55769|回复: 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  Y" C/ z' R2 F$ k2 p8 p

  2. % g8 b$ y6 S0 }5 H9 h: A' l
  3. SST25VF080B 8 Mbit(1M x 8) Serial Flash Memory
    3 @6 Q, X: p3 q% s- h9 Y$ A

  4. 5 Y% F" y/ J$ v( A$ H
  5. November 4th, 2005, Rev. 1.07 t: @* D+ K, V5 A6 H. K3 \; N
  6. * _" b- K3 ~& U- l- L6 h+ `
  7. ABOUT THE SOFTWARE
    + G: s3 A+ \; o; ^& d- ?
  8. This application note provides software driver examples for SST25VF080B,3 ^6 a6 K, F; e+ G$ @1 _3 U
  9. Serial Flash. Extensive comments are included in each routine to describe " w' }, F6 A8 G: r+ I  C
  10. the function of each routine.  The interface coding uses polling method
    , \' n# t0 |  ^5 f4 J' M$ }  W
  11. rather than the SPI protocol to interface with these serial devices.  The
    : X# a0 Q, F9 o3 s. n3 d* j
  12. functions are differentiated below in terms of the communication protocols& D( ^; t5 w# v" G: e6 L6 ]
  13. (uses Mode 0) and specific device operation instructions. This code has been ; b: e: N5 C. }
  14. designed to compile using the Keil compiler.; x; U/ C4 Y2 W+ V6 b9 m

  15. . u' o' c% c$ M4 w0 Q3 c

  16. . e  P+ m* h; \" |
  17. ABOUT THE SST25VF080B+ ^+ @) W; o/ c# Z3 {. W
  18. 1 {( K+ [* i7 T3 w# ?1 a! [
  19. Companion product datasheets for the SST25VF080B should be reviewed in
    ) E4 F, r: E! [* q5 W
  20. conjunction with this application note for a complete understanding
    & n: @- M4 y0 |/ J: ]
  21. of the device.- ?5 p! G. x. v

  22. / l  `6 m# _- w* l  v

  23. 2 m0 i: \5 N) L1 ^! N6 ?
  24. Device Communication Protocol(pinout related) functions:% f8 m7 W" R! n0 _7 ~- k
  25. , |) Z" h8 o9 S1 s4 Z
  26. Functions                                    Function' ]) G' {# S* ?; n# L( K& Z
  27. ------------------------------------------------------------------: A5 l8 A7 ^  a
  28. init                                        Initializes clock to set up mode 0.
    , u1 o+ Y9 e: s' f
  29. Send_Byte                                Sends one byte using SI pin to send and
    5 w! _6 }  g& O1 L! }, a
  30.                                                 shift out 1-bit per clock rising edge
    8 C8 {. ?) E5 J8 M
  31. Get_Byte                                Receives one byte using SO pin to receive and shift 8 j' T; x$ k6 Q
  32.                                                 in 1-bit per clock falling edge9 v0 Z3 S8 Y, O. s
  33. Poll_SO                                        Used in the polling for RY/BY# of SO during AAI programming, h& W8 |5 E, u  d! x; D
  34. CE_High                                        Sets Chip Enable pin of the serial flash to high
    / S6 d4 a2 C+ f- T3 ^
  35. CE_Low                                        Clears Chip Enable of the serial flash to low
    # l* i; ?5 V- @/ g1 A
  36. Hold_Low                                Clears Hold pin to make serial flash hold% z2 w# i4 i7 P8 W! @- G" N+ L4 y5 M
  37. Unhold                                        Unholds the serial flash
    0 ?8 ^& F3 H! @4 i
  38. WP_Low                                        Clears WP pin to make serial flash write protected, d% p3 W$ \# \% f3 h  [
  39. UnWP                                        Disables write protection pin
    & f# b  r9 L$ U
  40. / _: {0 [0 T  X- |' a1 ~
  41. Note:  The pin names of the SST25VF080B are used in this application note. The associated test code
    9 }" }% [/ {+ q, v# K
  42. will not compile unless these pinouts (SCK, SI, SO, SO, CE, WP, Hold) are pre-defined on your4 o3 g' M! c( u( |4 Y
  43. software which should reflect your hardware interfaced.          
    9 y) }; C, G0 R

  44. 1 r& i, |- j6 ~0 m* s5 V6 V

  45. 7 A/ M. m4 l, Z  h$ b6 F0 K
  46. Device Operation Instruction functions:  `* ^( p3 k% K; @2 f

  47. 8 R2 Y: T2 [  E6 L5 F7 U! ], R8 t0 \
  48. Functions                                    Function
    . K  A- b6 T1 ?- y# P
  49. ------------------------------------------------------------------0 o0 U6 P+ ^: S/ d% d
  50. Read_Status_Register        Reads the status register of the serial flash
    4 L" m4 f$ G7 C- Y/ ]! o
  51. EWSR                                        Enables the Write Status Register5 K7 r0 G) p! u. u5 ]
  52. WRSR                                        Performs a write to the status register7 \2 ]6 K1 d( S2 u% N/ }
  53. WREN                                        Write enables the serial flash& |. v! l: V2 n1 r- d% @% i5 p
  54. WRDI                                        Write disables the serial flash
    5 Q' q# g. Q8 e' a
  55. EBSY                                        Enable SO to output RY/BY# status during AAI programming9 j2 H2 _; B0 J! t  C9 Y
  56. DBSY                                        Disable SO to output RY/BY# status during AAI programming
      Z6 ]* K; q% n
  57. Read_ID                                        Reads the manufacturer ID and device ID
    ( I' Z0 {3 q2 \) F9 ]
  58. Jedec_ID_Read                        Reads the Jedec ID) E5 |: P0 e( V
  59. Read                                        Reads one byte from the serial flash and returns byte(max of 25 MHz CLK frequency)
    " ^% c4 @" @* S+ Z3 B4 z0 t
  60. Read_Cont                                Reads multiple bytes(max of 25 MHz CLK frequency)
    0 a/ Z" Y' k% ?# p+ [
  61. HighSpeed_Read                        Reads one byte from the serial flash and returns byte(max of 50 MHz CLK frequency)# p2 r9 \( G9 ?2 c* {
  62. HighSpeed_Read_Cont                Reads multiple bytes(max of 50 MHz CLK frequency)! w1 t* S! m. K! g- }
  63. Byte_Program                        Program one byte to the serial flash
      [- |0 ]4 c4 Q( [3 [
  64. Auto_Add_IncA                        Initial Auto Address Increment process
    # d8 V/ J5 u# B8 X
  65. Auto_Add_IncB                        Successive Auto_Address_Increment process after AAI initiation- E# s2 x- H/ Z1 p+ d% y! i
  66. Auto_Add_IncA_EBSY                Initial Auto Address Increment process with EBSY
    & x5 V) l+ l. f) V+ x
  67. Auto_Add_IncB_EBSY                Successive Auto_Address_Increment process after AAI initiation with EBSY and WRDI/DBSY
    ( Y( b1 _! e3 b/ \
  68. Chip_Erase                                Erases entire serial flash
      q9 c0 D3 A# B5 }
  69. Sector_Erase                        Erases one sector (4 KB) of the serial flash1 s6 Q5 u  ^5 f' J3 l
  70. Block_Erase_32K                        Erases 32 KByte block memory of the serial flash1 H- F0 y* |( O( r+ S
  71. Block_Erase_64K                        Erases 64 KByte block memory of the serial flash
    4 d, s3 P% G" R/ j. G5 e9 W$ ?
  72. Wait_Busy                                Polls status register until busy bit is low
    $ _6 N' _. _( y8 y1 X7 u+ J/ ?
  73. Wait_Busy_AAI                        Polls status register until busy bit is low for AAI programming
    0 P  Y& a, v$ V) b  J# F. H/ F
  74. WREN_Check                                Checks to see if WEL is set/ W5 U  H  K- f  M
  75. WREN_AAI_Check                        Checks to see if WEL and AAI mode is set' q1 G. T: L: ]4 _! i) Z4 J' t! [
  76. . D6 D! y$ P* I5 D
  77. % P# F/ I- ^/ e
  78. 6 x6 o* }1 q- M0 {' b9 a" f/ l
  79.                                                                      
    / B* i0 ~! {+ ?/ C+ Y  |
  80. "C" LANGUAGE DRIVERS 8 j) E. V8 M( L+ O# I* Y
  81. ; B$ @, E* ~# V- ]. g; F. {
  82. /********************************************************************/
    6 t% y0 W3 [  H- o8 Z& D4 d
  83. /* Copyright Silicon Storage Technology, Inc. (SST), 1994-2005            */' M" i4 e) `6 L
  84. /* Example "C" language Driver of SST25VF080B Serial Flash                        */9 H* q# V/ [& k/ e% J
  85. /* Conrado Canio, Silicon Storage Technology, Inc.                  */
    ( [# }8 R: j7 a7 |7 T' f9 K2 Z
  86. /*                                                                  */" Q2 f+ O7 a* J- D# g( W1 w) T
  87. /* Revision 1.0, November 4th, 2005                                                                          */   
    - Y5 n; v# j; m6 J
  88. /*                                                                  */7 v7 H$ N: p' m, Q
  89. /*                                                                                                                                        */* M: I! z3 i/ R1 p- x) J
  90. /********************************************************************/
    7 _/ E# t5 a4 _9 ?0 p  W
  91. 5 I1 F* U  }5 f9 t+ x9 l
  92. #include <stdio.h>
    * o( V6 W: |* S) |4 }# B: {* `
  93. #include <stdlib.h>
    7 F8 o) \3 T* j: o
  94. % y6 J4 e& L; U
  95. /* Function Prototypes */9 K9 }" L9 R$ ]- x# @! ?

  96. $ c) _8 l% A5 W
  97. void init();% J$ X: L6 E/ q0 p
  98. void Send_Byte(unsigned char out);
    ' J" ^0 l( x" h/ e. D
  99. unsigned char Get_Byte();
    9 G+ C, _4 `1 H" H: W7 p7 `" Z3 I+ ?
  100. void Poll_SO();. V! B. q1 u8 |- N$ r' W
  101. void CE_High();
    8 }, O% ]5 W1 ]3 ]
  102. void CE_Low();
    - ^8 u: T0 f# j% ^; r: \
  103. void Hold_Low();' Y7 u0 l8 n; ~1 k6 J
  104. void Unhold();, s3 s8 m: i5 h  }# D
  105. void WP_Low();
    8 v/ h: P6 r! ?% K1 T
  106. void UnWP();/ C5 h( q2 `! f, v3 v# [) R1 q+ W  {" [
  107. unsigned char Read_Status_Register();1 i# S+ n- B4 C% h/ G5 Z
  108. void EWSR();
    1 h! l6 L$ S# j4 o2 _% u, g$ C6 |7 Y1 W
  109. void WRSR(byte);
    2 L3 s) j! Z; e. K
  110. void WREN();
    7 v- ^& ~; C" a7 V3 a" P# z) [: }" x
  111. void WRDI();
    " @# E9 V- w8 c0 K& ?, Y
  112. void EBSY();9 R; O( |& `; x2 W- w) J9 q
  113. void DBSY();
    $ `1 Z$ t: P& j. y6 G' \$ h, s
  114. unsigned char Read_ID(ID_addr);) X; x* X1 Y. k- h+ U; A6 i$ [( k
  115. unsigned long Jedec_ID_Read();
    5 _: }( q2 H( i$ M
  116. unsigned char Read(unsigned long Dst);1 r" {+ N% x+ D4 [5 W2 ?
  117. void Read_Cont(unsigned long Dst, unsigned long no_bytes);
    2 R" ^& u3 a$ P7 k
  118. unsigned char HighSpeed_Read(unsigned long Dst); 2 G3 t$ i1 M, w+ C" b4 a
  119. void HighSpeed_Read_Cont(unsigned long Dst, unsigned long no_bytes);
    9 e" P6 L1 L5 d  x. K2 ]! [7 q# i
  120. void Byte_Program(unsigned long Dst, unsigned char byte);: {, `8 |# Q, C% Q% n
  121. void Auto_Add_IncA(unsigned long Dst, unsigned char byte1, unsigned char byte2);2 L( h( y3 Q; _# c, v+ Z8 {
  122. void Auto_Add_IncB(unsigned char byte1, unsigned char byte2);
      }# N6 ~# L/ I. n# j( F( @5 X& a" f
  123. void Auto_Add_IncA_EBSY(unsigned long Dst, unsigned char byte1, unsigned char byte2);( T/ q6 R) \; ^; r- L* {& S1 ~
  124. void Auto_Add_IncB_EBSY(unsigned char byte1, unsigned char byte2);  a+ H/ ]6 d& G. ^) X7 ^
  125. void Chip_Erase();8 S- s$ X' l1 T
  126. void Sector_Erase(unsigned long Dst);
    - c  k' B2 W- t7 I' K1 ?
  127. void Block_Erase_32K(unsigned long Dst);9 }8 J1 D7 a# i: r. E
  128. void Block_Erase_64K(unsigned long Dst);6 Q5 K+ ?4 _2 l/ y4 N  g
  129. void Wait_Busy();
    - {5 S4 u. d# y$ e
  130. void Wait_Busy_AAI();- N9 p4 V% y1 X4 l9 Y  y
  131. void WREN_Check();  g) {6 D% ^! f2 H
  132. void WREN_AAI_Check();, V% l* `- k/ F
  133. " Q+ W" e6 @" d; Q- j' B
  134. void Verify(unsigned char byte, unsigned char cor_byte);. f; q1 v1 T5 a, f

  135. # w( o4 e- r3 N- d( e7 R2 O1 g& L
  136. unsigned char idata upper_128[128];                /* global array to store read data */
    0 a, r& t  C6 l1 f3 y
  137.                                                                                 /* to upper RAM area from 80H - FFH */
      B) ^8 L+ T& |, S' [+ O4 \

  138. ; X0 z2 s* f! z
  139. /************************************************************************/( A* q) t8 }2 j4 S) F* z" R
  140. /* PROCEDURE: init                                                                                                                *// a4 x! B! u1 j3 t. w0 g' e- q6 P" e3 W
  141. /*                                                                                                                                                */
    6 |: i3 y  g2 n2 R" E2 m+ ^
  142. /* This procedure initializes the SCK to low. Must be called prior to         */& f" g$ i  r- q6 Y
  143. /* setting up mode 0.                                                                                                        */
    3 H4 l0 v1 L( u5 Q
  144. /*                                                                                                                                                */
    $ m& l3 x; y& L* W: ]4 V- w
  145. /* Input:                                                                                                                                */) o; K0 x; s$ D" A0 w! X1 U) S
  146. /*                None                                                                                                                        */
    & K: b' `$ D+ U8 x8 B! i3 l8 |1 }3 s
  147. /*                                                                                                                                                */, Y, d: I4 \$ N6 K6 D
  148. /* Output:                                                                                                                                */
    4 y# @- N7 b% C
  149. /*                SCK                                                                                                                                */# x+ S' F* Y& D) g" G  k
  150. /************************************************************************/- z$ E' j% D# d# Z
  151. void init()
    - d# f, \: x2 T/ `4 y
  152. {
    $ f/ C" a4 X8 e3 G) ~
  153.         SCK = 0;        /* set clock to low initial state */, n9 w7 L# F& G3 ^- p( @* c! [/ P
  154. }
    8 X6 P3 h% [7 d! X- _9 K$ X, E
  155. 0 ?2 j0 F6 j2 g0 x/ D, p8 o* u
  156. /************************************************************************/
    4 O" Z2 a: K9 {* d* d% ?3 q
  157. /* PROCEDURE: Send_Byte                                                                                                        */
    7 a/ L7 A, d4 _
  158. /*                                                                                                                                                */
    8 z4 M  z% r% t( q
  159. /* This procedure outputs a byte shifting out 1-bit per clock rising        */
    4 o& M& a6 y& Y7 t
  160. /* edge on the the SI pin(LSB 1st).                                                                                */; R& |0 s2 H  ]$ W4 u0 J/ }
  161. /*                                                                                                                                                */- R8 ~6 V5 X1 v$ P6 j  T/ \: H
  162. /* Input:                                                                                                                                */2 P& ?0 J3 A' }; S$ V2 [/ M
  163. /*                out                                                                                                                                */
    $ K$ [4 P* x/ Y1 Q6 q5 `
  164. /*                                                                                                                                                */) Y0 x( T; ]  o* _! l2 B* U& l) f+ f
  165. /* Output:                                                                                                                                */' G2 _- p4 A: B9 U
  166. /*                SI                                                                                                                                */( K' n; J: x9 f/ V0 S
  167. /************************************************************************/! X- \, U& w( A$ \+ m8 b
  168. void Send_Byte(unsigned char out)/ b- h7 F) Z% m% q3 q
  169. {
    & w6 r3 x9 ~8 N4 H. r$ W
  170.         + ]$ b1 _$ ?8 @- j* l& R$ Q1 Z8 a
  171.         unsigned char i = 0;
    7 d( u' ]* ?; d) n2 g! X- l
  172.         for (i = 0; i < 8; i++)9 ]. e* a" ]0 O+ e$ _3 Y
  173.         {5 i$ W- A3 v* ~
  174.                 2 a" q9 M! y5 V7 P, p8 E
  175.                 if ((out & 0x80) == 0x80)        /* check if MSB is high */
    0 O3 \+ `! y, W: F) ]
  176.                         SI = 1;
    . Y/ W1 ?# Z- N3 ?" w
  177.                 else
    8 w$ `$ v& l5 \1 Q, W5 G" {
  178.                         SI = 0;                                /* if not, set to low */
    2 m0 [# O4 t) K! f. Y4 ^
  179.                 SCK = 1;                                /* toggle clock high */
    9 i" y' q* B8 y7 U/ I
  180.                 out = (out << 1);                /* shift 1 place for next bit */, r5 O. G. p' X( ?
  181.                 SCK = 0;                                /* toggle clock low */" G5 P: v: @1 I: b
  182.         }: h( M& e, F( N  d' c& h
  183. }9 A- a, K* Y, V4 k6 A; O
  184. 6 V% H; E( [8 e) O- ?: ?
  185. /************************************************************************/
    . G1 \* X/ F8 [4 u: ^1 i/ }
  186. /* PROCEDURE: Get_Byte                                                                                                        */8 ]& e. P" U& n# f! W# x" @1 l
  187. /*                                                                                                                                                */( T0 Q7 Q$ E4 B9 e+ f. z
  188. /* This procedure inputs a byte shifting in 1-bit per clock falling                */! L, r3 N- ^* l. _) p
  189. /* edge on the SO pin(LSB 1st).                                                                                        */
    3 c' ~% p; |, Z0 {/ V6 d- B- j
  190. /*                                                                                                                                                */* \; Z- n" i4 D
  191. /* Input:                                                                                                                                */$ g5 Z6 ^8 Q2 x% @$ m! @7 d
  192. /*                SO                                                                                                                                */' n& E% a, P6 V$ e( I) m% K2 y
  193. /*                                                                                                                                                */2 p% j" S6 Z* j8 H* A8 O  f( {
  194. /* Output:                                                                                                                                */
    7 Q9 i) `) h+ u# t" ]
  195. /*                None                                                                                                                        */
    % O$ Z7 m' |0 V$ ~, p/ U- H% A
  196. /************************************************************************/) N2 u0 z& I8 z7 E+ c1 W
  197. unsigned char Get_Byte(); Q; z& f# j$ i* k8 K* ~: L" {8 ^# V
  198. {$ `5 x) l3 {: A8 M) l
  199.         unsigned char i = 0, in = 0, temp = 0;! q; R* [0 S2 Z! Z. R" t
  200.         for (i = 0; i < 8; i++)1 R9 c, |  U6 v; J  k/ o( |
  201.         {
    5 C) o4 X  O; e% j+ v) L
  202.                 in = (in << 1);                /* shift 1 place to the left or shift in 0 */$ W! N# P6 C0 `) ]: B/ Q6 ^+ A
  203.                 temp = SO;                        /* save input */0 P1 b( Z# g# d9 p, E* Z8 b
  204.                 SCK = 1;                        /* toggle clock high */; F: c4 C9 V) o& i/ A1 [
  205.                 if (temp == 1)                        /* check to see if bit is high */+ d; r, L' m1 v+ Y
  206.                         in = in | 0x01;                /* if high, make bit high */0 ~& D! D7 a/ _7 V' M

  207. 7 l# P: ]' L8 l( ?  Q1 L% \8 r
  208.                 SCK = 0;                        /* toggle clock low */
    ! J, ~4 q+ }6 s6 V3 a7 e( D

  209.   [, n* q! P& }+ h, `' ^# y
  210.         }7 j/ \/ O+ T8 s* k
  211.         return in;! E9 S3 q" A- c. V9 R# |* {
  212. }7 w4 d3 @& [: U/ S% c! Q
  213. 9 W1 N8 f4 s4 l" `$ [
  214. /************************************************************************/' {# Y) H8 `% S1 S
  215. /* PROCEDURE: Poll_SO                                                                                                        */
    & y8 K# |1 n1 ?; u+ A
  216. /*                                                                                                                                                */% F8 b9 [0 v* h. a4 E/ O8 w5 u
  217. /* This procedure polls for the SO line during AAI programming                  *// _# M/ @$ U+ w! ?3 A' T
  218. /* waiting for SO to transition to 1 which will indicate AAI programming*/) x# T! R$ @" h3 S. O
  219. /* is completed                                                                                                                        */
    7 Z( j0 y& s5 j5 V
  220. /*                                                                                                                                                */3 }0 z8 i+ F+ j9 c. X# w* W0 e% [
  221. /* Input:                                                                                                                                */* a  y  W6 y/ S" g8 ]! s9 k8 v
  222. /*                SO                                                                                                                                */
    7 K) S% ~$ L: F& ^2 x) s
  223. /*                                                                                                                                                */, A4 o7 K, P6 d+ s* O7 m$ l; N8 @
  224. /* Output:                                                                                                                                */
    2 j1 [( R3 d! z# W& S
  225. /*                None                                                                                                                        */
    4 E5 c! Q, W) W; L
  226. /************************************************************************/
    2 U, [: [6 `) b# G3 N4 S  l
  227. void Poll_SO()) S+ W4 g- m, j; p9 P( z
  228. {
    5 N. F0 E2 m, b, K6 B/ F" d0 r
  229.         unsigned char temp = 0;
    7 ~: j1 X. f1 D! Q' x$ V+ K+ P
  230.         CE_Low();
    5 C# a! w) W5 {4 V
  231.     while (temp == 0x00)        /* waste time until not busy */
    / }% g( N1 I( S& X$ r$ ^. O* e6 h6 }+ L# ]
  232.                 temp = SO;
    6 O' Z. C( J) T! w8 X: D  k
  233.         CE_High();7 @2 V0 G$ Y7 x( i% i: e+ X+ m% i
  234. }8 X5 X; ~* Q$ T2 G

  235. : S( z- P  E; S, Y3 v" [( g5 N
  236. /************************************************************************/
    4 C1 B+ d. [9 P5 M1 H! a0 j
  237. /* PROCEDURE: CE_High                                                                                                        */
    - `4 h( B$ V/ n8 u9 Z2 s4 w
  238. /*                                                                                                                                                */8 d& w) q3 W8 l
  239. /* This procedure set CE = High.                                                                                */9 M0 A" \. X5 I$ s
  240. /*                                                                                                                                                */, m  X# T7 |. a& I+ p
  241. /* Input:                                                                                                                                */; g4 X$ z  Z0 s! b( i) P8 j$ t' }
  242. /*                None                                                                                                                        */( E- b$ i3 F- k/ P/ ~" ?' {
  243. /*                                                                                                                                                */
    5 s$ V; U' H; m: p  e
  244. /* Output:                                                                                                                                */$ T, s2 J: Q1 @* {0 o
  245. /*                CE                                                                                                                                */
    0 _$ E/ J: M+ I' l
  246. /*                                                                                                                                                */
    # C4 @7 d6 s% f+ a+ N, \' A# m
  247. /************************************************************************/1 _. ]* f+ `. d' y; b; T9 d
  248. void CE_High()
    : W" E" b: R9 l, c  g0 T
  249. {9 \3 Z; y+ j3 [/ m0 {. _+ D
  250.         CE = 1;                                /* set CE high */
    3 g) h  k' P3 h. U
  251. }
    % t* K5 B9 k  B' u% r
  252. ; w, Z  v, n6 i/ V
  253. /************************************************************************/
    : `* y/ V7 C! l7 h) A+ U9 V
  254. /* PROCEDURE: CE_Low                                                                                                        */6 w& e" i& P& m6 c
  255. /*                                                                                                                                                */8 R9 j+ k8 _7 A$ V: M: h5 T
  256. /* This procedure drives the CE of the device to low.                                          */, @4 X0 ^" q. K% h- t- ^) b( c
  257. /*                                                                                                                                                */
    & A( e3 {2 p* _* M/ T+ R
  258. /* Input:                                                                                                                                */
    : Y2 q6 z$ g* T# s) \# ]
  259. /*                None                                                                                                                        */3 g" E% {& f$ W, E
  260. /*                                                                                                                                                */+ h1 Y2 L) V; J8 `
  261. /* Output:                                                                                                                                */
    8 o) [5 F. E$ r+ `$ m1 p+ F
  262. /*                CE                                                                                                                                */
    . n9 j6 H" H8 p" X" R  N
  263. /*                                                                                                                                                */
    2 _" D3 n' b+ k) C* ~
  264. /************************************************************************/- N  h3 O7 m; m% a. o
  265. void CE_Low()
    , Z# r2 l+ [0 z9 @
  266. {       
    3 S- E8 F0 C& K# q
  267.         CE = 0;                                /* clear CE low */
    2 I) G& L; S, O/ Y! z+ R
  268. }
    $ M, `; Z8 G6 I6 v
  269. " r' w" d+ G2 k& @3 [* U
  270. /************************************************************************/
    . Z7 Q' q5 X4 ?" O+ n, l
  271. /* PROCEDURE: Hold()                                                                                                        */
    0 d* h. V6 }- o3 j  S7 a
  272. /*                                                                                                                                                */2 |3 ~( `* g' y2 ~) W+ G2 P
  273. /* This procedure clears the Hold pin to low.                                                        */
    # h$ E( y7 o9 W; O$ F
  274. /*                                                                                                                                                */9 ^. _. K4 P3 Q0 o' t/ `5 d
  275. /* Input:                                                                                                                                */- \5 _) Q5 P1 m  I
  276. /*                None                                                                                                                        */7 t' j" o' n; y: O: X! r2 E6 o
  277. /*                                                                                                                                                */% J  p: @' p4 E* @/ r
  278. /* Output:                                                                                                                                */
    * _  D; W5 c4 h
  279. /*                Hold                                                                                                                        *// h3 n$ |% R: {; C
  280. /************************************************************************/
    7 P0 a5 c8 k1 l9 g' {% y
  281. void Hold_Low(), d: ^& F- C/ t! u3 F1 `
  282. {4 E+ N* n  e$ j8 q: a! a
  283.         Hold = 0;                        /* clear Hold pin */
    - F, A1 J" C3 S+ [6 e" \- A( }2 y
  284. }# Y5 Y5 Y( L1 a! l
  285. 2 @/ L; t% Z9 t
  286. /************************************************************************/
    1 \7 K  I' d" Y& ~
  287. /* PROCEDURE: Unhold()                                                                                                        */
    3 U! Y) O& u# q" I' q
  288. /*                                                                                                                                                */: [' }( ^, V' [$ a5 b) \9 `6 d5 _
  289. /* This procedure sets the Hold pin to high.                                                        */5 g" B; [) [( n* f3 O2 U2 @1 R
  290. /*                                                                                                                                                */: a% y" A. D) f- S  ^
  291. /* Input:                                                                                                                                */% D6 K- v5 q0 w) |: {
  292. /*                None                                                                                                                        */
    ) D: G' [6 F7 {' m4 _" l: o, y# {! p
  293. /*                                                                                                                                                */7 b8 z  {5 a) f, I3 [7 U
  294. /* Output:                                                                                                                                */, b* p+ ^# W3 k# K$ A) U# G/ c0 W  z  \
  295. /*                Hold                                                                                                                        */: T* T" s6 g) u% q: B: m$ b6 x, F
  296. /************************************************************************/
    6 e) q" W0 Z* N8 i7 W) F4 A
  297. void Unhold()! I+ c7 w( d# e" s' {4 c, z: `
  298. {
    9 y! J6 \% `, r! I
  299.         Hold = 1;                        /* set Hold pin */
    * k- \; \0 E/ j3 V6 C2 R
  300. }! V( ~8 T! {: j8 e+ f# I# B
  301. 1 ~; e+ x4 {/ v- O
  302. /************************************************************************/
    ) X3 W! l, i$ I  C. \# K2 W
  303. /* PROCEDURE: WP()                                                                                                                */+ u+ u) L, w7 U' f7 t3 Z
  304. /*                                                                                                                                                */
    - v$ O% Z! @1 X5 A5 \* m8 G6 p
  305. /* This procedure clears the WP pin to low.                                                                */
    . d; H$ T0 q, ?. W. a. j* D# D9 `
  306. /*                                                                                                                                                */8 L8 M2 F7 ^! Y* |9 ?
  307. /* Input:                                                                                                                                */" T* e6 U/ u# V! |) z2 D
  308. /*                None                                                                                                                        */
    ) H9 q# e* e5 K
  309. /*                                                                                                                                                */
    8 Z! a* _2 u, R. y, L9 c: h+ i
  310. /* Output:                                                                                                                                */
    , s2 l3 [5 C* q4 ]/ N
  311. /*                WP                                                                                                                                */
    0 b' B; T. {' }; ^' P' u3 w
  312. /************************************************************************/6 i  y% }5 R( I* _2 N! Z
  313. void WP_Low(): o$ k. s6 B9 {: n/ o. a* g
  314. {
    . p% l4 c) z' i, f+ I
  315.         WP = 0;                                /* clear WP pin */' H1 a% L: M7 v
  316. }5 S* P. w+ m% C8 a

  317. 0 i5 ?0 T% N) ?1 l
  318. /************************************************************************/
    5 D" u; M4 e, g1 ^+ S0 v, M0 Q
  319. /* PROCEDURE: UnWP()                                                                                                        */
    - P! ^& t( h. O
  320. /*                                                                                                                                                */
    ' Z7 ?1 v8 E) P9 l7 l3 z
  321. /* This procedure sets the WP pin to high.                                                                */
    3 P; B0 _7 i& R! K0 q9 r- L7 |
  322. /*                                                                                                                                                */
    / B4 G  P3 r0 e8 h6 U3 y
  323. /* Input:                                                                                                                                */" C/ q8 N5 r$ U) I0 R3 |
  324. /*                None                                                                                                                        */
    9 y( O$ D& B9 V+ G
  325. /*                                                                                                                                                */7 ]! u5 o, h# z; ?, c3 ]* Z" A, v
  326. /* Output:                                                                                                                                */
    6 p: s' d8 S; \7 @6 V# e
  327. /*                WP                                                                                                                                */
    : ]* z! w1 n9 ~2 a
  328. /************************************************************************/3 Q' M6 B# [! A1 h6 q+ l. t% c. P6 Q$ T
  329. void UnWP()" `/ V1 ^- V4 u& U: `
  330. {
    . X  r6 S  r) F; M2 r- _
  331.         WP = 1;                                /* set WP pin */
    8 Y% w8 d+ e  E
  332. }
    ) n+ Z3 d2 N0 W' v* v

  333. % ^. v6 T$ K6 d; }/ G
  334. /************************************************************************/
    6 q# K4 i' j& o" L% w$ ~" Z; d  U
  335. /* PROCEDURE: Read_Status_Register                                                                                */
    6 \' ^4 ?/ Z9 I7 u0 i- X5 e
  336. /*                                                                                                                                                */" R1 `! Q% \0 A% }& _# g1 d* a9 i  W
  337. /* This procedure read the status register and returns the byte.                */' r6 K. _3 Q7 b1 ]) F+ L
  338. /*                                                                                                                                                */
    & N9 k6 z+ O! w$ K
  339. /* Input:                                                                                                                                */
    $ T) z( e% i1 y) ?0 S' d6 p+ m9 `
  340. /*                None                                                                                                                        */
    2 b) P; _; s& X7 R, `2 j
  341. /*                                                                                                                                                */- K7 g$ W3 d0 ?5 R
  342. /* Returns:                                                                                                                                */7 ]7 p! p6 _* H5 r2 B3 _
  343. /*                byte                                                                                                                        */' i4 t3 C) h* q
  344. /************************************************************************/
    1 |" N. l9 g$ p& Y) S5 J
  345. unsigned char Read_Status_Register()
    + `% L2 Z8 K* e& F
  346. {
    , I( `6 W0 e2 u( j8 f
  347.         unsigned char byte = 0;
    6 p( [4 Y) V7 P  M# n
  348.         CE_Low();                                /* enable device */* a# R" x7 o# {: d
  349.         Send_Byte(0x05);                /* send RDSR command */& w. D8 G" b& W0 a; L1 P
  350.         byte = Get_Byte();                /* receive byte */
    ' z' f6 }- |% j' }6 U5 F7 O, s
  351.         CE_High();                                /* disable device *// E+ R& k( d2 @
  352.         return byte;
    5 F7 L8 {' J) R$ E4 J) {# w
  353. }
    & C3 i% W) H1 C9 R3 f! z2 w  c9 w

  354. # p9 ]; o8 q% Q$ `
  355. /************************************************************************/( l8 W% M, @8 M) f& k' w9 j
  356. /* PROCEDURE: EWSR                                                                                                                */" P1 F# U$ \) A0 y
  357. /*                                                                                                                                                */' v) j& {) R2 F- i0 m
  358. /* This procedure Enables Write Status Register.                                                  */! G3 N5 U8 C9 V( f$ P3 m  r3 h; W
  359. /*                                                                                                                                                */
    / Y  X* C/ T9 Q9 b) E
  360. /* Input:                                                                                                                                */! g. c0 p* x9 J4 i! w5 ]
  361. /*                None                                                                                                                        */
    / \, M+ \2 N4 b8 A1 |
  362. /*                                                                                                                                                */" I1 u+ d7 q4 c7 F% Q  ~3 s  N
  363. /* Returns:                                                                                                                                */" Z& z4 {8 ]' |) v, F
  364. /*                Nothing                                                                                                                        */
    * g5 a1 X2 a4 [! f* [6 J
  365. /************************************************************************/
    5 H2 E) \% N" o4 T5 U3 @
  366. void EWSR()8 l  ]4 L0 @- _
  367. {
    & W( A: ?- `4 {* {0 b3 t' y
  368.         CE_Low();                                /* enable device */
    , {' o, M& `# O8 p1 f
  369.         Send_Byte(0x50);                /* enable writing to the status register */. o8 P' W1 k' s% }- i, n( [
  370.         CE_High();                                /* disable device */0 `# _# ?5 L9 K- y& I9 {
  371. }
    0 Z8 b# t6 ]( t" [
  372. ' t0 B' P9 D0 h/ |* u$ Z! F8 Z$ u
  373. /************************************************************************/
    0 O; U( x% k! T" x* C9 T
  374. /* PROCEDURE: WRSR                                                                                                                */' w/ F* Y3 [; G% A& y
  375. /*                                                                                                                                                */
    8 G2 G. t/ }' J; C1 v
  376. /* This procedure writes a byte to the Status Register.                                        */: c. P$ z  m  ?( }# z( a* X9 p$ y
  377. /*                                                                                                                                                */
    " ?3 x4 |- T) C0 Y/ o/ X
  378. /* Input:                                                                                                                                */! S4 E0 {  u# k, b# L" M
  379. /*                byte                                                                                                                        */- t! Y/ y; g) q7 q; [+ V" q) ?
  380. /*                                                                                                                                                */& i; y3 O) N1 d  h, k* h( n
  381. /* Returns:                                                                                                                                */* E- b7 r; s3 Z6 N- e3 b
  382. /*                Nothing                                                                                                                        */
    $ u# t: M0 {( L2 y
  383. /************************************************************************/; ]& \1 s% [5 ?( n
  384. void WRSR(byte)# Z# u2 X$ u5 e. Z) K8 g7 y" T# D
  385. {
      N. n% U& f' r9 G  @7 G; L
  386.         CE_Low();                                /* enable device */
    : Z/ C& o5 M7 a6 x0 P
  387.         Send_Byte(0x01);                /* select write to status register */2 Z  \1 i! o. c, n* h3 B$ n* c
  388.         Send_Byte(byte);                /* data that will change the status of BPx
    ) \. }, F$ r1 ^: O
  389.                                                                 or BPL (only bits 2,3,4,5,7 can be written) */' i% t: V3 w+ @2 D1 H/ U0 F" o
  390.         CE_High();                                /* disable the device */6 H. E( t! j7 P8 Z  U+ u; c4 _
  391. }( E7 ?& M8 d7 ?8 V4 n( A

  392. : C( b# w  B6 J! B- N- d
  393. /************************************************************************/8 F& e7 }* l( f; k# Q8 }$ {) u( n
  394. /* PROCEDURE: WREN                                                                                                                */0 n3 p! b# o! Z8 g8 V
  395. /*                                                                                                                                                */' X" d6 k9 n$ Q( `3 t
  396. /* This procedure enables the Write Enable Latch.  It can also be used         */
    / ?. p5 v1 X* y2 S- O; J" J2 w% n$ t
  397. /* to Enables Write Status Register.                                                                        */* D  |' u1 A, A" F/ _
  398. /*                                                                                                                                                */
    / D( Y4 I! G1 k' I9 r+ d& @
  399. /* Input:                                                                                                                                */
    2 Q8 N5 L7 E/ C9 U
  400. /*                None                                                                                                                        */
    4 B* n) P# A: B9 y8 L  r" x
  401. /*                                                                                                                                                */
    7 \2 ]9 {+ \  c3 J
  402. /* Returns:                                                                                                                                */0 V" Y1 Q4 {/ w9 h
  403. /*                Nothing                                                                                                                        */5 O* S+ Q0 V# _0 [. y
  404. /************************************************************************/
    - f! J! T. c( @0 o0 v2 F
  405. void WREN()
    4 S% C/ \- s2 `" q
  406. {
    % e& O" n. i5 u6 Z1 e
  407.         CE_Low();                                /* enable device */- O) h! m$ o: i4 i5 l
  408.         Send_Byte(0x06);                /* send WREN command */6 O/ R/ g7 i4 v  e+ P9 E! m
  409.         CE_High();                                /* disable device */
    ( B5 O. V9 t' G
  410. }
    , F4 r4 @0 L' Z; ~4 m( ^

  411. ; @5 S& S- J5 O# I5 B, Q7 c  }
  412. /************************************************************************/
    $ C4 n) d% C/ e; E2 c
  413. /* PROCEDURE: WRDI                                                                                                                */# Y0 z5 l' W: [  i* h) K
  414. /*                                                                                                                                                */+ U; P5 y( m1 r  y, q2 Q/ B: J
  415. /* This procedure disables the Write Enable Latch.                                                */  K& f; t6 i  U% @( I/ M
  416. /*                                                                                                                                                */
    & y- d- E: X8 w0 b3 h6 j) H
  417. /* Input:                                                                                                                                */
    ) q$ b1 A) B  w5 P- d! ^
  418. /*                None                                                                                                                        */1 ~4 x, {5 b( l8 t
  419. /*                                                                                                                                                */! Z& q$ c' A6 J8 q8 p% W7 y
  420. /* Returns:                                                                                                                                */
    8 }% C; x8 r5 e
  421. /*                Nothing                                                                                                                        */: H8 v, W( b+ x
  422. /************************************************************************/
    , W& j% c& p) v  P' S
  423. void WRDI()/ D  R% E, ^( U
  424. {+ F& |: I( G- B+ k/ }, ^: C' a4 O  `
  425.         CE_Low();                                /* enable device */
    ; n" z/ G+ i$ e3 a' U0 S+ S( \: q
  426.         Send_Byte(0x04);                /* send WRDI command */" r) V/ D: l6 Y6 J
  427.         CE_High();                                /* disable device */6 Q6 D! B0 X- [3 l
  428. }
    # X( a- ^# c; b5 X7 d" G- f8 i
  429. ' z8 T9 `$ v8 d# V, W. T2 |# q
  430. /************************************************************************/) g- B/ L- E- q" _) [- n
  431. /* PROCEDURE: EBSY                                                                                                                */8 {; g4 C; g" u; s
  432. /*                                                                                                                                                */2 Y* q$ s2 e5 S* t3 \) l
  433. /* This procedure enable SO to output RY/BY# status during AAI                         */7 Y, \4 U" i9 z0 L+ A6 S! a& ?0 r2 W
  434. /* programming.                                                                                                                        */
    5 N& H" e) \& {5 c
  435. /*                                                                                                                                                */0 Q. h5 g" y1 `  m8 }7 S
  436. /* Input:                                                                                                                                */
    + v( l# l, ~; b! p( Z3 Z7 i
  437. /*                None                                                                                                                        */: b3 ]7 |1 p1 O- x7 b1 d
  438. /*                                                                                                                                                */
    2 E3 l* b' O& P2 X, w
  439. /* Returns:                                                                                                                                */
    ) \4 T- A: B7 ~
  440. /*                Nothing                                                                                                                        */& g1 i. t; U' \( H5 }, D
  441. /************************************************************************/
    $ `4 U( ~0 D" h" Y/ H
  442. void EBSY()
    / ?" p* i% O3 |9 \9 u1 J
  443. {
    6 ^; N6 x* @& b' b9 Q8 \- A# N
  444.         CE_Low();                                /* enable device */
    " {* C# `* t( \9 u7 O
  445.         Send_Byte(0x70);                /* send EBSY command */$ a9 j1 I! k4 A; T
  446.         CE_High();                                /* disable device */% @8 _9 |( o& N& x3 `
  447. }- }1 i- u! A5 e! o

  448. & e% Y1 n# J5 T3 \0 \
  449. /************************************************************************/; u* Q4 {% C2 y: u, @
  450. /* PROCEDURE: DBSY                                                                                                                */
    ' g9 c" y- Q' E- i( C6 }
  451. /*                                                                                                                                                */9 y5 Q. R) ~' z$ `% A- ^$ G
  452. /* This procedure disable SO as output RY/BY# status signal during AAI        */
    % H) [) o" q( b% }2 @- K/ ~' y
  453. /* programming.                                                                                                                        */- k( a) v$ w; a! e8 T
  454. /*                                                                                                                                                */% ]5 p7 _' \3 @6 J- c
  455. /* Input:                                                                                                                                */
    ' X( @$ f( w% Z! x
  456. /*                None                                                                                                                        */
    & Z- r# \  ^7 e% Y, J) p
  457. /*                                                                                                                                                */
    6 m6 s7 B3 k# `: ^! M- k& \% L
  458. /* Returns:                                                                                                                                */" Z2 S6 l! f9 A- p
  459. /*                Nothing                                                                                                                        */! v2 n1 j/ `7 ~
  460. /************************************************************************/- K6 W5 }4 n+ x0 [6 ?% L
  461. void DBSY()
    . C# E+ F2 \; ?4 q: N' R6 B7 a
  462. {
    6 v1 V. R% J# |$ V6 W9 m
  463.         CE_Low();                                /* enable device */* B/ l) |. P! V3 W
  464.         Send_Byte(0x80);                /* send DBSY command */
    9 R. P+ z2 c7 \3 e) C$ S' C
  465.         CE_High();                                /* disable device */+ q" _1 l- N+ A' q
  466. }5 M  \/ B; T! c; J  r+ d8 K7 e: W

  467. 5 I3 @" x1 j% ]) K6 \. V
  468. /************************************************************************/
    5 H3 C& H2 K% H6 k8 \9 R
  469. /* PROCEDURE: Read_ID                                                                                                        */
    ' I3 Z# @0 X) S/ P1 L$ J3 O
  470. /*                                                                                                                                                */
    9 f7 w" D$ j4 I% ?2 L
  471. /* This procedure Reads the manufacturer's ID and device ID.  It will         */: ?. v2 e! i/ l4 }
  472. /* use 90h or ABh as the command to read the ID (90h in this sample).   */
    + E2 h8 f' p; z
  473. /* It is up to the user to give the last byte ID_addr to determine      */
    8 t% A: p6 ]3 ?* L
  474. /* whether the device outputs manufacturer's ID first, or device ID         */
    0 [: h, ^" m& k- n
  475. /* first.  Please see the product datasheet for details.  Returns ID in */, g5 C7 K( Y+ w6 I- G# ~
  476. /* variable byte.                                                                                                                */3 O  A1 U% i, \4 k
  477. /*                                                                                                                                                */) E$ o. W1 J+ F" j7 Z6 ~1 ^
  478. /* Input:                                                                                                                                */! |9 d# D* @1 v) B, p. ?( u2 u1 x
  479. /*                ID_addr                                                                                                                        */
    ! A9 m- b, [9 l6 ^$ C+ R
  480. /*                                                                                                                                                */
    3 Q  K2 v4 A& o2 C, \# \! k( |
  481. /* Returns:                                                                                                                                */
    # ]' O& f& P, C# p! j
  482. /*                byte:        ID1(Manufacture's ID = BFh or Device ID = 8Eh)                        */( |8 i) u6 n) _
  483. /*                                                                                                                                                */
    / _- y3 s/ X; `! w
  484. /************************************************************************/) V! r& A) G0 n
  485. unsigned char Read_ID(ID_addr)
    " e3 z; r2 D# M3 s. D) ]" h4 _. ?
  486. {
      H3 J# @9 i2 U; d# d, g7 I
  487.         unsigned char byte;2 v" h, ^) T1 W  K
  488.         CE_Low();                                /* enable device */6 D  r6 s0 g% {
  489.         Send_Byte(0x90);                /* send read ID command (90h or ABh) */2 c% x- U+ t% ~4 m8 |2 u
  490.     Send_Byte(0x00);                /* send address */6 l1 o; b' h9 x- f0 [" \" ^  ~
  491.         Send_Byte(0x00);                /* send address */" l7 R: [+ P+ L
  492.         Send_Byte(ID_addr);                /* send address - either 00H or 01H */
    2 s& p" t" p+ V
  493.         byte = Get_Byte();                /* receive byte */
    : J& O9 n( ^/ m# O8 R% C8 h+ k& ^
  494.         CE_High();                                /* disable device */
    ' G" U5 p* g8 V
  495.         return byte;: Y5 r$ U- F: _* l$ s' u3 H! A
  496. }
    ' k5 B' u- M! e: K$ T" _
  497. % Y2 n5 [, B+ o8 b' }" [2 k
  498. /************************************************************************/
    " g, f0 s4 s- s
  499. /* PROCEDURE: Jedec_ID_Read                                                                                                */
    8 L: k/ t' M6 s( N9 n; k, j; b# t
  500. /*                                                                                                                                                */
    ( o! v  E' T) ?
  501. /* This procedure Reads the manufacturer's ID (BFh), memory type (25h)  */9 V+ G+ {4 x' J/ W; q; p9 _
  502. /* and device ID (8Eh).  It will use 9Fh as the JEDEC ID command.            */
    9 Z4 I$ g; b5 Z, a6 d6 z
  503. /* Please see the product datasheet for details.                                                  */, r: q1 j( P4 \9 ?( G
  504. /*                                                                                                                                                */8 ?" `" J# l4 @( j
  505. /* Input:                                                                                                                                */( [! l; a; `6 [& |: r
  506. /*                None                                                                                                                        */! ^( M* d5 y& ^
  507. /*                                                                                                                                                */4 _' i) l! Z. _% K$ U
  508. /* Returns:                                                                                                                                */
      |; s5 K1 Q  ^  P- i) |
  509. /*                IDs_Read:ID1(Manufacture's ID = BFh, Memory Type (25h),                        */
    * R8 Z- L! J8 T( A% }  a, ?
  510. /*                 and Device ID (8Eh)                                                                                        */$ p) m/ S) M3 }8 S% n* v  D
  511. /*                                                                                                                                                */. L+ W$ B8 a  W9 N) q/ T
  512. /************************************************************************/
      D! b0 @; c+ r! ?, j7 Z, G4 z
  513. unsigned long Jedec_ID_Read()
    + v* J/ ~) ]* n1 Y
  514. {
    + x4 [  Y1 k% A- K1 `9 T
  515.         unsigned long temp;- o) F: M% G4 p0 D1 w6 [* Y9 _+ h+ P
  516.        
    % {/ D* M8 a6 _' Q
  517.         temp = 0;% q$ `" U3 {7 ?5 g' Z& [( }
  518. 0 m6 |( V7 e2 u. U  A' I
  519.         CE_Low();                                        /* enable device */0 I! r3 n/ ]# |" B2 ~! x3 C
  520.         Send_Byte(0x9F);                        /* send JEDEC ID command (9Fh) */
    9 W1 I$ {" A8 k8 M. Q; b
  521.     temp = (temp | Get_Byte()) << 8;        /* receive byte */
    # b) P: n: k2 X4 L# b
  522.         temp = (temp | Get_Byte()) << 8;        ' @' l1 P, K% ^* u8 S8 G* F
  523.         temp = (temp | Get_Byte());                 /* temp value = 0xBF258E */+ `$ k+ @+ [9 H3 r, s
  524.         CE_High();                                                        /* disable device */
    7 `! b, V$ r% z+ P
  525. $ o$ d( l6 y! D9 |" S' j
  526.         return temp;
    5 a7 ^7 W. v" v8 Y6 \0 N" u7 U
  527. }# C8 Z& h/ M# u. f2 _2 S7 V" j

  528. 4 |2 y. s& N7 J/ b. Z
  529. /************************************************************************/8 ?  a' k+ s. S% S! x! e( j0 {7 Y
  530. /* PROCEDURE:        Read                                                                                                        */, u- \8 w: Y6 k! U6 R6 T& v
  531. /*                                                                                                                                                */               
    " ?7 G$ A* H" x& o- V: a
  532. /* This procedure reads one address of the device.  It will return the         */
    & W" h4 z: T* ]$ }5 C, a
  533. /* byte read in variable byte.                                                                                        */
    7 ?; e* B6 n; |0 _% Z% O& J
  534. /*                                                                                                                                                */
      C8 e  S' `# ~
  535. /*                                                                                                                                                *// [% j) u9 y+ x' `
  536. /*                                                                                                                                                */
    / |' a. H# D# t/ V7 G  i
  537. /* Input:                                                                                                                                */' h, M9 |0 a0 o# Y
  538. /*                Dst:        Destination Address 000000H - 0FFFFFH                                        */
    ( E* z' }% E; ^! C, c4 z
  539. /*                                                                                                                                      */
    0 J8 n  v/ i; D4 @1 t
  540. /*                                                                                                                                                */) ^# w9 U9 t! T% G0 p
  541. /* Returns:                                                                                                                                */% {6 k5 J7 a0 X# R1 F
  542. /*                byte                                                                                                                        */
    5 c/ f- Y: Y: `5 P
  543. /*                                                                                                                                                */
    ! O/ J: f9 c- r* B
  544. /************************************************************************/8 s) ^* ^# o* D6 q3 h, ?
  545. unsigned char Read(unsigned long Dst) 0 Q. L0 a$ f. N" R" ]0 K: k
  546. {
    , u: ^; {1 X. W0 c0 z
  547.         unsigned char byte = 0;       
    ! L/ _! m# v1 `$ g+ A

  548. $ q9 K# B* o/ Q: Q. m
  549.         CE_Low();                                /* enable device */# `6 ?) e9 t# s; |* E' @+ w
  550.         Send_Byte(0x03);                 /* read command */* l6 r4 N  K* L& u+ r$ U
  551.         Send_Byte(((Dst & 0xFFFFFF) >> 16));        /* send 3 address bytes *// i8 k9 R: }2 u; D! Q% W
  552.         Send_Byte(((Dst & 0xFFFF) >> 8));0 q; M3 s1 W1 `* {" o
  553.         Send_Byte(Dst & 0xFF);7 ?$ v# R  [5 G% s5 g# i
  554.         byte = Get_Byte();- X  s+ o; _* K5 _3 b8 N
  555.         CE_High();                                /* disable device */8 L5 ?  o, I5 l' \4 W  k  o& T1 d
  556.         return byte;                        /* return one byte read */5 v! n1 f, D1 m2 D) F! x
  557. }1 O  E# |) O. t  y7 K; N0 ]
  558. + _1 g) Y* r  d0 S; W$ X
  559. /************************************************************************/9 G7 Q& {8 X$ A  J
  560. /* PROCEDURE:        Read_Cont                                                                                                */1 Z8 y0 ^, ~2 o, q
  561. /*                                                                                                                                                */                " ]0 E& j( A6 j3 ~% J2 F' E" w+ v/ m
  562. /* This procedure reads multiple addresses of the device and stores                */
    8 S! L- O7 c6 v/ f" a+ C' ?9 U
  563. /* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*/
      t3 t: {9 y9 U1 a- L# s  N
  564. /*                                                                                                                                                */# R) c) p1 |3 @% E  P% x( S
  565. /* Input:                                                                                                                                */
    , P' l8 W- S% e2 c
  566. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */7 w- G5 z+ |- i# ^
  567. /*      no_bytes        Number of bytes to read        (max = 128)                                        */
    # G3 `( z/ r0 E; k  d5 C, ^
  568. /*                                                                                                                                                */
    3 l) r/ }8 l: U9 |: C
  569. /* Returns:                                                                                                                                */
    7 `: C3 i, r; I# C. J; O. L, U8 X
  570. /*                Nothing                                                                                                                        */
    : \, {/ Z% b$ X5 A& x& V/ T
  571. /*                                                                                                                                                */
    6 M# c* W) Z+ U& e( ?. q
  572. /************************************************************************/
    . y6 z. a5 N% {7 J; d  X
  573. void Read_Cont(unsigned long Dst, unsigned long no_bytes)
    1 [# [/ S5 y  w
  574. {9 k" L% L! R4 ~6 o
  575.         unsigned long i = 0;
    . S9 b) X& ]2 n" |1 S
  576.         CE_Low();                                        /* enable device */
    # f8 C7 b% K: v8 v
  577.         Send_Byte(0x03);                         /* read command */
    / T0 J( K! V& d7 b+ A; K* T+ \
  578.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */
    % o# S' H# \8 u4 b3 D. j) Y
  579.         Send_Byte(((Dst & 0xFFFF) >> 8));: m8 E3 Y4 e# h0 T2 B
  580.         Send_Byte(Dst & 0xFF);
    3 h9 j2 ?" R/ J
  581.         for (i = 0; i < no_bytes; i++)                /* read until no_bytes is reached */
    ' V" i; a9 l8 v1 a
  582.         {8 J/ `  \6 ~; C, s8 q
  583.                 upper_128[i] = Get_Byte();        /* receive byte and store at address 80H - FFH */
    6 M* e0 N6 x$ m1 t0 {
  584.         }
    $ B: E7 |; _3 F5 ^6 G
  585.         CE_High();                                        /* disable device */
    + a$ G3 \0 \5 ]! _: w& a

  586. 2 ?. B0 b' L7 r8 @% r3 I) J
  587. }
    ' I( `: I# `! X0 c% t$ L
  588. ; F/ O1 N& f" p( H# G: s1 e
  589. /************************************************************************/6 V+ y/ g5 Y# U1 Y+ m2 V
  590. /* PROCEDURE:        HighSpeed_Read                                                                                        */$ }2 a" c% K# f! l
  591. /*                                                                                                                                                */                + x. l: v+ r7 }0 r' `- Z
  592. /* This procedure reads one address of the device.  It will return the         */) {9 k. L/ _$ Y' K! a
  593. /* byte read in variable byte.                                                                                        */; z; Z" F) h. k: d
  594. /*                                                                                                                                                */& m: h. N) C* J* U; f7 ^# l- l
  595. /*                                                                                                                                                */
    7 B" H, F+ R, L- S% k: l1 y9 I1 Q$ P
  596. /*                                                                                                                                                */4 a0 M$ ?9 t$ _3 ^+ N% y" O1 k
  597. /* Input:                                                                                                                                */
    6 e- D- I( `5 c1 q5 m$ Y1 y
  598. /*                Dst:        Destination Address 000000H - 0FFFFFH                                        */
      f( Y" }* n: Y" E! O* W4 W* _1 R
  599. /*                                                                                                                                      */
    + O; y% v/ g+ T& {6 Z
  600. /*                                                                                                                                                */
    2 M1 j5 j$ j6 U
  601. /* Returns:                                                                                                                                */
    ( f0 [: f- x, s) o5 P  I! \
  602. /*                byte                                                                                                                        */
    ! o- {3 j' t4 p. c
  603. /*                                                                                                                                                */2 l2 t; N" }5 t" z- F! q# a
  604. /************************************************************************/: j" @  o4 I3 L& _
  605. unsigned char HighSpeed_Read(unsigned long Dst) ' J) V' E; F' t- L  ?9 l! x! l
  606. {
    9 ~9 K* `3 Q& ?7 H
  607.         unsigned char byte = 0;        9 @% }; I1 e+ u
  608. 0 g8 C8 A4 X1 M
  609.         CE_Low();                                /* enable device */9 o+ m7 {: N4 |7 R
  610.         Send_Byte(0x0B);                 /* read command */4 S: I! W( S, X" \- O1 Z+ T1 V  \7 M
  611.         Send_Byte(((Dst & 0xFFFFFF) >> 16));        /* send 3 address bytes */) B; D( N9 \4 |2 @
  612.         Send_Byte(((Dst & 0xFFFF) >> 8));
    + X! a+ z$ i4 P- X; b& o
  613.         Send_Byte(Dst & 0xFF);5 H; |6 A0 W; D6 r% ]
  614.         Send_Byte(0xFF);                /*dummy byte*/( Q/ }* W$ F% n( j
  615.         byte = Get_Byte();# s. L9 h7 w7 K+ q; B) u
  616.         CE_High();                                /* disable device */  ]- q( S9 {5 c
  617.         return byte;                        /* return one byte read */- z0 i9 ~9 [6 k
  618. }
    " _, O; W, I4 X. }: l  A$ N8 N6 [

  619. / B9 c4 J: q7 n" R% I$ j: Q
  620. /************************************************************************/& g* T' _- ]. R5 `  Z" l) {
  621. /* PROCEDURE:        HighSpeed_Read_Cont                                                                                */# U; ^  U; Y' o$ |. t0 D/ F$ |2 f
  622. /*                                                                                                                                                */               
    2 P& v0 Q" ?/ @5 D1 a" ~
  623. /* This procedure reads multiple addresses of the device and stores                */
    1 ^# p+ O& {# s* j, M' M; f
  624. /* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*/0 v& g+ c2 Q5 {3 c! d
  625. /*                                                                                                                                                */
    2 S5 d/ X2 o* x( d( G
  626. /* Input:                                                                                                                                */
    ( r' a0 c( g& @
  627. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */  h* @6 v0 @/ I/ o- O6 E
  628. /*      no_bytes        Number of bytes to read        (max = 128)                                        */$ |% G2 u7 I. ^$ K
  629. /*                                                                                                                                                */% |1 v4 E8 \+ O, A4 k
  630. /* Returns:                                                                                                                                */
    ' C! N# \8 G1 x* y2 D7 ]9 D( |$ q! F
  631. /*                Nothing                                                                                                                        */# d2 p  R& {# a
  632. /*                                                                                                                                                */' h3 L* Y" K) ?+ Y
  633. /************************************************************************/+ Q* f- x/ U' G- d2 I/ E! U7 A
  634. void HighSpeed_Read_Cont(unsigned long Dst, unsigned long no_bytes)
    0 u( {& t3 {/ ]" x4 S" C3 x
  635. {1 `6 `7 n. N5 p- d9 J; \( R) C% ~
  636.         unsigned long i = 0;$ i1 i* S5 \$ G8 [* M
  637.         CE_Low();                                        /* enable device */2 c; v8 T( c/ O$ q2 R% g
  638.         Send_Byte(0x0B);                         /* read command */4 L# w9 x7 Q& D, q0 G; H' I1 w& i; O
  639.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */: S% S3 x0 p) n4 g* k" O! n
  640.         Send_Byte(((Dst & 0xFFFF) >> 8));; M& A5 w: f% X5 p* p
  641.         Send_Byte(Dst & 0xFF);
    4 q6 t4 e8 k  ^9 n
  642.         Send_Byte(0xFF);                        /*dummy byte*/
    9 K) r( g3 m! _% b
  643.         for (i = 0; i < no_bytes; i++)                /* read until no_bytes is reached */
    # V, x! N4 m) v: H+ L1 g' i
  644.         {% E4 a% Z% Y- w* H$ |# X6 q: F$ o. u% `
  645.                 upper_128[i] = Get_Byte();        /* receive byte and store at address 80H - FFH */
    4 d8 l) s/ \) A% x6 ?
  646.         }
    6 H! R/ k8 D  p0 v
  647.         CE_High();                                /* disable device */4 t1 ^+ Z2 N& C/ j8 S, A" P
  648. }; Q! g5 D; B' U' Q0 M( o! Q) Q

  649. : b- H" |: t& s
  650. /************************************************************************/+ Z  b/ N# E/ X+ k/ J% F
  651. /* PROCEDURE:        Byte_Program                                                                                        */, e/ `  P! Q, ^# M* a
  652. /*                                                                                                                                                */
    ( I& s; o. K: P7 Z, C
  653. /* This procedure programs one address of the device.                                        */. F: Q0 U$ M+ D6 x
  654. /* Assumption:  Address being programmed is already erased and is NOT        */3 o0 J" E/ g: {9 m
  655. /* block protected.                                                                                                                */6 z4 t6 v5 O- ^$ r% q% ^+ c
  656. /*                                                                                                                                                */
    + Q7 x8 e1 y& E) K1 u. F- @* m
  657. /*                                                                                                                                                */
    $ N, G0 B' [4 ?' V+ e
  658. /*                                                                                                                                                */8 y. |. Y) R5 E; e. r# Q) M
  659. /* Input:                                                                                                                                */+ W* Y+ h7 w' S* m- ~) c
  660. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */9 [* O, o( L) V9 l+ G: |
  661. /*                byte:                byte to be programmed                                                                */2 y/ {$ F* ?. H( ~- G+ C* U) g2 T8 ?
  662. /*                                                                                                                                      */
    0 O  c8 b  u  w  L% }6 d0 v! Z, U
  663. /*                                                                                                                                                */! T" |8 C% L6 @4 Q
  664. /* Returns:                                                                                                                                */
    & p$ _/ H, U0 s" ]% c2 L) h7 w
  665. /*                Nothing                                                                                                                        */
    * T3 [3 ^, O" L8 }9 [7 g
  666. /*                                                                                                                                                */+ c9 f2 P! |5 \2 r
  667. /************************************************************************/
    ( `7 F. h" k# @8 I  Q
  668. void Byte_Program(unsigned long Dst, unsigned char byte)
    & s( `1 b0 H% i% e$ B
  669. {
    7 r/ Q8 |# @1 `9 N& h& B% _3 z
  670.         CE_Low();                                        /* enable device */# }  ?2 x& b- |  c' {' N# s4 b
  671.         Send_Byte(0x02);                         /* send Byte Program command */
    4 P! ^$ P0 O( G: N. @" h
  672.         Send_Byte(((Dst & 0xFFFFFF) >> 16));        /* send 3 address bytes */
    + z2 }0 P( a  V9 @8 ]% L8 K
  673.         Send_Byte(((Dst & 0xFFFF) >> 8));) @+ K! z. H: {
  674.         Send_Byte(Dst & 0xFF);
    7 `( {: h7 ]1 S4 w1 R4 K. Y
  675.         Send_Byte(byte);                        /* send byte to be programmed */$ x6 k- ]5 ?- r+ `2 K% R8 D
  676.         CE_High();                                        /* disable device */# f7 P5 p; A( d" H# j
  677. }. e# Y* d* m; Q

  678. / ~. Q, n9 k) ^7 Y5 ]0 Q& h) b* G
  679. /************************************************************************/
    / W* g2 }1 J, Y! V* I/ x
  680. /* PROCEDURE:        Auto_Add_IncA                                                                                        */. y" Z2 M/ Z4 h) B2 p3 L
  681. /*                                                                                                                                                */& ?  H3 z8 G8 D0 S
  682. /* This procedure programs consecutive addresses of 2 bytes of data into*/4 l2 ?; w# [2 q, H2 D3 H
  683. /* the device:  1st data byte will be programmed into the initial                 */
    ( O) w2 Z3 S3 p1 ~
  684. /* address [A23-A1] and with A0 = 0.  The 2nd data byte will be be                 */; [; }" D, M  ^
  685. /* programmed into initial address [A23-A1] and with A0  = 1.  This          */
      C7 v0 B1 t* _# `0 y
  686. /* is used to to start the AAI process.  It should be followed by                 */3 `: d# I4 v. l( f8 a
  687. /* Auto_Add_IncB.                                                                                                                */5 x/ x% B" X6 ]1 E) S0 g! O
  688. /* Assumption:  Address being programmed is already erased and is NOT        *// H% ]: K/ y4 z9 o6 R  F
  689. /*                                block protected.                                                                                */
    ; i- @7 T* I- F$ o
  690. /*                                                                                                                                                */
    / e& R8 I' m- g
  691. /*                                                                                                                                                */% D& [6 V# s& b% c; ]
  692. /* Note: Only RDSR command can be executed once in AAI mode with SO          */
    + y/ R( E* ~4 L
  693. /*          disable to output RY/BY# status.  Use WRDI to exit AAI mode                 */$ `0 X0 E2 D" L
  694. /*         unless AAI is programming the last address or last address of                */2 p3 a9 T* v2 f8 S9 g. W; N! A! Y
  695. /*          unprotected block, which automatically exits AAI mode.                                */- D6 }% K" ^' t
  696. /*                                                                                                                                                */
    8 G: d/ m+ f3 W/ [0 ~! e: T
  697. /* Input:                                                                                                                                */
      M- c* X  M. R5 e  u
  698. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */8 L* Z& p( J8 i% ^* h6 p% v( N/ ?* O
  699. /*                byte1:                1st byte to be programmed                                                        */" ]. f0 m8 d5 E* z# G" o. l
  700. /*      byte1:                2nd byte to be programmed                                                        */) O( `% v" q) i; R
  701. /*                                                                                                                                                */: M3 ~' \* f4 A) W. G- f7 J6 {
  702. /* Returns:                                                                                                                                */) Y3 X7 K# u# I8 L' b# S/ h; B( m
  703. /*                Nothing                                                                                                                        */2 q8 z9 `! }3 k6 y6 t$ h9 y
  704. /*                                                                                                                                                */8 \2 [" @" [4 y
  705. /************************************************************************/
    ; Y4 ]8 s8 ^  y$ y0 e$ ^
  706. void Auto_Add_IncA(unsigned long Dst, unsigned char byte1, unsigned char byte2)
    ' Z. v# d9 R% ^) F' \" d' c4 {
  707. {
    * |+ Q9 a* Y) `
  708.         CE_Low();                                        /* enable device */
    , w  q" o* S" K5 Q  W* W& r1 s3 A
  709.         Send_Byte(0xAD);                        /* send AAI command */
    % `0 d3 n& r0 V+ g6 }- k; W
  710.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */& n! u6 o  Y5 ]/ g( \3 T
  711.         Send_Byte(((Dst & 0xFFFF) >> 8));
    5 s& L6 S8 M9 U" P
  712.         Send_Byte(Dst & 0xFF);3 F$ `' y4 p  Z0 i# y
  713.         Send_Byte(byte1);                        /* send 1st byte to be programmed */       
    # d7 D) {, g1 S% L, p* _5 P
  714.         Send_Byte(byte2);                        /* send 2nd byte to be programmed */
    4 |, _" q. x0 ?0 f+ M5 a7 d
  715.         CE_High();                                        /* disable device */; Q2 R, x; y. g
  716. }  F) q5 z7 p5 p9 I9 g5 ~1 ^2 s

  717. 5 P' w0 O- \, x% o$ l7 h: t+ |
  718. /************************************************************************/: X# T" r$ g! j  ~
  719. /* PROCEDURE:        Auto_Add_IncB                                                                                        *// {7 z3 R3 _; {$ V: w/ a& d. A
  720. /*                                                                                                                                                */
    & a1 w: e) c& l) Q3 a$ H8 @( _% |
  721. /* This procedure programs consecutive addresses of 2 bytes of data into*/' ^3 @7 Q9 [* y) O- O% a
  722. /* the device:  1st data byte will be programmed into the initial                 */
    - g6 |1 Z0 M) b5 M; u/ r* M4 R& R
  723. /* address [A23-A1] and with A0 = 0.  The 2nd data byte will be be                 */
    & q/ V8 L" \  |  s
  724. /* programmed into initial address [A23-A1] and with A0  = 1.    This          */3 z/ j7 R, u- l: ~' i! Q; N
  725. /* is used after Auto_Address_IncA.                                                                                */% h- @! E. ^0 m$ b6 E4 U
  726. /* Assumption:  Address being programmed is already erased and is NOT        */
    3 r  c% j% H" C6 U7 F( ]1 u
  727. /*                                block protected.                                                                                */1 }, F  H9 ?" k% x6 p5 I, C
  728. /*                                                                                                                                                */3 ~7 A# [% y0 [6 k
  729. /* Note: Only WRDI and AAI command can be executed once in AAI mode         */
    1 U6 T% A% |0 `1 B
  730. /*         with SO enabled as RY/BY# status.  When the device is busy                 */
    ) H' L: \8 ~+ i! b
  731. /*         asserting CE# will output the status of RY/BY# on SO.  Use WRDI        */, T1 ?* P' D( f6 j
  732. /*          to exit AAI mode unless AAI is programming the last address or                */7 {) b* A0 |8 V  x
  733. /*         last address of unprotected block, which automatically exits                 */
    ( T% c0 I4 V9 r9 u# M0 c- U
  734. /*         AAI mode.                                                                                                                        */8 a2 a' W7 w1 n8 d5 @- i
  735. /*                                                                                                                                                */: O2 I4 J! Z0 g( s
  736. /* Input:                                                                                                                                */+ Q) A' D( R' S7 D4 J- {2 L  w
  737. /*                                                                                                                                                */
    5 s4 |% J( X: _; I
  738. /*                byte1:                1st byte to be programmed                                                        */% s* f4 T, L* z4 N, H
  739. /*                byte2:                2nd byte to be programmed                                                        */3 e* J6 r, }5 G5 H. ], q/ V5 b, M
  740. /*                                                                                                                                      */, l8 \: t+ Z3 c0 p) H! K" Q  l* @
  741. /*                                                                                                                                                */$ m, j% `+ {# _, z8 X
  742. /* Returns:                                                                                                                                */
    1 a; k: ~7 V* C
  743. /*                Nothing                                                                                                                        */
    ; Y# z* |% C2 M. i
  744. /*                                                                                                                                                */
    ; a& m6 {" ?. b& v) d$ R
  745. /************************************************************************/" i" l* }1 i4 r! B& y8 n- J
  746. void Auto_Add_IncB(unsigned char byte1, unsigned char byte2)
    9 n. W! G# u1 T
  747. {
    2 T6 T) n7 B* d. @# X' ^/ s1 E
  748.         CE_Low();                                        /* enable device */
    4 D( Z- J9 n% p1 c0 Y+ y9 P' F
  749.         Send_Byte(0xAD);                        /* send AAI command */
    4 q6 _% V/ f" |8 y+ \1 g' y+ t
  750.         Send_Byte(byte1);                        /* send 1st byte to be programmed */5 N0 [8 X1 n4 @* J( K% g
  751.         Send_Byte(byte2);                        /* send 2nd byte to be programmed */
    % P( E* r) P. B( B
  752.         CE_High();                                        /* disable device */4 o5 C' C8 _  Y" B* T6 Z$ o
  753. }7 ?2 _( K% {- A1 f$ B1 z

  754.   e7 p3 g: K/ U
  755. /************************************************************************/
    0 f% i/ e, k5 D% E: ?+ Y
  756. /* PROCEDURE:        Auto_Add_IncA_EBSY                                                                                */
    0 c; E! M* G+ A1 H- C2 Z
  757. /*                                                                                                                                                */
    5 ^; T. J7 Y1 z$ \
  758. /* This procedure is the same as procedure Auto_Add_IncA except that it */
    2 a6 N' M2 b2 K" Y: _7 a
  759. /* uses EBSY and Poll_SO functions to check for RY/BY. It programs                 */4 @! t( f/ y) e8 u. R# Y, x: w9 {' n
  760. /* consecutive addresses of the device.  The 1st data byte will be                 */
    0 K9 Y6 v( O* v( e( \; j7 z* g
  761. /* programmed into the initial address [A23-A1] and with A0 = 0.  The         */
    4 d) {7 c8 X. C( E0 O( @+ Z5 V& I7 j
  762. /* 2nd data byte will be programmed into initial address [A23-A1] and         */
    " Q5 ^8 j2 R/ Q. L' M
  763. /* with A0  = 1.  This is used to to start the AAI process.  It should  */
    ( J! W. r% h) m# ~! f
  764. /* be followed by Auto_Add_IncB_EBSY.                                                                        */
    " L( `. x4 a! u' b* }/ h2 I
  765. /* Assumption:  Address being programmed is already erased and is NOT        */
    3 W+ s" K2 Q% T. T
  766. /*                                block protected.                                                                                */
    " C0 }; s: q; Y" R6 N
  767. /*                                                                                                                                                */
    3 J7 j; z5 P) Q" B) b$ _+ l
  768. /*                                                                                                                                                */5 l/ \# N& k& d5 x/ r4 j; M8 N
  769. /* Note: Only WRDI and AAI command can be executed once in AAI mode         */
    9 g9 `% D& g2 n  s
  770. /*         with SO enabled as RY/BY# status.  When the device is busy                 */6 L& g6 Y9 k! g0 @
  771. /*         asserting CE# will output the status of RY/BY# on SO.  Use WRDI        *// a8 q  e3 O9 A( S# h; ?
  772. /*          to exit AAI mode unless AAI is programming the last address or                */
      f0 a& O( }8 C# Y; n8 D
  773. /*         last address of unprotected block, which automatically exits                 */+ ?! d: Y! V0 t0 f5 o  a/ p
  774. /*         AAI mode.                                                                                                                        */  _& x# O, X# m5 q6 W! W" W
  775. /*                                                                                                                                                */! w5 d, b  A) N) N2 K# ^5 l
  776. /* Input:                                                                                                                                */) O0 J, |% A9 H5 R; A
  777. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */
    ' @7 w+ q  a3 E  |3 W) i: k/ Y
  778. /*                byte1:                1st byte to be programmed                                                        */5 y# `$ s3 }6 G9 b
  779. /*      byte1:                2nd byte to be programmed                                                        */  z& p( a% |$ W0 B4 U) x
  780. /*                                                                                                                                                */3 o0 e2 k1 ?$ d" x7 Q8 ~
  781. /* Returns:                                                                                                                                */
    ( `# D+ V0 L+ f: Z
  782. /*                Nothing                                                                                                                        */7 m2 m# _/ Z, H# u4 R  V* d
  783. /*                                                                                                                                                */
    4 H9 [1 b3 `, k4 V2 Z
  784. /************************************************************************/
      G: J0 m( k; |
  785. void Auto_Add_IncA_EBSY(unsigned long Dst, unsigned char byte1, unsigned char byte2)
      }* M1 \% V. H0 ~, p! e( e# v) ]
  786. {# g4 t, A( z  @$ d! W
  787.         EBSY();                                                /* enable RY/BY# status for SO in AAI */       
    6 C& m) V8 F6 i4 f$ ~+ ]/ ]' L; b  }

  788. # q' J: h" A- E: K& K% F
  789.         CE_Low();                                        /* enable device */( Q  r) [% D8 X
  790.         Send_Byte(0xAD);                        /* send AAI command */' M" \4 N7 A/ ~% L$ U
  791.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */
    8 t" u( W( j1 m
  792.         Send_Byte(((Dst & 0xFFFF) >> 8));8 S7 ?0 w  Z: p6 A* e
  793.         Send_Byte(Dst & 0xFF);
    & R& h7 a0 Q0 I. m
  794.         Send_Byte(byte1);                        /* send 1st byte to be programmed */       
    + \2 [% d) E! V3 u, o8 j( s2 Q+ `' z4 j
  795.         Send_Byte(byte2);                        /* send 2nd byte to be programmed */. K# f& p. C3 s  t5 ~* ?
  796.         CE_High();                                        /* disable device */
    / Y+ n' V0 t) z* O$ \7 [
  797.        
    $ g+ \; K* L, ]) B6 F. V7 Z# s
  798.         Poll_SO();                                        /* polls RY/BY# using SO line */
    / z: w" e$ @9 r5 O3 a
  799. , \, `) ?. b5 ]; W
  800. }' b3 S2 G4 b: C$ F" ~& _. b3 y

  801. $ A+ ~. v" H% n4 J6 s
  802. /************************************************************************/
    & k- X# _7 z1 U5 z1 j' g
  803. /* PROCEDURE:        Auto_Add_IncB_EBSY                                                                                */8 }  `/ U8 h0 v9 Q2 u, o0 F7 e
  804. /*                                                                                                                                                */9 t. j9 i  ]( f2 c7 W1 F
  805. /* This procedure is the same as Auto_Add_IncB except that it uses                 */! T# I1 q" X9 H* C* d" N- E0 m
  806. /* Poll_SO to poll for RY/BY#.  It demonstrate on how to use DBSY after        */
    9 u0 B- p! H  q  y' W  ~' T
  807. /* AAI programmming is completed.  It programs consecutive addresses of */
    % _+ b2 e9 H- A6 f& U* G! Y
  808. /* the device.  The 1st data byte will be programmed into the initial   */
    # ^' t  @) a" l7 t; P& l" l
  809. /* address [A23-A1] and with A0 = 0.  The 2nd data byte will be                        */
    3 g9 V& O5 u8 H: t7 h8 K3 ]7 s9 M
  810. /* programmed into initial address [A23-A1] and with A0  = 1.  This is         */: m$ B! E4 g; G1 ?+ o9 Z: V- t
  811. /* used after Auto_Address_IncA.                                                                                */
    & A" O" }8 `# y5 l; B/ M5 y2 V
  812. /* Assumption:  Address being programmed is already erased and is NOT        */
    8 X. ~8 ?$ u+ R1 X
  813. /*                                block protected.                                                                                */6 P2 J+ _- F* D7 f; R+ L: x" H& ^
  814. /*                                                                                                                                                */8 {: l8 U5 g# m" H+ Q, |$ M
  815. /* Note: Only WRDI and AAI command can be executed once in AAI mode         */
    8 p7 F, [& Y* A# M6 d' Y
  816. /*         with SO enabled as RY/BY# status.  When the device is busy,                 */
      [  W) H% @; B% U0 t% v
  817. /*         asserting CE# will output the status of RY/BY# on SO.  Use WRDI        */6 F8 ^1 A- P$ _. k: c4 M- k9 G& g
  818. /*          to exit AAI mode unless AAI is programming the last address or                */2 G. Y. S+ D; P* {8 C
  819. /*         last address of unprotected block, which automatically exits                 */
    + U* I9 N1 P) z/ W( k* |
  820. /*         AAI mode.                                                                                                                        */- r; U" I4 o+ u/ F9 F7 U
  821. /*                                                                                                                                                */
    4 r* h3 m0 j9 x2 L: u' w
  822. /* Input:                                                                                                                                */
    ( {+ U0 a" e) O3 H4 i/ h* S7 F
  823. /*                                                                                                                                                */: E2 |9 k# V& c5 t
  824. /*                byte1:                1st byte to be programmed                                                        */0 k2 n0 _% N2 k; g# ~$ U4 x
  825. /*                byte2:                2nd byte to be programmed                                                        */
    9 k5 V) B* V- H$ ]- `; V
  826. /*                                                                                                                                      */
    7 x( s" \# J- A; A5 v3 w
  827. /*                                                                                                                                                */
    7 o: B% g8 l) J1 w5 x: s+ M# p( S5 o
  828. /* Returns:                                                                                                                                */: i* T1 {3 f9 h. P! r
  829. /*                Nothing                                                                                                                        */: P# _1 x3 t2 \3 T3 `
  830. /*                                                                                                                                                */
    9 m9 ?/ H% R9 T. G5 o: J& R
  831. /************************************************************************/$ v* S$ Y& @" |/ }
  832. void Auto_Add_IncB_EBSY(unsigned char byte1, unsigned char byte2)
    7 `$ B7 P9 O9 ~
  833. {
    0 k9 I) M  d6 g) ~- l
  834.         CE_Low();                                /* enable device */8 U% i% J9 E. }$ v2 ^0 a9 m
  835.         Send_Byte(0xAD);                /* send AAI command */
    * }1 K& X+ h+ m8 i; A
  836.         Send_Byte(byte1);                /* send 1st byte to be programmed */
    - b8 B5 a& z; y2 S9 T
  837.         Send_Byte(byte2);                /* send 2nd byte to be programmed */" o3 R5 n0 A3 J) G7 @' G) |
  838.         CE_High();                                /* disable device */# \3 r: w, p2 e3 j! I( c3 N9 b
  839. ; o% L- r7 I- {0 v6 Q0 q- X) x
  840.         Poll_SO();                                /* polls RY/BY# using SO line */
    0 r+ V/ e+ k! b' c1 F! w
  841. / E/ ^/ n4 b1 I/ S. Q) R
  842.         WRDI();                                 /* Exit AAI before executing DBSY */
    ! q- }2 j$ V% `" K
  843.         DBSY();                                        /* disable SO as RY/BY# output if in AAI */% O- G$ V) y6 |
  844. }
    ; @' U+ A* ]2 n

  845. ! _3 w' u$ h* U
  846. /************************************************************************/: k% `% X( Z! D% y6 u" }
  847. /* PROCEDURE: Chip_Erase                                                                                                *// M+ c4 P) a" y2 w8 g
  848. /*                                                                                                                                                */$ s& a; Y/ {4 |7 z( v# u% Z! M
  849. /* This procedure erases the entire Chip.                                                                */
    ' t# o# G0 f. D6 W; D; M, g# Y
  850. /*                                                                                                                                                */
    6 e  L7 E6 h4 p( [3 ]
  851. /* Input:                                                                                                                                */# J% E, C7 K+ `# \
  852. /*                None                                                                                                                        */
    1 |$ D# B' U) Y0 u9 T
  853. /*                                                                                                                                                */
    + [+ X3 L* T- C# f1 s
  854. /* Returns:                                                                                                                                */- i* c# ^  g: `* v
  855. /*                Nothing                                                                                                                        */
    2 ?* O2 q% v# I7 P0 s" G# \4 r
  856. /************************************************************************/
    3 B8 H4 x& P' L
  857. void Chip_Erase()
    & n0 q$ P/ V( M% w" w
  858. {                                               
    8 p1 W7 ]2 W: E
  859.         CE_Low();                                /* enable device */
    1 Q8 d* `+ N" T1 @
  860.         Send_Byte(0x60);                /* send Chip Erase command (60h or C7h) */; t4 _, r- T+ v4 K
  861.         CE_High();                                /* disable device */
    & R3 v7 v/ u3 e& l5 H1 r
  862. }% g5 u% D# f  e) I( T
  863. * ~- S4 ]  C: o) t
  864. /************************************************************************// \! c* H" S1 k$ T: y% v& l' o' \
  865. /* PROCEDURE: Sector_Erase                                                                                                */
    3 f7 z5 r7 ~( n  a* d9 Q) R
  866. /*                                                                                                                                                */
    2 W4 [; E7 l" ~5 i" z/ ^
  867. /* This procedure Sector Erases the Chip.                                                                */0 h8 [/ I0 n! o3 w8 O' v. }
  868. /*                                                                                                                                                */, L$ a3 e% u9 R& S0 D
  869. /* Input:                                                                                                                                */- ^, O. E- |0 n. i6 u7 p
  870. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */7 l4 M' y0 a+ K' Y, p0 h
  871. /*                                                                                                                                                */
    & N, H6 r( O! L0 a1 f5 t
  872. /* Returns:                                                                                                                                */5 Q1 F; T7 P- z# o+ |- y. y4 L& U
  873. /*                Nothing                                                                                                                        */
    : |; ]4 U  j+ Z" S0 P0 M
  874. /************************************************************************/
    # h2 R! E! X2 J; p8 J9 z
  875. void Sector_Erase(unsigned long Dst)3 u: P. o) V2 n$ F* W& J
  876. {) J2 d/ O* n7 v  m+ `$ h

  877. 6 ]8 ?) Z- Y) d3 r

  878. 9 c( w% v7 N8 {. E1 S8 x& j* T' Q8 X* w
  879.         CE_Low();                                        /* enable device */2 y$ V' {/ _8 c- p
  880.         Send_Byte(0x20);                        /* send Sector Erase command */
    1 E5 R3 ^8 J9 I
  881.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */
    6 C$ |6 J8 b  j, w
  882.         Send_Byte(((Dst & 0xFFFF) >> 8));! Y5 f6 L- `/ Z) j9 t
  883.         Send_Byte(Dst & 0xFF);
    8 ^; Q2 u+ m* f  a+ s
  884.         CE_High();                                        /* disable device */0 G( m& d6 y7 X, M' Y6 w+ f
  885. }        * ?# A2 h4 C- Z

  886. : G4 @* d6 Z" n* J2 n) x# \+ _* S* [  f
  887. /************************************************************************/- C: [" |$ c2 u( M
  888. /* PROCEDURE: Block_Erase_32K                                                                                        */
    7 {) Y; K7 F# U
  889. /*                                                                                                                                                */
    ; b7 e* B4 b* t9 W( S+ x, \+ X
  890. /* This procedure Block Erases 32 KByte of the Chip.                                        */
    - z' u; Y7 ^# r/ U3 _' u
  891. /*                                                                                                                                                */* D8 {! I, w% G9 n
  892. /* Input:                                                                                                                                */
    $ ?5 x( k0 ~2 j% A5 E
  893. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */% v; c: O, V* S5 ]6 a* F5 D
  894. /*                                                                                                                                                */
    4 V! i1 m. p$ F" W. t
  895. /* Returns:                                                                                                                                */
    + ~( M1 A! o8 r. K/ g/ G" A6 J. {
  896. /*                Nothing                                                                                                                        */
    $ A( P$ b( Q+ n  F
  897. /************************************************************************/( \5 k/ P, A3 I, P: C4 V* W+ q
  898. void Block_Erase_32K(unsigned long Dst)9 g% Q: f# O* H) [- i3 B
  899. {
    3 `* q. B4 L+ F! v& M
  900.         CE_Low();                                        /* enable device */
    . c5 {% ]5 `7 D0 b5 J7 _3 \
  901.         Send_Byte(0x52);                        /* send 32 KByte Block Erase command */9 _, _* j: ?- Y# `% x9 d, Y3 T; a
  902.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */+ L/ {. l3 D# X% Y" Y
  903.         Send_Byte(((Dst & 0xFFFF) >> 8));
      W6 U5 e- V+ _: \- K% @- k' {
  904.         Send_Byte(Dst & 0xFF);. c! a! a# R1 U6 D
  905.         CE_High();                                        /* disable device */
    ' ]3 U* M0 p# D8 `( r( c
  906. }
    8 P& F0 y; G6 }
  907.   y. J. V3 n3 [! W
  908. /************************************************************************/
    . B2 g: n; f4 d; E$ S
  909. /* PROCEDURE: Block_Erase_64K                                                                                        */
    , t0 n$ T. I8 X' Q  r" p! m: \
  910. /*                                                                                                                                                */
    5 Q8 e2 i; w! W* B5 N
  911. /* This procedure Block Erases 64 KByte of the Chip.                                        */
    4 W4 Q: j" O9 h
  912. /*                                                                                                                                                */
    - @9 N- C: o5 J) v+ h$ ]$ c
  913. /* Input:                                                                                                                                */" U) @1 \. H/ n$ m' B
  914. /*                Dst:                Destination Address 000000H - 0FFFFFH                                */
    / g/ v. M( I. h% r) x
  915. /*                                                                                                                                                */
    ' q% {3 \9 h' c% s
  916. /* Returns:                                                                                                                                */
    ' b  H0 z# W2 b
  917. /*                Nothing                                                                                                                        */
    + p( e& e9 H/ i5 i% ?
  918. /************************************************************************/
    : [8 @. R1 Q  h* ?
  919. void Block_Erase_64K(unsigned long Dst)
    : E/ d) R' q3 T, o* L7 c2 a, C+ v
  920. {
    ) B; ?) l' d  U+ w9 Z# T, }
  921.         CE_Low();                                        /* enable device */+ n( f2 b3 ?8 S. [
  922.         Send_Byte(0xD8);                        /* send 64KByte Block Erase command */- b) ^) }$ c0 U' O
  923.         Send_Byte(((Dst & 0xFFFFFF) >> 16));         /* send 3 address bytes */8 F4 }+ F- ?- G0 f# ?; J" q
  924.         Send_Byte(((Dst & 0xFFFF) >> 8));5 M0 |8 A1 }6 n! R
  925.         Send_Byte(Dst & 0xFF);
    : Q* \& H  {6 \7 Y' n( g: l
  926.         CE_High();                                        /* disable device */7 ^+ n5 r5 k" R" f! O/ K
  927. }
    / c# D4 ?$ o3 x  W3 \4 H. E8 C

  928. 8 N9 S* c+ J" v6 E
  929. /************************************************************************/
    9 g$ W2 Q; n! \- w0 @- @  q; _+ x
  930. /* PROCEDURE: Wait_Busy                                                                                                        */
    2 a# U2 b- `+ i
  931. /*                                                                                                                                                */
    ) _' V% |- M. _) {1 q
  932. /* This procedure waits until device is no longer busy (can be used by        */# E+ [9 ^$ |$ U" N) D
  933. /* Byte-Program, Sector-Erase, Block-Erase, Chip-Erase).                                */1 B- f; l# J7 e: \$ A: {8 x1 [
  934. /*                                                                                                                                                */
    6 W7 T; Y$ ~6 B5 e
  935. /* Input:                                                                                                                                */6 O  i' Q, _0 E% {, q
  936. /*                None                                                                                                                        */
    ' q& X" i2 P/ t* W4 w' I
  937. /*                                                                                                                                                */# ]' R) E+ s; A* S% a  ^5 B
  938. /* Returns:                                                                                                                                */
      r' h) b# a  y
  939. /*                Nothing                                                                                                                        */$ g# N. k  D5 C0 v6 _8 s- x
  940. /************************************************************************/
    7 B* V0 @7 D+ n" s- J& I" t3 P
  941. void Wait_Busy(); @; a! m0 t/ U, P
  942. {
    0 V. N- s2 D% V) c
  943.         while (Read_Status_Register() == 0x03)        /* waste time until not busy */* V2 a5 w4 F  ?( G
  944.                 Read_Status_Register();# R# W. f1 b2 N2 c6 B: ^5 f
  945. }
    . S5 r4 k# ]* \6 y: y$ Y% p: [

  946. % f! _7 T! U2 u3 C% @4 ^$ q( e, _3 C
  947. /************************************************************************/2 R: w( P5 p) b" _
  948. /* PROCEDURE: Wait_Busy_AAI                                                                                                */
    5 f4 v! j' Q3 ^/ T5 a
  949. /*                                                                                                                                                */
    * k% d3 V5 K% @! s
  950. /* This procedure waits until device is no longer busy for AAI mode.        */8 {  S) `+ |5 y6 t+ r* X" ~* {
  951. /*                                                                                                                                                */
    ! s5 I7 s1 J5 X+ S# ?
  952. /* Input:                                                                                                                                */
    + x" }4 f% a0 p
  953. /*                None                                                                                                                        */
    % w$ O* ~1 r$ Y0 _5 y* b5 C) ?
  954. /*                                                                                                                                                */# Y; j3 u0 }! F+ @
  955. /* Returns:                                                                                                                                */
    . t0 u3 [( Q% Y
  956. /*                Nothing                                                                                                                        */
    " p4 V9 z9 G! i8 R, x. c; t
  957. /************************************************************************/" u( j1 i1 Q  }- k) I
  958. void Wait_Busy_AAI()" |2 t+ i7 A2 i* W8 ]
  959. {
    8 r$ u9 `0 w5 X! `
  960.         while (Read_Status_Register() == 0x43)        /* waste time until not busy */( z6 P( ?, ]& N3 q# ]
  961.                 Read_Status_Register();+ ]$ @( j' `. J, \" B: v" e. T
  962. }
    0 A/ e* [! ], A$ v! Y9 ?! f; K" I
  963. ) Y; C7 k: P- a* `$ D1 r3 p
  964. /************************************************************************/; u% S' M; l5 V8 w4 @
  965. /* PROCEDURE: WREN_Check                                                                                                */  E1 S+ z5 i. a+ a- Z
  966. /*                                                                                                                                                */
    9 a3 ]0 m0 g0 m- @4 w
  967. /* This procedure checks to see if WEL bit set before program/erase.        */' C! y# T! v0 u+ _
  968. /*                                                                                                                                                */- Z8 }7 v! j- ~7 ^
  969. /* Input:                                                                                                                                */; K/ h$ q/ a5 P2 v' t% ~# ]9 S, i, ^
  970. /*                None                                                                                                                        */* n  ?+ q4 L# _; r
  971. /*                                                                                                                                                */" {* z0 v' T1 u* j6 q4 c
  972. /* Returns:                                                                                                                                */
    7 Z6 |8 ^( d3 E! c, @3 s0 Q
  973. /*                Nothing                                                                                                                        */; ~2 a/ s% W( u) M4 G
  974. /************************************************************************/
    6 ^" T3 E; t& o( m, _' _2 o
  975. void WREN_Check()$ e9 t* V4 z- p) {3 R0 Q" e1 y
  976. {; F6 W  A% A, u; h
  977.         unsigned char byte;1 T0 T8 P* e+ x
  978.         byte = Read_Status_Register();        /* read the status register */
    5 Z7 t( d$ _- C; p1 ^6 h$ g! m) r
  979.         if (byte != 0x02)                /* verify that WEL bit is set */7 W7 c+ o5 H# w
  980.         {
    * T& G5 k4 L5 A- ?1 G  m0 Z
  981.                 while(1)
    : t. ]0 L6 P7 ]1 T
  982.                         /* add source code or statements for this file */
    + V# W! B0 n6 v& `) {( n" X
  983.                         /* to compile                                  */
    : ?' Y0 n$ l7 S! h- A
  984.                         /* i.e. option: insert a display to view error on LED? */* H1 M7 Y) ?4 t& E' e9 i
  985.                  
    : C$ S- l# w1 u0 b& R
  986.         }
    8 C3 {; B8 R) g1 a+ L, E7 N7 g8 t4 q
  987. }1 ~6 O' X! F- z( t: t

  988. : g! z6 g3 Y4 o4 v- B, M
  989. /************************************************************************/
    7 g  W/ S3 p( ^* Z! T
  990. /* PROCEDURE: WREN_AAI_Check                                                                                        */
    : S0 i6 V2 _& x" O0 X  L. f0 r" E( v
  991. /*                                                                                                                                                */: q; ]: z0 [7 Y/ C
  992. /* This procedure checks for AAI and WEL bit once in AAI mode.                        *// W# l5 ?! \& b2 ~& \( t6 k* N& H' F
  993. /*                                                                                                                                                */- h/ S2 z" e" ~% F$ u3 P0 h0 g
  994. /* Input:                                                                                                                                */9 Q3 t3 `3 V0 @$ Q+ n
  995. /*                None                                                                                                                        */+ _5 b6 o, e# h& g# L
  996. /*                                                                                                                                                */
    3 T$ c. Q0 \7 k! m( A/ q
  997. /* Returns:                                                                                                                                */) j: F: X8 N5 L
  998. /*                Nothing                                                                                                                        */  a* w; F4 |3 R0 Z3 B& U0 P
  999. /************************************************************************/( Z+ [$ |: ^0 Y) `5 }+ S) r8 L' G
  1000. void WREN_AAI_Check()
    1 v$ m0 {: f9 {" I8 D
  1001. {  B' U1 Q% m9 w) P- f3 U+ y
  1002.         unsigned char byte;0 g, c1 |  k7 d4 v. E
  1003.         byte = Read_Status_Register();        /* read the status register */
    3 @! T$ x8 p2 B5 n4 S( R- w
  1004.         if (byte != 0x42)                /* verify that AAI and WEL bit is set */- t# \: b6 x7 N; N* _& z2 V% M' u
  1005.         {
    : @. X6 z' n- R' F" E5 e
  1006.                 while(1)               
    - T, {7 H3 O6 G0 N+ N# i. F) i
  1007.                         /* add source code or statements for this file */
    8 p( }( `$ P& t5 F& p
  1008.                         /* to compile                                  */+ N' m% g; M. O" c- H$ B( i! M
  1009.                         /* i.e. option: insert a display to view error on LED? */# Q9 c$ k7 {+ R4 y0 q
  1010. ) n9 e9 L' q  F& W2 D% |
  1011.         }! x" j7 L: F  b7 u
  1012. }
    4 a2 a0 D1 K9 u- R% k

  1013. $ x9 P2 G& Q" ]! ^) i6 ^, H
  1014. /************************************************************************/7 S! x0 o9 z9 A+ k  W" ^7 @0 y/ A
  1015. /* PROCEDURE: Verify                                                                                                        */9 {% U/ p# ^9 Z. ]! H8 F: N
  1016. /*                                                                                                                                                */
    $ _/ r  e9 O/ T: H
  1017. /* This procedure checks to see if the correct byte has be read.                */% Y3 H/ O2 r; _- ]+ L
  1018. /*                                                                                                                                                */
    , m( m3 D6 m6 w  {+ I9 Y" A" H1 C
  1019. /* Input:                                                                                                                                */
    6 U( Y: ^& C+ c0 F: V7 Z
  1020. /*                byte:                byte read                                                                                        */
    ( T* h% v) R- d* e
  1021. /*                cor_byte:        correct_byte that should be read                                        */4 e6 ^3 P! P3 r) ?5 O4 e# e
  1022. /*                                                                                                                                                */- A" R( Q* c- r, Y% K5 n: g
  1023. /* Returns:                                                                                                                                */
    , J. e& Q. N. t7 t( J
  1024. /*                Nothing                                                                                                                        */" ?1 W; S, u) S3 F
  1025. /************************************************************************/! U2 ]( N- z5 ?! Z# o- s* ], Y
  1026. void Verify(unsigned char byte, unsigned char cor_byte)" k3 V6 H( C5 u$ Q4 X8 t* s
  1027. {
    & A1 q7 A& S- ^/ t! i+ n, T9 y& R3 O
  1028.         if (byte != cor_byte): [; D% a1 f1 v+ n% _0 C
  1029.         {1 b' b, T* T# _
  1030.                 while(1)
    / S/ h/ f5 n. U# Y8 W& m1 B
  1031.                         /* add source code or statement for this file */
      [8 O2 _" u, x5 C% J1 D0 A2 E1 s
  1032.                         /* to compile                                  */
    8 A2 ]; h3 j& n% N6 M$ A
  1033.                         /* i.e. option: insert a display to view error on LED? */
    ; `8 I/ ]2 H& p
  1034.                 ; X; T0 M; n8 {3 j; s1 h4 V# }" s
  1035.         }# c# k" j1 j7 \4 j) g
  1036. }
    3 G( D. x- {" Z" i! H7 h
  1037. 3 c/ b1 K9 H0 {; P7 X

  1038. 2 y* p3 I. j4 ]/ I+ K: M3 q* o
  1039. int main()$ L7 o( w1 W, z& ]8 l4 V
  1040. {
    2 a/ u% S2 S2 D7 o+ C0 I
  1041. 8 Y. H8 @; c( J
  1042. return 0;- ^3 w* J5 W' ~$ Z3 E9 R
  1043. }
复制代码
发表于 2007-12-11 18:30:23 | 显示全部楼层
老大:+ f, ^; e* L" s+ B# s
   main()4 n1 b4 p5 V9 T9 ~( r6 G8 d
   里面怎么是空的呢?
, w* f2 `3 e+ G5 E) ?6 s   发一份给我吧
8 l, P7 h6 X7 W2 m! d) Lmail:luyijun2005@hotmail.com
% H% O* S) R# s9 P7 }咯。。。。
回复

使用道具 举报

 楼主| 发表于 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才能执行。
2 v% g3 ]7 k, H2 P! s- [* |- `0 ^! l4 E7 H0 B& c
[ 本帖最后由 screw 于 2008-1-8 17:46 编辑 ]
回复

使用道具 举报

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

使用道具 举报

 楼主| 发表于 2008-1-10 17:30:38 | 显示全部楼层
每个FLASHROM的SPI协义部分几乎都在自己的DataSheet(DS)里有。; \) D# s# ~  w  J/ U" P3 W
EC的代码在哪跑,你看DS的说明,每个EC都不同的。
) r; f* Q1 y. F' l, ~! @  [5 ZOEM用多大的FLASH,是由OEM决定的。或者你去各计算机厂商的网站上看看他们BIOS下载的文件有多大不就知道了?5 G& M# O) P1 s; c9 u! N# ]' q
上面几个问题是你没看任何东西而白问。
2 |, I  |3 F" c# r/ G! `
8 }2 E" w0 g6 _/ V: _* e至于冷清,那是一定的。中国大陆本来就没多少静下心来做技术的。请问一下,你有静下心来看过spec了么?hoho...
回复

使用道具 举报

发表于 2008-1-11 18:49:08 | 显示全部楼层
该怎么说呢,我是抱着很诚恳的态度来问问题的。上面我问出来的问题都是经过认真思考才问的。您站上贴出来的跟EC有关的spec我都看多,而且是很多遍(ACPI不是全部章节都看,因为我是hw)。EC的spec我也看多很多家,因为我们要做EC chip。楼主“上面几个问题是你没看任何东西而白问。”“请问一下,你有静下心来看过spec了么?”这个结论未免武断。# ]4 G/ y8 ?/ p# P2 \% f" C
" ~- Z% l* k# ^/ a! H
关于SPI flash对SPI接口的定义,我当然知道各家spec里面都有提到,但是我要知道如何才是通用的,我们不是只要支持一款就可以。所以我才会问SPI是否有官方spec。您也知道,做产品是一定要符合工业标准的!4 O  v& z( F9 G9 I" @$ U, i) l

- |7 W$ A/ R* ^" `/ G: F0 Z  g7 p关于EC firmware在哪里运行,除了ns有用内部flash的以外,基本都说是在flash上直接跑,并行的flash不会有问题,但是串行的flash速度可能就是问题,因此我会问到“EC firmware是直接在flash上运行吗?还是dump到EC内部的ram运行?直接在flash上运行会不会速度不够快?因为SPI是串行的,还要过转换才能得到指令阿,然后MCU才能执行。”
$ M7 X& N+ p, Q( u  a# J$ j9 N* v5 {: p
关于flash的大小,我当然知道是OEM定义,所以我才问“OEM一般使用多大的flash?”。因为我猜想您应该在BIOS厂家做过,所以想问一下。何况Flash的大小跟BIOS code的大小不一定等价啊...1 U  d, S- C0 c0 F& l, O1 ~

: a5 M+ Y$ |$ Y, M) S4 Z- x不管怎么说,多谢。
回复

使用道具 举报

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

使用道具 举报

发表于 2009-7-3 12:14:41 | 显示全部楼层
楼上这位前辈与我目前遇到的问题一样
! i% P' G2 G( \' g8 H& _似乎要把SPI能support 到最大,这EC chip应该有好卖点
% z/ b- N8 r% P( R, Z- g- fBIOS功能要不要强大,也就决定了SPI Flach的大小
1 `0 e% x( G4 g  l$ \5 x我是这么想的~让OEM去决定要挂多大!
2 B) x  O* h0 U! f5 h如果我司有BIOS工程师就好了~哈
$ u; n. H' I% ~0 c6 m; FWPCE775应该算很新的东西,来看它支持到多大?
/ j6 B* c6 e* A6 K. Y+ w% T: j
6 `' n! \  G, O6 P8 P  y另外,我觉得好多人都说会抢BUS,那肯定EC也是经过SPI 去fetch code来执行,但应该不用解到内存,因为8051的内存只做128byte
6 G/ r. b- u# v4 S其它2K byte是放在SPI flash上(ENE),不会多花时间去存放,然后再decode一次执行代码." b3 B) a8 S4 M- X: p% o
. ]) u, B' _0 t' T
这份driver收下~希望以后有用到
; Z* D, z; c$ v- |谢谢bini大大% a7 a# E- N, K4 g: l& S7 }. ~6 [
* b/ K% H7 Q: X
很新很新的新手,如有错误请指正 (准备看第二家的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()
1 m# f5 z# b$ x6 g{; D7 e9 j& \$ a- w  E
        unsigned char temp = 0;2 D# Q2 m( Q* h, t. d
        CE_Low();
4 u' \7 q* m+ ^* {  F    while (temp == 0x00)        /* waste time until not busy */" I* t' }, \# F& T( v5 ?
                temp = SO;
  `: s7 J) d: `4 d- ~" ^. F4 f        CE_High();
' ]7 B' x; Y! b9 z4 t( L" ^; G}
回复

使用道具 举报

发表于 2009-8-17 17:00:56 | 显示全部楼层
void Send_Byte(unsigned char out)
% B& [- P5 V! L+ E9 T. M' w! X{
  ~2 r: z! P5 u. D        
* z5 H3 v  e( \        unsigned char i = 0;4 ?* Z6 Q. P1 i- ^  U
        for (i = 0; i < 8; i++)- d5 s8 @2 [! o5 C. d* B; E
        {
+ u( \! g8 F2 ~1 ^                , o- O; X1 S, ^# V  d: _8 u6 H; Z6 k
                if ((out & 0x80) == 0x80)        /* check if MSB is high */6 N, q- u7 r' m2 |% ?& h7 ?
                        SI = 1;
" Q$ j5 z  o0 f0 N* S+ ^- g                else
: h4 J7 h0 ]  O- z1 R0 o                        SI = 0;                                /* if not, set to low */
9 N4 ]5 h0 t* L$ }; S- g4 I! l 问              SCK = 1;                                /* toggle clock high *// t6 s4 d% v6 }/ U
   题            out = (out << 1);                /* shift 1 place for next bit */# t  o3 M- Q- D7 M! ]" m
                SCK = 0;                                /* toggle clock low */
- X6 c+ N$ a# S4 S% y1 \: M        }+ R  O* l/ O$ d
}; o) E3 o; L/ U% \$ D$ g! n
如果将SCK = 1; out = (out << 1); 调换。会因sck置位时间过短,而出现问题吗?
回复

使用道具 举报

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

本版积分规则

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

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

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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