⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fm25h20.lst

📁 FPGA和MCU的并口通信 及MCU和E2PROM(FM25H20)SPI通信
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   FM25H20                                                               11/27/2008 11:07:27 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE FM25H20
OBJECT MODULE PLACED IN FM25H20.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE FM25H20.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          //-----------------------------------------------------------------------------
   2          // F31x_SPI0_EEPROM_Polled_Mode.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright 2006 Silicon Laboratories, Inc.
   5          // http://www.silabs.com
   6          //
   7          // Program Description:
   8          //
   9          // This program accesses a SPI EEPROM using polled mode access. The 'F31x MCU 
  10          // is configured in 4-wire Single Master Mode, and the EEPROM is the only 
  11          // slave device connected to the SPI bus. The read/write operations are 
  12          // tailored to access a Microchip 4 kB EEPROM 25LC320. The relevant hardware 
  13          // connections of the 'F31x MCU are shown here:
  14          // 
  15          // P0.0 - SPI SCK    (digital output, push-pull)
  16          // P0.1 - SPI MISO   (digital input, open-drain)
  17          // P0.2 - SPI MOSI   (digital output, push-pull)
  18          // P0.3 - SPI NSS    (digital output, push-pull)
  19          // P0.4 - UART TXD   (digital output, push-pull)
  20          // P0.5 - UART RXD   (digital input, open-drain)
  21          // P3.3 - LED        (digital output, push-pull)
  22          //
  23          //
  24          // How To Test:
  25          //
  26          // Method1:
  27          // 1) Download the code to a 'F31x device that is connected as above.
  28          // 2) Run the code. The LED will blink fast during the write/read/verify 
  29          //    operations.
  30          // 3) If the verification passes, the LED will blink slowly. If it fails,
  31          //    the LED will be OFF.
  32          //
  33          // Method2 (optional):
  34          // 1) Download code to a 'F31x device that is connected as above, and 
  35          //    also connected to a RS232 transceiver.
  36          // 2) Connect a straight serial cable from the RS232 transceiver to a PC.
  37          // 3) On the PC, open HyperTerminal (or any other terminal program) and connect
  38          //    to the COM port at <BAUDRATE> and 8-N-1
  39          // 4) HyperTerminal will print the progress of the write/read operation, and in 
  40          //    the end will print the test result as pass or fail. Additionally, if the 
  41          //    verification passes, the LED will blink slowly. If it fails, the LED will 
  42          //    be OFF.
  43          //
  44          //
  45          // Target:         C8051F31x
  46          // Tool chain:     Keil C51 7.50 / Keil EVAL C51
  47          // Command Line:   None
  48          //
  49          // Release 1.0
  50          //    -Initial Revision (PKC)
  51          //    -18 MAY 2006
  52          //
  53          
  54          //-----------------------------------------------------------------------------
  55          // Includes
C51 COMPILER V7.50   FM25H20                                                               11/27/2008 11:07:27 PAGE 2   

  56          //-----------------------------------------------------------------------------
  57          #include <C8051F310.h>                 // SFR declarations
  58          #include <stdio.h>                     // printf is declared here
  59          #include"mcu.h"
  60          //-----------------------------------------------------------------------------
  61          // 16-bit SFR Definitions for the 'F31x
  62          //-----------------------------------------------------------------------------
  63          sfr16 TMR2     = 0xCC;                 // Timer2 low and high bytes together
  64          
  65          //-----------------------------------------------------------------------------
  66          // User-defined types, structures, unions etc
  67          //-----------------------------------------------------------------------------
  68          
  69          
  70          //-----------------------------------------------------------------------------
  71          // main() Routine
  72          //-----------------------------------------------------------------------------
  73          /*void WR (void)
  74          {
  75             UINT  address;                      // EEPROM address
  76             BYTE  test_byte;                    // Used as a temporary variable
  77             
  78                                 // Initializes hardware peripherals
  79             
  80             
  81             // The following code will test the EEPROM by performing write/read/verify
  82             // operations. The first test will write 0xFFs to the EEPROM, and the 
  83             // second test will write the LSBs of the EEPROM addresses.
  84          
  85             // Fill EEPROM with 0xFF's
  86             //LED = 1;
  87            // printf("Filling with 0xFF's...\n");
  88             for (address = 0; address < EEPROM_CAPACITY; address++)
  89             {
  90                test_byte = P2;
  91                EEPROM_Write (address, test_byte);
  92          
  93                // Print status to UART0
  94                /*if ((address % 16) == 0)
  95                {
  96                   printf ("\nWriting 0x%04x: %02x ", address, (UINT)test_byte);
  97                   LED = ~LED;
  98                }
  99                else
 100                   printf ("%02x ", (UINT)test_byte); */
 101          //   }
 102          
 103             // Verify EEPROM with 0xFF's
 104             //printf("\n\nVerifying 0xFF's...\n");
 105            
 106            /* for (address = 0; address < EEPROM_CAPACITY; address++)
 107             {
 108                test_byte = EEPROM_Read (address);
 109          
 110                // Print status to UART0
 111                /*if ((address % 16) == 0)
 112                {
 113                   printf ("\nVerifying 0x%04x: %02x ", address, (UINT)test_byte);
 114                   LED = ~LED;
 115                }
 116                else
 117                   printf ("%02x ", (UINT)test_byte);
C51 COMPILER V7.50   FM25H20                                                               11/27/2008 11:07:27 PAGE 3   

 118                           */
 119                //if (test_byte == 0x3FFFF)
 120                 //  break;//{
 121                  // LED = 0;
 122                   //printf ("Error at %u\n", address);
 123                   //while (1);                    // Stop here on error (for debugging)
 124                //}
 125             //}*/
 126          
 127             // Fill EEPROM with LSB of EEPROM addresses
 128             //printf("\n\nFilling with LSB of EEPROM addresses...\n");
 129            // for (address = 0; address < EEPROM_CAPACITY; address++)
 130            // {
 131              //  test_byte = address & 0xFF;
 132              //  EEPROM_Write (address, test_byte);
 133          
 134                // Print status to UART0
 135               /* if ((address % 16) == 0)
 136                {
 137                   printf ("\nWriting 0x%04x: %02x ", address, (UINT)test_byte);
 138                   LED = ~LED;
 139                }
 140                else
 141                   printf ("%02x ", (UINT)test_byte);*/
 142          //   }
 143          
 144             // Verify EEPROM with LSB of EEPROM addresses
 145            // printf("\n\nVerifying LSB of EEPROM addresses...\n");
 146             /*for (address = 0; address < EEPROM_CAPACITY; address++)
 147             {
 148                test_byte = EEPROM_Read (address);
 149          
 150                // print status to UART0
 151               /* if ((address % 16) == 0)
 152                {
 153                   printf ("\nVerifying 0x%04x: %02x ", address, (UINT)test_byte);
 154                   LED = ~LED;
 155                }
 156                else
 157                   printf ("%02x ", (UINT)test_byte);
 158                
 159                if (test_byte != (address & 0xFF))
 160                {
 161                   LED = 0;
 162                   printf ("Error at %u\n", address);
 163                   while (1);                    // Stop here on error (for debugging)
 164                }
 165             }
 166          */
 167            // printf ("\n\nVerification success!\n");
 168             
 169            /* while (1)                           // Loop forever
 170             {                                   
 171                LED = ~LED;                      // Flash LED when done (all verified)
 172                Delay_ms (200);
 173             }*/
 174          
 175          //-----------------------------------------------------------------------------
 176          // Initialization Subroutines
 177          //-----------------------------------------------------------------------------
 178          
 179          //-----------------------------------------------------------------------------
C51 COMPILER V7.50   FM25H20                                                               11/27/2008 11:07:27 PAGE 4   

 180          // PCA0_Init
 181          //-----------------------------------------------------------------------------
 182          //
 183          // Return Value : None
 184          // Parameters   : None
 185          //
 186          // This function disables the watchdog timer.
 187          //
 188          //-----------------------------------------------------------------------------
 189          void PCA0_Init (void)
 190          {
 191   1         PCA0MD   &= ~0x40;
 192   1         PCA0MD    = 0x00;
 193   1      }
 194          
 195          //-----------------------------------------------------------------------------
 196          // OSCILLATOR_Init
 197          //-----------------------------------------------------------------------------
 198          //
 199          // Return Value : None
 200          // Parameters   : None
 201          //
 202          // This function initializes the system clock to use the internal oscillator
 203          // at 24.5 MHz.
 204          //
 205          //-----------------------------------------------------------------------------
 206          void OSCILLATOR_Init (void)
 207          {
 208   1         OSCICN   = 0x83;
 209   1      }
 210          
 211          //-----------------------------------------------------------------------------
 212          // PORT_Init
 213          //-----------------------------------------------------------------------------
 214          //
 215          // Return Value : None
 216          // Parameters   : None
 217          //
 218          // This function configures the crossbar and GPIO ports.
 219          //
 220          // P0.0  -  SCK  (SPI0), Push-Pull,  Digital
 221          // P0.1  -  MISO (SPI0), Open-Drain, Digital
 222          // P0.2  -  MOSI (SPI0), Push-Pull,  Digital
 223          // P0.3  -  NSS  (SPI0), Push-Pull,  Digital
 224          // P0.4  -  TX0 (UART0), Push-Pull,  Digital
 225          // P0.5  -  RX0 (UART0), Open-Drain, Digital
 226          // P0.6  -  Unassigned,  Open-Drain, Digital
 227          // P0.7  -  Skipped,     Open-Drain, Digital (Switch S2 on Target Board)
 228          
 229          // P1.0  -  Unassigned,  Open-Drain, Digital
 230          // P1.1  -  Unassigned,  Open-Drain, Digital
 231          // P1.2  -  Unassigned,  Open-Drain, Digital
 232          // P1.3  -  Unassigned,  Open-Drain, Digital
 233          // P1.4  -  Unassigned,  Open-Drain, Digital
 234          // P1.5  -  Unassigned,  Open-Drain, Digital
 235          // P1.6  -  Unassigned,  Open-Drain, Digital
 236          // P1.7  -  Unassigned,  Open-Drain, Digital
 237          // P2.0  -  Unassigned,  Open-Drain, Digital
 238          // P2.1  -  Unassigned,  Open-Drain, Digital
 239          // P2.2  -  Unassigned,  Open-Drain, Digital
 240          // P2.3  -  Unassigned,  Open-Drain, Digital
 241          //
C51 COMPILER V7.50   FM25H20                                                               11/27/2008 11:07:27 PAGE 5   

 242          // P3.3  -  LED,         Push-Pull,  Digital
 243          //
 244          //-----------------------------------------------------------------------------
 245          void PORT_Init (void)
 246          {
 247   1         P0MDOUT   = 0xc1;
 248   1         P0SKIP    = 0x00;
 249   1         //P3MDOUT   = 0x08;
 250   1         XBR0      = 0x02;
 251   1         XBR1      = 0x40;
 252   1      }
 253          
 254          //-----------------------------------------------------------------------------
 255          // TIMER2_Init
 256          //-----------------------------------------------------------------------------
 257          //
 258          // Return Value : None
 259          // Parameters   : None
 260          //
 261          // Initializes Timer2 to be clocked by SYSCLK for use as a delay timer.
 262          //
 263          //-----------------------------------------------------------------------------
 264          void TIMER2_Init (void)
 265          {
 266   1         CKCON    |= 0x10;
 267   1      }
 268          
 269          //-----------------------------------------------------------------------------
 270          // UART0_Init
 271          //-----------------------------------------------------------------------------
 272          //
 273          // Return Value : None
 274          // Parameters   : None
 275          //
 276          // Configures the UART0 using Timer1, for <BAUDRATE> and 8-N-1. Once this is
 277          // set up, the standard printf function can be used to output data.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -