DIY编程器网

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2991|回复: 7
打印 上一主题 下一主题

39VF400A读写代码

[复制链接]
跳转到指定楼层
楼主
发表于 2012-10-29 07:55:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Software
Drivers

39VF400A
4 Mbit Multi-Purpose Flash

September 2001


ABOUT THE SOFTWARE

This application note provides software driver examples for 39VF400A 4 Mbit
Multi-Purpose Flash, that can be used in any microprocessor based system.
Please note that the software driver for 39VF400A is the same as the driver
for 39VF400 except the part number has been changed. Software driver examples
used in this document utilize two programming languages: (a) high -level "C"
for broad platform support and (b) optimized x86 assembly language. In many
cases, software driver routines can be inserted "as is" into the main body of
code being developed by the system software developers. Extensive comments
are included in each routine to describe the function of each routine. The
driver in "C" language can be used with many microprocessors and
microcontrollers, while the x86 assembly language provides an optimized solution
for x86 microprocessors. A Code Segment base address equal to C000h was used in
this sample code.  Software designers shall assign the segment address
appropriate to their designs.

ABOUT THE 39VF400A

Companion product datasheet for the 39VF400A should be reviewed in conjunction
with this application note for a complete understanding of the device.

Both the C and x86 assembly code in the document contain the following routines,
in this order:

Name                    Function
------------------------------------------------------------------
Check_SST_39VF400A      Check manufacturer and device ID
CFI_Query               CFI Query Entry/Exit command sequence
Erase_One_Sector        Erase a sector of 2048 words
Erase_One_Block         Erase a block of 32K words
Erase_Entire_Chip       Erase the contents of the entire chip
Program_One_Word        Alter data in one word
Program_One_Sector      Alter data in 2048 word sector
Program_One_Block       Alter data in 32K word block
Check_Toggle_Ready      End of internal program or erase detection using
                        Toggle bit
Check_Data_Polling      End of internal program or erase detection using
                        Data# polling


"C" LANGUAGE DRIVERS

  1. /***********************************************************************/
  2. /* Copyright Silicon Storage Technology, Inc. (SST), 1994-2001         */
  3. /* Example "C" language Driver of 39VF400A 4 Mbit Multi-Purpose Flash  */
  4. /* Nelson Wang, Silicon Storage Technology, Inc.                       */
  5. /*                                                                     */
  6. /* Revision 1.0, Sept. 12, 2001                                     */
  7. /*                                                                     */
  8. /* This file requires these external "timing"  routines:               */
  9. /*                                                                     */
  10. /*      1.)  Delay_150_Nano_Seconds                                    */
  11. /*      2.)  Delay_25_Milli_Seconds                                    */
  12. /*      3.)  Delay_100_Milli_Seconds                                   */
  13. /***********************************************************************/

  14. #define FALSE                   0
  15. #define TRUE                    1

  16. #define SECTOR_SIZE             2048    /* Must be 2048 words for 39VF400A */
  17. #define BLOCK_SIZE              32768   /* Must be 32K words for 39VF400A  */

  18. #define SST_ID                  0x00BF  /* SST Manufacturer's ID code   */
  19. #define SST_39VF400A            0x2780  /* SST39VF400A device code      */
  20.                                         /* same device code as SST39VF400 */

  21. typedef unsigned char           BYTE;
  22. typedef unsigned int            WORD;

  23. /* -------------------------------------------------------------------- */
  24. /*                       EXTERNAL ROUTINES                              */
  25. /* -------------------------------------------------------------------- */

  26. extern void     Delay_150_Nano_Seconds();
  27. extern void     Delay_25_Milli_Seconds();
  28. extern void     Delay_100_Milli_Seconds();


  29. /************************************************************************/
  30. /* PROCEDURE:   Check_SST_39VF400A                                      */
  31. /*                                                                      */
  32. /* This procedure decides whether a physical hardware device has a      */
  33. /* SST39VF400A 4 Mbit Multi-Purpose Flash installed or not.             */
  34. /*                                                                      */
  35. /* Input:                                                               */
  36. /*          None                                                        */
  37. /*                                                                      */
  38. /* Output:                                                              */
  39. /*          return TRUE:  indicates a SST39VF400A                       */
  40. /*          return FALSE: indicates not a SST39VF400A                   */
  41. /************************************************************************/

  42. int Check_SST_39VF400A()              /* same device code as SST39VF400 */
  43. {
  44.         WORD far *Temp;
  45.         WORD SST_id1;
  46.         WORD far *Temp1;
  47.         WORD SST_id2;
  48.         int  ReturnStatus;

  49.         /*  Issue the Software Product ID code to 39VF400A   */

  50.         Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h  */
  51.         *Temp1= 0xAAAA;                 /* write data 0xAAAA to the address */
  52.         Temp1 = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh  */
  53.         *Temp1= 0x5555;                 /* write data 0x5555 to the address */
  54.         Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h  */
  55.         *Temp1= 0x9090;                 /* write data 0x9090 to the address */

  56.         Delay_150_Nano_Seconds();       /* insert delay time = Tida         */

  57.         /* Read the product ID from 39VF400A */

  58.         Temp  = (WORD far *)0xC0000000; /* set up address to be C000:0000h */
  59.         SST_id1  =  *Temp;              /* get first ID word               */
  60.         SST_id1  =  SST_id1 & 0xFF;     /* mask of higher byte             */
  61.         Temp1 = (WORD far *)0xC0000001; /* set up address to be C000:0001h */
  62.         SST_id2  =  *Temp1;             /* get second ID word              */

  63.         /* Determine whether there is a SST39VF400A installed or not */

  64.         if ((SST_id1 == SST_ID) && (SST_id2 ==SST_39VF400A))
  65.                 ReturnStatus = TRUE;
  66.         else
  67.                 ReturnStatus = FALSE;

  68.         /* Issue the Soffware Product ID Exit code thus returning the 39VF400A*/
  69.         /* to the read operating mode                                         */

  70.         Temp1  = (WORD far *)0xC0005555; /* set up address to be C000:5555h   */
  71.         *Temp1 = 0xAAAA;                 /* write data 0xAAAA to the address  */
  72.         Temp1  = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh   */
  73.         *Temp1 = 0x5555;                 /* write data 0x5555 to the address  */
  74.         Temp1  = (WORD far *)0xC0005555; /* set up address to be C000:5555h   */
  75.         *Temp1 = 0xF0F0;                 /* write data 0xF0F0 to the address  */

  76.         Delay_150_Nano_Seconds();        /* insert delay time = Tida          */

  77.         return(ReturnStatus);
  78. }


  79. /************************************************************************/
  80. /* PROCEDURE:   CFI_Query                                               */
  81. /*                                                                      */
  82. /* This procedure should be used to query for CFI information           */
  83. /*                                                                      */
  84. /* Input:                                                               */
  85. /*          None                                                        */
  86. /*                                                                      */
  87. /* Output:                                                              */
  88. /*          None                                                        */
  89. /************************************************************************/

  90. int CFI_Query()
  91. {
  92.         WORD far *Temp1;

  93.         /*  Issue the Software Product ID code to 39VF400A   */

  94.         Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h    */
  95.         *Temp1= 0xAAAA;                 /* write data 0xAAAA to the address   */
  96.         Temp1 = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh    */
  97.         *Temp1= 0x5555;                 /* write data 0x5555 to the address   */
  98.         Temp1 = (WORD far *)0xC0005555; /* set up address to be C000:5555h    */
  99.         *Temp1= 0x9898;                 /* write data 0x9898 to the address   */

  100.         Delay_150_Nano_Seconds();       /* insert delay time = Tida           */

  101.         /* --------------------------------- */
  102.         /*  Perform all CFI operations here  */
  103.         /*  NOTE:  no sample code provided   */
  104.         /* --------------------------------- */


  105.         /* Issue the CFI Exit code thus returning the 39VF400A */
  106.         /* to the read operating mode                          */

  107.         Temp1  = (WORD far *)0xC0005555; /* set up address to be C000:5555h   */
  108.         *Temp1 = 0xAAAA;                 /* write data 0xAAAA to the address  */
  109.         Temp1  = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh   */
  110.         *Temp1 = 0x5555;                 /* write data 0x5555 to the address  */
  111.         Temp1  = (WORD far *)0xC0005555; /* set up address to be C000:5555h   */
  112.         *Temp1 = 0xF0F0;                 /* write data 0xF0F0 to the address  */

  113.         Delay_150_Nano_Seconds();        /* insert delay time = Tida          */
  114. }


  115. /************************************************************************/
  116. /* PROCEDURE:   Erase_One_Sector                                        */
  117. /*                                                                      */
  118. /* This procedure can be used to erase a total of 2048 words.           */
  119. /*                                                                      */
  120. /* Input:                                                               */
  121. /*      Dst     DESTINATION address where the erase operation starts    */
  122. /*                                                                      */
  123. /* Output:                                                              */
  124. /*      NONE                                                            */
  125. /************************************************************************/

  126. int Erase_One_Sector (WORD far *Dst)
  127. {
  128.         WORD far *Temp;

  129.         /*  Issue the Sector Erase command to 39VF400A  */

  130.         Temp  = (WORD far *)0xC0005555; /* set up address to be C000:5555h  */
  131.         *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
  132.         Temp  = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh  */
  133.         *Temp = 0x5555;                 /* write data 0x5555 to the address */
  134.         Temp  = (WORD far *)0xC0005555; /* set up address to be C000:5555h  */
  135.         *Temp = 0x8080;                 /* write data 0x8080 to the address */
  136.         Temp  = (WORD far *)0xC0005555; /* set up address to be C000:5555h  */
  137.         *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
  138.         Temp  = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh  */
  139.         *Temp = 0x5555;                 /* write data 0x5555 to the address */

  140.         Temp  = Dst;                  /* set up starting address to be erased */
  141.         *Temp = 0x3030;                 /* write data 0x3030 to the address */
  142.         Delay_25_Milli_Seconds();       /* Delay time = Tse                 */
  143. }


  144. /************************************************************************/
  145. /* PROCEDURE:   Erase_One_Block                                         */
  146. /*                                                                      */
  147. /* This procedure can be used to erase a total of 32K words.            */
  148. /*                                                                      */
  149. /* Input:                                                               */
  150. /*      Dst     DESTINATION address where the erase operation starts    */
  151. /*                                                                      */
  152. /* Output:                                                              */
  153. /*      NONE                                                            */
  154. /************************************************************************/

  155. int Erase_One_Block (WORD far *Dst)
  156. {
  157.         WORD far *Temp;

  158.         /*  Issue the Sector Erase command to 39VF400A  */

  159.         Temp  = (WORD far *)0xC0005555; /* set up address to be C000:5555h  */
  160.         *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
  161.         Temp  = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh  */
  162.         *Temp = 0x5555;                 /* write data 0x5555 to the address */
  163.         Temp  = (WORD far *)0xC0005555; /* set up address to be C000:5555h  */
  164.         *Temp = 0x8080;                 /* write data 0x8080 to the address */
  165.         Temp  = (WORD far *)0xC0005555; /* set up address to be C000:5555h  */
  166.         *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
  167.         Temp  = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh  */
  168.         *Temp = 0x5555;                 /* write data 0x5555 to the address */

  169.         Temp  = Dst;                  /* set up starting address to be erased */
  170.         *Temp = 0x5050;                 /* write data 0x5050 to the address */
  171.         Delay_25_Milli_Seconds();       /* Delay time = Tbe                 */
  172. }


  173. /************************************************************************/
  174. /* PROCEDURE:   Erase_Entire_Chip                                       */
  175. /*                                                                      */
  176. /* This procedure can be used to erase the entire chip.                 */
  177. /*                                                                      */
  178. /* Input:                                                               */
  179. /*      NONE                                                            */
  180. /*                                                                      */
  181. /* Output:                                                              */
  182. /*      NONE                                                            */
  183. /************************************************************************/

  184. int Erase_Entire_Chip()
  185. {
  186.         WORD far *Temp;

  187.         /*  Issue the Chip Erase command to 39VF400A  */

  188.         Temp  = (WORD far *)0xC0005555; /* set up address to be C000:5555h  */
  189.         *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
  190.         Temp  = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh  */
  191.         *Temp = 0x5555;                 /* write data 0x5555 to the address */
  192.         Temp  = (WORD far *)0xC0005555; /* set up address to be C000:5555h  */
  193.         *Temp = 0x8080;                 /* write data 0x8080 to the address */
  194.         Temp  = (WORD far *)0xC0005555; /* set up address to be C000:5555h  */
  195.         *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
  196.         Temp  = (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh  */
  197.         *Temp = 0x5555;                 /* write data 0x5555 to the address */
  198.         Temp  = (WORD far *)0xC0005555; /* set up address to be C000:5555h  */
  199.         *Temp = 0x1010;                 /* write data 0x1010 to the address */
  200.         Delay_100_Milli_Seconds();      /* Delay Tsce time                  */
  201. }


  202. /************************************************************************/
  203. /* PROCEDURE:   Program_One_Word                                        */
  204. /*                                                                      */
  205. /* This procedure can be used to program ONE word of data to the        */
  206. /* 39VF400.                                                             */
  207. /*                                                                      */
  208. /* NOTE:  It is necessary to first erase the sector containing the      */
  209. /*        word to be programmed.                                            */
  210. /*                                                                      */
  211. /* Input:                                                               */
  212. /*           SrcWord The WORD which will be written to the 39VF400A     */
  213. /*           Dst     DESTINATION address which will be written with the */
  214. /*                   data passed in from Src                            */
  215. /*                                                                      */
  216. /* Output:                                                              */
  217. /*           None                                                       */
  218. /************************************************************************/

  219. void Program_One_Word (WORD SrcWord,    WORD far *Dst)
  220. {
  221.     WORD far *Temp;
  222.         WORD far *SourceBuf;
  223.         WORD far *DestBuf;
  224.         int Index;

  225.         DestBuf = Dst;

  226.         Temp =  (WORD far *)0xC0005555; /* set up address to be C000:555h   */
  227.         *Temp = 0xAAAA;                 /* write data 0xAAAA to the address */
  228.         Temp =  (WORD far *)0xC0002AAA; /* set up address to be C000:2AAAh  */
  229.         *Temp = 0x5555;                 /* write data 0x5555 to the address */
  230.         Temp =  (WORD far *)0xC0005555; /* set up address to be C000:5555h  */
  231.         *Temp = 0xA0A0;                 /* write data 0xA0A0 to the address */
  232.         *DestBuf = SrcWord;             /* transfer the byte to destination */
  233.         Check_Toggle_Ready(DestBuf);    /* wait for TOGGLE bit to get ready */
  234. }


  235. /************************************************************************/
  236. /* PROCEDURE:   Program_One_Sector                                      */
  237. /*                                                                      */
  238. /* This procedure can be used to program a total of 2048 words of data  */
  239. /* to the SST39VF400A.                                                  */
  240. /*                                                                      */
  241. /* Input:                                                               */
  242. /*           Src     SOURCE address containing the data which will be   */
  243. /*                   written to the 39VF400A                            */
  244. /*           Dst     DESTINATION address which will be written with the */
  245. /*                   data passed in from Src                            */
  246. /*                                                                      */
  247. /* Output:                                                              */
  248. /*           None                                                       */
  249. /************************************************************************/

  250. void Program_One_Sector (WORD far *Src,    WORD far *Dst)
  251. {
  252.         WORD far *Temp;
  253.         WORD far *SourceBuf;
  254.         WORD far *DestBuf;
  255.         int Index;

  256.         SourceBuf = Src;
  257.         DestBuf = Dst;

  258.         Erase_One_Sector(Dst);          /* erase the sector first */

  259.         for (Index = 0; Index < SECTOR_SIZE; Index++)
  260.         {
  261.             Temp =  (WORD far *)0xC0005555;
  262.             /* set up address to be C000:555h           */
  263.             *Temp = 0xAAAA;
  264.             /* write data 0xAAAA to the address         */
  265.             Temp =  (WORD far *)0xC0002AAA;
  266.             /* set up address to be C000:2AAAh          */
  267.             *Temp = 0x5555;
  268.             /* write data 0x5555 to the address         */
  269.             Temp =  (WORD far *)0xC0005555;
  270.             /* set up address to be C000:5555h          */
  271.             *Temp = 0xA0A0;
  272.             /* write data 0xA0A0 to the address         */
  273.             Temp = DestBuf;
  274.             /* save the original Destination address    */
  275.             *DestBuf++ = *SourceBuf++;
  276.             /* transfer data from source to destination */
  277.             Check_Toggle_Ready(Temp);
  278.             /* wait for TOGGLE bit to get ready         */
  279.         }
  280. }


  281. /************************************************************************/
  282. /* PROCEDURE:   Program_One_Block                                       */
  283. /*                                                                      */
  284. /* This procedure can be used to program a total of 32k words of data   */
  285. /* to the SST39VF400A.                                                  */
  286. /*                                                                      */
  287. /* Input:                                                               */
  288. /*           Src     SOURCE address containing the data which will be   */
  289. /*                   written to the 39VF400A                            */
  290. /*           Dst     DESTINATION address which will be written with the */
  291. /*                   data passed in from Src                            */
  292. /*                                                                      */
  293. /* Output:                                                              */
  294. /*           None                                                       */
  295. /************************************************************************/

  296. void Program_One_Block (WORD far *Src,    WORD far *Dst)
  297. {
  298.         WORD far *Temp;
  299.         WORD far *SourceBuf;
  300.         WORD far *DestBuf;
  301.         int Index;

  302.         SourceBuf = Src;
  303.         DestBuf = Dst;

  304.         Erase_One_Block(Dst);          /* erase the sector first */

  305.         for (Index = 0; Index < BLOCK_SIZE; Index++)
  306.         {
  307.             Temp =  (WORD far *)0xC0005555;
  308.             /* set up address to be C000:555h           */
  309.             *Temp = 0xAAAA;
  310.             /* write data 0xAAAA to the address         */
  311.             Temp =  (WORD far *)0xC0002AAA;
  312.             /* set up address to be C000:2AAAh          */
  313.             *Temp = 0x5555;
  314.             /* write data 0x5555 to the address         */
  315.             Temp =  (WORD far *)0xC0005555;
  316.             /* set up address to be C000:5555h          */
  317.             *Temp = 0xA0A0;
  318.             /* write data 0xA0A0 to the address         */
  319.             Temp = DestBuf;
  320.             /* save the original Destination address    */
  321.             *DestBuf++ = *SourceBuf++;
  322.             /* transfer data from source to destination */
  323.             Check_Toggle_Ready(Temp);
  324.             /* wait for TOGGLE bit to get ready         */
  325.         }
  326. }


  327. /************************************************************************/
  328. /* PROCEDURE:    Check_Toggle_Ready                                     */
  329. /*                                                                      */
  330. /* During the internal program cycle, any consecutive read operation    */
  331. /* on DQ6 will produce alternating 0's and 1's (i.e. toggling between   */
  332. /* 0 and 1). When the program cycle is completed, DQ6 of the data will  */
  333. /* stop toggling. After the DQ6 data bit stops toggling, the device is  */
  334. /* ready for next operation.                                            */
  335. /*                                                                      */
  336. /* Input:                                                               */
  337. /*           Dst        must already be set-up by the caller            */
  338. /*                                                                      */
  339. /* Output:                                                              */
  340. /*           None                                                       */
  341. /************************************************************************/

  342. void Check_Toggle_Ready (WORD far  *Dst)
  343. {
  344.         BYTE Loop = TRUE;
  345.         WORD PreData;
  346.         WORD CurrData;
  347.         unsigned long TimeOut = 0;

  348.         PreData = *Dst;
  349.         PreData = PreData & 0x4040;
  350.         while ((TimeOut< 0x07FFFFFF) && (Loop))
  351.         {
  352.             CurrData = *Dst;
  353.             CurrData = CurrData & 0x4040;
  354.             if (PreData == CurrData)
  355.                     Loop = FALSE;   /* ready to exit the while loop */
  356.             PreData = CurrData;
  357.             TimeOut++;
  358.         }
  359. }


  360. /************************************************************************/
  361. /* PROCEDURE:   Check_Data_Polling                                      */
  362. /*                                                                      */
  363. /* During the internal program cycle, any attempt to read DQ7 of the    */
  364. /* last byte loaded during the page/byte-load cycle will receive the    */
  365. /* complement of the true data.  Once the program cycle is completed,   */
  366. /* DQ7 will show true data.                                             */
  367. /*                                                                      */
  368. /* Input:                                                               */
  369. /*           Dst        must already be set-up by the caller            */
  370. /*           True       Data is the original (true) data                */
  371. /*                                                                      */
  372. /* Output:                                                              */
  373. /*           None                                                       */
  374. /************************************************************************/

  375. void Check_Data_Polling (WORD far  *Dst,       WORD TrueData)
  376. {
  377.         BYTE Loop = TRUE;
  378.         WORD CurrData;
  379.         unsigned long TimeOut = 0;

  380.         TrueData = TrueData &  0x8080;
  381.         while ((TimeOut< 0x07FFFFFF) && (Loop))
  382.         {
  383.                 CurrData = *Dst;
  384.                 CurrData = CurrData & 0x8080;
  385.                 if (TrueData == CurrData)
  386.                         Loop = FALSE;   /* ready to exit the while loop  */
  387.                 TimeOut++;
  388.         }
  389. }
复制代码




8086 ASSEMBLY LANGUAGE DRIVERS

  1. ; ======================================================================
  2. ; Copyright Silicon Storage Technology, Inc. (SST), 1994-2001
  3. ; EXAMPLE 8086 assembly Drivers for SST39VF400A 4 Mbit MultiPurpose Flash
  4. ; Frank Cirimele,  Silicon Storage Technology, Inc.
  5. ;
  6. ; Revision 1.0,  Sept. 12, 2001
  7. ;
  8. ; This file requires these external "timing" routines:
  9. ;
  10. ;       1.)  Delay_150_Nano_Seconds
  11. ;       2.)  Delay_25_Milli_Seconds
  12. ;       3.)  Delay_100_Milli_Seconds
  13. ; ======================================================================

  14. SECTOR_SIZE             EQU     2048    ; Must be 4096 bytes for SST39VF400A
  15. BLOCK_SIZE              EQU     32768

  16. SST_ID                  EQU     00BFh  ; SST Manufacturer's ID code
  17. SST_SST39VF400A         EQU     2780h  ; SST SST39VF400A internal code, and
  18.                                        ;  is same device code as SST39VF400
  19. ABS_SEGMENT     EQU     0C000h

  20. extrn   Delay_150_Nano_Seconds:near
  21. extrn   Delay_25_Milli_Seconds:near
  22. extrn   Delay_100_Milli_Seconds:near


  23. ;=======================================================================
  24. ; PROCEDURE:    Check_SST_SST39VF400A
  25. ;
  26. ; This procedure decides whether a physical hardware device has a
  27. ; SST39VF400A 4 Mbit Multi-Purpose Flash installed or not.
  28. ;
  29. ; Input:
  30. ;       None
  31. ;
  32. ; Output:
  33. ;       carry bit:   CLEARED means a SST39VF400A is installed
  34. ;       carry bit:   SET means a SST39VF400A is NOT installed
  35. ;
  36. ;=======================================================================

  37. Check_SST_SST39VF400A       proc    near

  38.         push    ax                              ; save registers
  39.         push    ds
  40.     pushf                    ; save interrupt state

  41.     ; It is mandatory to maintain pushf as the last push instruction.

  42.         cli                                     ; disable interrupts
  43.         mov     ax, ABS_SEGMENT                 ; set up data segment
  44.         mov     ds, ax

  45.         mov     ds:word ptr [5555h], 0AAAAh     ; issue the 3-byte product ID
  46.         mov     ds:word ptr [2AAAh], 05555h     ;  command to the SST39VF400A
  47.         mov     ds:word ptr [5555h], 09090h

  48.         call    Delay_150_Nano_Seconds          ; insert delay = Tida

  49.         mov     ax, ds:[0]
  50.         cmp     ax, SST_ID                      ; is this a SST part?
  51.         jne     CSC5                            ; NO, then return Carry set
  52.         mov     ax, ds:[1]
  53.         cmp     ax, SST_SST39VF400A             ; is it a SST39VF400A?
  54.         jne     CSC5                            ; NO, then Non-SST part and
  55.                                                 ; set Carry flag
  56. CSC4:
  57.     pop    ax                ; get flags from stack
  58.     and    ax, 0FFFEh            ; and clear carry flag
  59.         jmp     short CSC6

  60. CSC5:
  61.     pop    ax                ; get flags from stack
  62.     or     ax, 0001h            ; and set carry flag

  63. CSC6:
  64.     push    ax                ; return flags to stack

  65. ;
  66. ; Issue the Software Product ID Exit code thus returning the SST39VF400A
  67. ; to the read operation mode.
  68. ;

  69.         mov     ds:word ptr [5555h], 0AAAAh     ; issue the 3-byte product ID
  70.         mov     ds:word ptr [2AAAh], 05555h     ;  exit command to the
  71.         mov     ds:word ptr [5555h], 0F0F0h    ;  SST39VF400A

  72.         call    Delay_150_Nano_Seconds        ; insert delay = Tida

  73.         popf                                    ; restore flags
  74.         pop     ds                              ; restore registers
  75.         pop     ax

  76.         ret

  77. Check_SST_SST39VF400A endp


  78. ;=======================================================================
  79. ; PROCEDURE:    CFI_Query
  80. ;
  81. ; This procedure provides access to the CFI information embedded within
  82. ; the SST39VF400A 4 Mbit Multi-Purpose Flash device.
  83. ;
  84. ; Input:
  85. ;       None
  86. ;
  87. ; Output:
  88. ;       None
  89. ;
  90. ;=======================================================================

  91. CFI_Query       proc    near

  92.     pushf                    ; save interrupt state
  93.     push    ax                              ; save registers
  94.         push    ds

  95.         cli                                     ; disable interrupts
  96.         mov     ax, ABS_SEGMENT                 ; set up the ds register
  97.         mov     ds, ax

  98.         mov     ds:word ptr [5555h], 0AAAAh     ; issue the 3-byte product ID
  99.         mov     ds:word ptr [2AAAh], 05555h     ;  command to the SST39VF400A
  100.         mov     ds:word ptr [5555h], 09898h

  101.         call    Delay_150_Nano_Seconds        ; insert delay = Tida

  102. ; -----------------------------------
  103. ;   Perform all CFI operations here
  104. ;   NOTE:  NO sample code provided
  105. ; -----------------------------------


  106.         mov     ds:word ptr [5555h], 0AAAAh    ; issue the 3-byte product ID
  107.         mov     ds:word ptr [2AAAh], 05555h    ; exit command to the SST39VF400A
  108.         mov     ds:word ptr [5555h], 0F0F0h

  109.         call    Delay_150_Nano_Seconds        ; insert delay = Tida

  110.         pop     ds                              ; restore registers
  111.         pop     ax
  112.     popf                    ; restore flags

  113.         ret

  114. CFI_Query       endp


  115. ; =====================================================================
  116. ; PROCEDURE:    Erase_One_Sector
  117. ;
  118. ; This procedure can be used to erase a sector, or total of 2048 bytes,
  119. ; in the SST39VF400A.
  120. ;
  121. ; Input:
  122. ;       es:di   points to the beginning address of the "Destination"
  123. ;               sector which will be erased.
  124. ;               ==> Note: The address MUST be on a sector boundary,
  125. ;                         that is, a multiple of 2048.
  126. ;
  127. ; Output:
  128. ;       None
  129. ; =====================================================================

  130. Erase_One_Sector        proc    near

  131.         push    ax                              ; save register

  132.         mov     es:word ptr [5555h], 0AAAAh    ; send 6-byte code for
  133.         mov     es:word ptr [2AAAh], 05555h    ; sector erase
  134.         mov     es:word ptr [5555h], 08080h
  135.         mov     es:word ptr [5555h], 0AAAAh
  136.         mov     es:word ptr [2AAAh], 05555h
  137.         mov     ax, 03030h
  138.         mov     word ptr es:[di], ax

  139.         call    Delay_25_Milli_Seconds        ; insert delay = Tse

  140.         pop     ax                              ; restore register

  141.         ret

  142. Erase_One_Sector        endp


  143. ; =====================================================================
  144. ; PROCEDURE:    Erase_One_Block
  145. ;
  146. ; This procedure can be used to erase a block, or total of 32K words,
  147. ; in the SST39VF400A.
  148. ;
  149. ; Input:
  150. ;       es:di   points to the beginning address of the "Destination"
  151. ;               block which will be erased.
  152. ;               ==> Note: The address MUST be on a block boundary,
  153. ;                         that is, a multiple of 32K.
  154. ;
  155. ; Output:
  156. ;       None
  157. ; =====================================================================

  158. Erase_One_Block         proc    near

  159.         push    ax                              ; save register

  160.         mov     es:word ptr [5555h], 0AAAAh    ; send 6-byte code for
  161.         mov     es:word ptr [2AAAh], 05555h    ; block erase
  162.         mov     es:word ptr [5555h], 08080h
  163.         mov     es:word ptr [5555h], 0AAAAh
  164.         mov     es:word ptr [2AAAh], 05555h
  165.         mov     ax, 05050h
  166.         mov     word ptr es:[di], ax

  167.         call    Delay_25_Milli_Seconds        ; insert delay = Tbe

  168.         pop     ax                              ; restore register

  169.         ret

  170. Erase_One_Block         endp


  171. ; =====================================================================
  172. ; PROCEDURE:    Erase_Entire_Chip
  173. ;
  174. ; This procedure can be used to erase the entire contents of
  175. ; SST's SST39VF400A.
  176. ;
  177. ; Input:
  178. ;       none
  179. ;
  180. ; Output:
  181. ;       None
  182. ; =====================================================================

  183. Erase_Entire_Chip       proc    near

  184.         mov     es:word ptr [5555h], 0AAAAh    ; send 6-byte code for
  185.         mov     es:word ptr [2AAAh], 05555h    ; chip erase
  186.         mov     es:word ptr [5555h], 08080h
  187.         mov     es:word ptr [5555h], 0AAAAh
  188.         mov     es:word ptr [2AAAh], 05555h
  189.         mov     es:word ptr [5555h], 01010h

  190.         call    Delay_100_Milli_Seconds        ; insert delay = Tsce

  191.         ret

  192. Erase_Entire_Chip       endp


  193. ; =====================================================================
  194. ; PROCEDURE:    Program_One_Word
  195. ;
  196. ; This procedure can be used to program ONE word of data to the SST39VF400A.
  197. ;
  198. ; NOTE:  It is necessary to first erase the sector containing the word to
  199. ;        be programmed.
  200. ;
  201. ;
  202. ; Input:
  203. ;       ax      WORD which will be written into the SST39VF400A.
  204. ;       es:di   DESTINATION address which will be written with the
  205. ;               data input in ax.
  206. ;
  207. ; Output:
  208. ;       None
  209. ;       SI, DI:  Contain their original values
  210. ; =====================================================================

  211. Program_One_Word          proc    near

  212.         push    ax                              ; save registers
  213.         push    ds
  214.         mov     ax, ABS_SEGMENT                 ; set up the ds register
  215.         mov     ds, ax
  216.         mov     ds:word ptr [5555h], 0AAAAh     ; send 3 byte data protection
  217.         mov     ds:word ptr [2AAAh], 05555h     ;  sequence to the chip
  218.         mov     ds:word ptr [5555h], 0A0A0h
  219.         pop     ds                              ; restore the byte to be
  220.         pop     ax                             ;  programmed from stack
  221.         mov     word ptr es:[di], ax            ; program the byte
  222.         call    check_Toggle_Ready              ; wait for valid TOGGLE bit

  223.         ret

  224. Program_One_Word          endp


  225. ; =====================================================================
  226. ; PROCEDURE:    Program_One_Sector
  227. ;
  228. ; This procedure can be used to program a memory sector, or total of
  229. ; 2048 words, of the SST39VF400A.
  230. ;
  231. ; Input:
  232. ;       ds:si   SOURCE address containing the data which will be
  233. ;               written into the SST39VF400A.
  234. ;       es:di   DESTINATION address which will be written with the
  235. ;               data passed in for ds:si
  236. ;
  237. ; Output:
  238. ;       None
  239. ;       SI, DI:  Contain their original values
  240. ; =====================================================================

  241. Program_One_Sector        proc    near

  242.         push    ax              ; save registers
  243.         push    bx
  244.         push    di
  245.         push    si
  246.         pushf                   ; preserve the "Direction" flag
  247.         cld                     ; clear "Direction" flag to
  248.                                 ;  auto-increment SI and DI
  249. ;
  250. ; Erase the sector before programming.  Each erase command will erase a total
  251. ; of 2048 words for the SST39VF400A
  252. ;
  253.         call    Erase_One_Sector
  254. ;
  255. ; The following loop will program a total of 2048 words to the SST39VF400A
  256. ;
  257.         mov     cx, SECTOR_SIZE
  258. POS1:
  259.         push    ds
  260.         mov     ax, ABS_SEGMENT
  261.         mov     ds, ax
  262.         mov     ds:word ptr [5555h], 0AAAAh    ; send 3-byte SDP sequence
  263.         mov     ds:word ptr [2AAAh], 05555h
  264.         mov     ds:word ptr [5555h], 0A0A0h
  265.         pop     ds

  266.         lodsw                           ; get the word to be programmed
  267.         mov     bx, di                  ; preserve original DI temporarily
  268.         stosw                           ; program the word
  269.         push    di                      ; preserve incremented DI temporarily
  270.         mov     di, bx            ; restore original DI
  271.         call    check_Toggle_Ready      ; wait for TOGGLE bit to get ready
  272.         pop     di                      ; retrieve the updated DI
  273.         loop    POS1                    ; continue program more words until done
  274. ;
  275. ; Restore the registers' value from the stack
  276. ;
  277.         popf                            ; restore original direction flag
  278.         pop     si                      ; restore registers
  279.         pop     di
  280.         pop     bx
  281.         pop     ax

  282.         ret

  283. Program_One_Sector        endp


  284. ; =====================================================================
  285. ; PROCEDURE:    Program_One_Block
  286. ;
  287. ; This procedure can be used to program a memory block, or a total of
  288. ; 32K words, of the SST39VF400A.
  289. ;
  290. ; Input:
  291. ;       ds:si   SOURCE address containing the data which will be
  292. ;               written into the SST39VF400A.
  293. ;       es:di   DESTINATION address which will be written with the
  294. ;               data passed in for ds:si
  295. ;
  296. ; Output:
  297. ;       None
  298. ;       SI, DI:  Contain their original values
  299. ; =====================================================================

  300. Program_One_Block         proc    near

  301.         push    ax              ; save registers
  302.         push    bx
  303.         push    di
  304.         push    si
  305.         pushf                   ; preserve the "Direction" flag
  306.         cld                     ; clear "Direction" flag to
  307.                                 ;  auto-increment SI and DI
  308. ;
  309. ; Erase the block before programming.  Each erase command will erase a total
  310. ; of 32K words of the SST39VF400A.
  311. ;
  312.         call    Erase_One_Block
  313. ;
  314. ; The following loop will program a total of 32K words to SST's SST39VF400A
  315. ;
  316.         mov     cx, BLOCK_SIZE
  317. POB1:
  318.         push    ds
  319.         mov     ax, ABS_SEGMENT
  320.         mov     ds, ax
  321.         mov     ds:word ptr [5555h], 0AAAAh     ; send 3-byte SDP sequence
  322.         mov     ds:word ptr [2AAAh], 05555h     
  323.         mov     ds:word ptr [5555h], 0A0A0h
  324.         pop     ds

  325.         lodsw                           ; get the word to be programmed
  326.         mov     bx, di                  ; preserve DI temporarily
  327.         stosw                           ; program the word
  328.         push    di                      ; preserve incremented DI temporarily
  329.         mov     di, bx            ; restore original DI
  330.         call    check_Toggle_Ready      ; wait for TOGGLE bit to get ready
  331.         pop     di                      ; retrieve the updated DI
  332.         loop    POB1                    ; continue program more words until done

  333.         popf                            ; restore original direction flag
  334.         pop     si                      ; restore registers
  335.         pop     di
  336.         pop     bx
  337.         pop     ax

  338.         ret

  339. Program_One_Block         endp


  340. ;======================================================================
  341. ; PROCEDURE:                    Check_Toggle_Ready
  342. ;
  343. ; During the internal program cycle, any consecutive read operation
  344. ; on DQ6 will produce alternating 0抯 and 1抯, i.e. toggling between
  345. ; 0 and 1. When the program cycle is completed, the DQ6 data will
  346. ; stop toggling. After the DQ6 data stops toggling, the device is ready
  347. ; for the next operation.
  348. ;
  349. ; Input:
  350. ;       es:di   must already be set-up by the caller
  351. ;
  352. ; Output:
  353. ;       None
  354. ;======================================================================

  355. Check_Toggle_Ready      proc    near

  356.         push    ax              ; save registers
  357.         push    bx

  358.         mov     ax, es:[di]     ; read a word from the chip
  359.         and     ax, 4040h       ; mask out the TOGGLE bit (DQ6)
  360. CTR_Tog2:
  361.         mov     bx, es:[di]     ; read the same word from the chip again
  362.         and     bx, 4040h       ; mask out the TOGGLE bit (DQ6)
  363.         cmp     ax, bx          ; is DQ6 still toggling?
  364.         je      CTR_Tog3        ; No, then the write operation is done
  365.         xchg    ax, bx          ; YES, then continue checking...
  366.         jmp     short CTR_Tog2
  367. CTR_Tog3:
  368.         pop     bx              ; restore registers
  369.         pop     ax

  370.         ret

  371. Check_Toggle_Ready      endp


  372. ;=======================================================================
  373. ; PROCEDURE:                    Check_Data_Polling
  374. ;
  375. ; During the internal program cycle, any attempt to read DQ7 of the last
  376. ; byte loaded during the page/byte-load cycle will receive the complement
  377. ; of the true data.  Once the program cycle is completed, DQ7 will show
  378. ; true data.
  379. ;
  380. ; Input:
  381. ;       es:di   must already be set-up by the caller
  382. ;       bx      contains the original (true) data
  383. ;
  384. ; Output:
  385. ;       None
  386. ;
  387. ;=======================================================================

  388. Check_Data_Polling      proc    near

  389.         push    ax              ; save registers
  390.         push    bx

  391.         and     bx, 8080h       ; mask out the DQ7 bit
  392. CDP_Tog2:
  393.         mov     ax, es:[di]     ; read a word from the chip
  394.         and     ax, 8080h       ; mask out the DQ7 bit
  395.         cmp     ax, bx          ; is DQ7 still complementing?
  396.         jne     CDP_Tog2

  397.         pop     bx              ; restore registers
  398.         pop     ax

  399.         ret

  400. Check_Data_Polling      endp
复制代码



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏1 分享分享 支持支持 反对反对
沙发
发表于 2012-10-29 09:14:47 | 只看该作者
这是官网上面copy 的吗
板凳
发表于 2013-9-22 10:48:21 | 只看该作者
mark!         
地板
发表于 2014-5-24 15:36:34 | 只看该作者
官网会给烧写代码吗?
5#
 楼主| 发表于 2014-5-24 16:04:32 | 只看该作者
这是别人能用的代码,单片机操作该型号芯片
7#
 楼主| 发表于 2014-9-29 15:18:24 | 只看该作者
jy11 发表于 2014-9-29 12:51
c与汇编???

函数实现部分都是汇编的
8#
发表于 2014-10-17 17:27:40 | 只看该作者
真牛 ,也不 晕 。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|文字版|手机版|DIY编程器网 ( 桂ICP备14005565号-1 )

GMT+8, 2024-4-21 00:30 , 耗时 0.098423 秒, 17 个查询请求 , Gzip 开启.

各位嘉宾言论仅代表个人观点,非属DIY编程器网立场。

桂公网安备 45031202000115号

DIY编程器群(超员):41210778 DIY编程器

DIY编程器群1(满员):3044634 DIY编程器1

diy编程器群2:551025008 diy编程器群2

QQ:28000622;Email:libyoufer@sina.com

本站由桂林市临桂区技兴电子商务经营部独家赞助。旨在技术交流,请自觉遵守国家法律法规,一旦发现将做封号删号处理。

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