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

📄 f06x_spi0_eeprom_polled_mode.lst

📁 // This program accesses a SPI EEPROM using polled mode access. The F06x MCU // is configured in 4-
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V8.08   F06X_SPI0_EEPROM_POLLED_MODE                                          01/31/2008 14:21:16 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE F06X_SPI0_EEPROM_POLLED_MODE
OBJECT MODULE PLACED IN F06x_SPI0_EEPROM_Polled_Mode.OBJ
COMPILER INVOKED BY: C:\SiLabs\MCU\IDEfiles\C51\BIN\C51.exe F06x_SPI0_EEPROM_Polled_Mode.c DB OE

line level    source

   1          //-----------------------------------------------------------------------------
   2          // F06x_SPI_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 'F06x 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 'F06x MCU are shown here:
  14          //
  15          // P0.0 - UART TXD   (digital output, push-pull)
  16          // P0.1 - UART RXD   (digital input, open-drain)
  17          // P0.2 - SPI SCK    (digital output, push-pull)
  18          // P0.3 - SPI MISO   (digital input, open-drain)
  19          // P0.4 - SPI MOSI   (digital output, push-pull)
  20          // P0.5 - SPI NSS    (digital output, push-pull)
  21          // P1.6 - LED        (digital output, push-pull)
  22          //
  23          //
  24          // How To Test:
  25          //
  26          // Method1:
  27          // 1) Download the code to a 'F06x 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 'F06x 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:         C8051F06x
  46          // Tool chain:     Keil C51 7.50 / Keil EVAL C51
  47          // Command Line:   None
  48          //
  49          // Release 1.0
  50          //    -Initial Revision (PKC / TP)
  51          //    -25 JULY 2006
  52          //
  53          
  54          //-----------------------------------------------------------------------------
  55          // Includes
C51 COMPILER V8.08   F06X_SPI0_EEPROM_POLLED_MODE                                          01/31/2008 14:21:16 PAGE 2   

  56          //-----------------------------------------------------------------------------
  57          #include <C8051F060.h>                 // SFR declarations
  58          #include <stdio.h>                     // printf is declared here
  59          
  60          //-----------------------------------------------------------------------------
  61          // 16-bit SFR Definitions for the 'F06x
  62          //-----------------------------------------------------------------------------
  63          sfr16 TMR2     = 0xCC;                 // Timer2 low and high bytes together
  64          
  65          //-----------------------------------------------------------------------------
  66          // User-defined types, structures, unions etc
  67          //-----------------------------------------------------------------------------
  68          #ifndef BYTE
  69          #define BYTE unsigned char
  70          #endif
  71          
  72          #ifndef UINT
  73          #define UINT unsigned int
  74          #endif
  75          
  76          //-----------------------------------------------------------------------------
  77          // Global Constants
  78          //-----------------------------------------------------------------------------
  79          #define BAUDRATE           115200      // Baud rate of UART in bps
  80          #define SYSCLK             24500000    // Internal oscillator frequency in Hz
  81          
  82          // Microchip 25AA320 Slave EEPROM Parameters
  83          #define  F_SCK_MAX         1450000     // Max SCK freq (Hz)
  84          #define  T_NSS_DISABLE_MIN 500         // Min NSS disable time (ns)
  85          #define  EEPROM_CAPACITY   4096        // EEPROM capacity (bytes)
  86          
  87          // EEPROM Instruction Set
  88          #define  EEPROM_CMD_READ   0x03        // Read Command
  89          #define  EEPROM_CMD_WRITE  0x02        // Write Command
  90          #define  EEPROM_CMD_WRDI   0x04        // Reset Write Enable Latch Command
  91          #define  EEPROM_CMD_WREN   0x06        // Set Write Enable Latch Command
  92          #define  EEPROM_CMD_RDSR   0x05        // Read Status Register Command
  93          #define  EEPROM_CMD_WRSR   0x01        // Write Status Register Command
  94          
  95          sbit LED = P1^6;                       // LED='1' means ON
  96          sbit SW1 = P3^7;                       // SW1='0' means switch pressed (unused)
  97          
  98          //-----------------------------------------------------------------------------
  99          // Function Prototypes
 100          //-----------------------------------------------------------------------------
 101          // The following functions DO NOT save and restore SFRPAGE:
 102          void Reset_Sources_Init (void);
 103          void OSCILLATOR_Init (void);
 104          void PORT_Init (void);
 105          void TIMER2_Init (void);
 106          void UART0_Init (void);
 107          void SPI0_Init (void);
 108          void Init_Device (void);
 109          
 110          // The following functions save and restore SFRPAGE:
 111          void Delay_us (BYTE time_us);
 112          void Delay_ms (BYTE time_ms);
 113          void EEPROM_Write (UINT address, BYTE value);
 114          BYTE EEPROM_Read (UINT address);
 115          
 116          //-----------------------------------------------------------------------------
 117          // main() Routine
C51 COMPILER V8.08   F06X_SPI0_EEPROM_POLLED_MODE                                          01/31/2008 14:21:16 PAGE 3   

 118          //-----------------------------------------------------------------------------
 119          void main (void)
 120          {
 121   1         UINT  address;                      // EEPROM address
 122   1         BYTE  test_byte;                    // Used as a temporary variable
 123   1      
 124   1         Init_Device ();                     // Initializes hardware peripherals
 125   1      
 126   1         // The following code will test the EEPROM by performing write/read/verify
 127   1         // operations. The first test will write 0xFFs to the EEPROM, and the
 128   1         // second test will write the LSBs of the EEPROM addresses.
 129   1      
 130   1         SFRPAGE = UART0_PAGE;               // Set to page0 for printf via UART0
 131   1                                             // LED on P1.6 is on all pages.
 132   1      
 133   1         // Fill EEPROM with 0xFF's
 134   1         LED = 1;
 135   1         printf("Filling with 0xFF's...\n");
 136   1         for (address = 0; address < EEPROM_CAPACITY; address++)
 137   1         {
 138   2            test_byte = 0xFF;
 139   2            EEPROM_Write (address, test_byte);
 140   2      
 141   2            // Print status to UART0
 142   2            if ((address % 16) == 0)
 143   2            {
 144   3               printf ("\nWriting 0x%04x: %02x ", address, (UINT)test_byte);
 145   3               LED = ~LED;
 146   3            }
 147   2            else
 148   2               printf ("%02x ", (UINT)test_byte);
 149   2         }
 150   1      
 151   1         // Verify EEPROM with 0xFF's
 152   1         printf("\n\nVerifying 0xFF's...\n");
 153   1         for (address = 0; address < EEPROM_CAPACITY; address++)
 154   1         {
 155   2            test_byte = EEPROM_Read (address);
 156   2      
 157   2            // Print status to UART0
 158   2            if ((address % 16) == 0)
 159   2            {
 160   3               printf ("\nVerifying 0x%04x: %02x ", address, (UINT)test_byte);
 161   3               LED = ~LED;
 162   3            }
 163   2            else
 164   2               printf ("%02x ", (UINT)test_byte);
 165   2            if (test_byte != 0xFF)
 166   2            {
 167   3               LED = 0;
 168   3               printf ("Error at %u\n", address);
 169   3               while (1);                    // Stop here on error (for debugging)
 170   3            }
 171   2         }
 172   1      
 173   1         // Fill EEPROM with LSB of EEPROM addresses
 174   1         printf("\n\nFilling with LSB of EEPROM addresses...\n");
 175   1         for (address = 0; address < EEPROM_CAPACITY; address++)
 176   1         {
 177   2            test_byte = address & 0xFF;
 178   2            EEPROM_Write (address, test_byte);
 179   2      
C51 COMPILER V8.08   F06X_SPI0_EEPROM_POLLED_MODE                                          01/31/2008 14:21:16 PAGE 4   

 180   2            // Print status to UART0
 181   2            if ((address % 16) == 0)
 182   2            {
 183   3               printf ("\nWriting 0x%04x: %02x ", address, (UINT)test_byte);
 184   3               LED = ~LED;
 185   3            }
 186   2            else
 187   2               printf ("%02x ", (UINT)test_byte);
 188   2         }
 189   1      
 190   1         // Verify EEPROM with LSB of EEPROM addresses
 191   1         printf("\n\nVerifying LSB of EEPROM addresses...\n");
 192   1         for (address = 0; address < EEPROM_CAPACITY; address++)
 193   1         {
 194   2            test_byte = EEPROM_Read (address);
 195   2      

⌨️ 快捷键说明

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