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

📄 f06x_spi0_slave.lst

📁 // This program accesses a SPI EEPROM using polled mode access. The F06x MCU // is configured in 4-
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.08   F06X_SPI0_SLAVE                                                       12/30/2007 08:45:23 PAGE 1   


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

line level    source

   1          //-----------------------------------------------------------------------------
   2          // F06x_SPI0_Slave.c
   3          //-----------------------------------------------------------------------------
   4          // Copyright 2006 Silicon Laboratories, Inc.
   5          // http://www.silabs.com
   6          //
   7          // Program Description:
   8          //
   9          // This program configures a C8051F06x as a SPI Slave. The 'F06x MCU
  10          // is configured in 4-wire Slave Mode.
  11          //
  12          // This example is intended to be used with the SPI0_Master example.
  13          //
  14          // Pinout:
  15          //
  16          // P0.0 - SPI SCK    (digital input, open-drain)
  17          // P0.1 - SPI MISO   (digital output, push-pull)
  18          // P0.2 - SPI MOSI   (digital input, open-drain)
  19          // P0.3 - SPI NSS    (digital input, open-drain)
  20          //
  21          // P1.6 - LED        (digital output, push-pull)
  22          //
  23          // all other port pins unused.
  24          //
  25          //
  26          // How To Test:
  27          //
  28          // 1) Download the code to a F060-TB that is connected as above to
  29          //    another device running the SPI0_Master code.
  30          // 2) Verify that the J3 jumper is populated.
  31          // 3) Run the code.
  32          // 4) If the communication passes, the LEDs on both the Master and Slave
  33          //    boards will blink slowly. If it fails, the LEDs will be OFF.
  34          //
  35          //
  36          // Target:         C8051F06x
  37          // Tool chain:     Keil C51 7.50 / Keil EVAL C51
  38          // Command Line:   None
  39          //
  40          // Release 1.0
  41          //    -Initial Revision (TP)
  42          //    -14 DEC 2006
  43          //
  44          
  45          //-----------------------------------------------------------------------------
  46          // Includes
  47          //-----------------------------------------------------------------------------
  48          
  49          #include <C8051F060.h>                 // SFR declarations
  50          
  51          //-----------------------------------------------------------------------------
  52          // Global Constants
  53          //-----------------------------------------------------------------------------
  54          
  55          #define SYSCLK             24500000    // Internal oscillator frequency in Hz
C51 COMPILER V8.08   F06X_SPI0_SLAVE                                                       12/30/2007 08:45:23 PAGE 2   

  56          
  57          #define MAX_BUFFER_SIZE    8           // Maximum buffer Master will send
  58          
  59          // Instruction Set
  60          #define  SLAVE_LED_ON      0x01        // Turn the Slave LED on
  61          #define  SLAVE_LED_OFF     0x02        // Turn the Slave LED off
  62          #define  SPI_WRITE         0x04        // Send a byte from the Master to the
  63                                                 // Slave
  64          #define  SPI_READ          0x08        // Send a byte from the Slave to the
  65                                                 // Master
  66          #define  SPI_WRITE_BUFFER  0x10        // Send a series of bytes from the
  67                                                 // Master to the Slave
  68          #define  SPI_READ_BUFFER   0x20        // Send a series of bytes from the Slave
  69                                                 // to the Master
  70          #define  ERROR_OCCURRED    0x40        // Indicator for the Slave to tell the
  71                                                 // Master an error occurred
  72          
  73          sbit LED = P1^6;                       // LED='1' means ON
  74          
  75          //-----------------------------------------------------------------------------
  76          // Global Variables
  77          //-----------------------------------------------------------------------------
  78          
  79          unsigned char SPI_Data = 0xA5;
  80          
  81          unsigned char SPI_Data_Array[MAX_BUFFER_SIZE] = {0};
  82          
  83          //-----------------------------------------------------------------------------
  84          // Function Prototypes
  85          //-----------------------------------------------------------------------------
  86          
  87          void Watchdog_Init (void);
  88          void Oscillator_Init (void);
  89          void Port_Init (void);
  90          void SPI0_Init (void);
  91          void Init_Device (void);
  92          
  93          //-----------------------------------------------------------------------------
  94          // main() Routine
  95          //-----------------------------------------------------------------------------
  96          void main (void)
  97          {
  98   1         Init_Device ();                     // Initializes hardware peripherals
  99   1      
 100   1         EA = 1;                             // Enable global interrupts
 101   1      
 102   1         LED = 0;
 103   1      
 104   1         while (1);                          // Loop forever
 105   1      }
 106          
 107          //-----------------------------------------------------------------------------
 108          // Initialization Subroutines
 109          //-----------------------------------------------------------------------------
 110          
 111          //-----------------------------------------------------------------------------
 112          // Watchdog_Init
 113          //-----------------------------------------------------------------------------
 114          //
 115          // Return Value : None
 116          // Parameters   : None
 117          //
C51 COMPILER V8.08   F06X_SPI0_SLAVE                                                       12/30/2007 08:45:23 PAGE 3   

 118          // This function disables the watchdog timer.
 119          //
 120          //-----------------------------------------------------------------------------
 121          void Watchdog_Init (void)
 122          {
 123   1         unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE
 124   1      
 125   1         SFRPAGE = CONFIG_PAGE;              // Switch to the necessary SFRPAGE
 126   1      
 127   1         WDTCN     = 0xDE;                   // Disable the Watchdog Timer
 128   1         WDTCN     = 0xAD;
 129   1      
 130   1         SFRPAGE = SFRPAGE_save;             // Restore the SFRPAGE
 131   1      }
 132          
 133          //-----------------------------------------------------------------------------
 134          // Oscillator_Init
 135          //-----------------------------------------------------------------------------
 136          //
 137          // Return Value : None
 138          // Parameters   : None
 139          //
 140          // This function initializes the system clock to use the internal oscillator
 141          // at 24.5 MHz.
 142          //
 143          //-----------------------------------------------------------------------------
 144          void Oscillator_Init (void)
 145          {
 146   1         unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE
 147   1      
 148   1         SFRPAGE = CONFIG_PAGE;              // Switch to the necessary SFRPAGE
 149   1      
 150   1         OSCICN = 0x83;                      // Set the internal oscillator to
 151   1                                             // 24.5 MHz
 152   1      
 153   1         SFRPAGE = SFRPAGE_save;             // Restore the SFRPAGE
 154   1      }
 155          
 156          //-----------------------------------------------------------------------------
 157          // Port_Init
 158          //-----------------------------------------------------------------------------
 159          //
 160          // Return Value : None
 161          // Parameters   : None
 162          //
 163          // This function configures the crossbar and GPIO ports.
 164          //
 165          // P0.0  -  SCK  (SPI0), Open-Drain, Digital
 166          // P0.1  -  MISO (SPI0), Push-Pull,  Digital
 167          // P0.2  -  MOSI (SPI0), Open-Drain, Digital
 168          // P0.3  -  NSS  (SPI0), Open-Drain, Digital
 169          //
 170          // P1.6  -  LED,         Push-Pull,  Digital (LED D3 on Target Board)
 171          //
 172          //-----------------------------------------------------------------------------
 173          void PORT_Init (void)
 174          {
 175   1         unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE
 176   1      
 177   1         SFRPAGE = CONFIG_PAGE;              // Switch to the necessary SFRPAGE
 178   1      
 179   1         P0MDOUT = 0x02;                     // Make MISO push-pull
C51 COMPILER V8.08   F06X_SPI0_SLAVE                                                       12/30/2007 08:45:23 PAGE 4   

 180   1         P1MDOUT = 0x40;                     // Make the LED push-pull
 181   1      
 182   1         XBR0 = 0x02;                        // Enable the SPI on the XBAR
 183   1         XBR2 = 0x40;                        // Enable the XBAR and weak pull-ups
 184   1      
 185   1         SFRPAGE = SFRPAGE_save;             // Restore the SFRPAGE
 186   1      }
 187          
 188          //-----------------------------------------------------------------------------
 189          // SPI0_Init
 190          //-----------------------------------------------------------------------------
 191          //
 192          // Return Value : None
 193          // Parameters   : None
 194          //
 195          // Configures SPI0 to use 4-wire Slave mode. The SPI timing is
 196          // configured for Mode 0,0 (data centered on first edge of clock phase and
 197          // SCK line low in idle state).
 198          //
 199          //-----------------------------------------------------------------------------
 200          void SPI0_Init()
 201          {
 202   1         unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE
 203   1      
 204   1         SFRPAGE = SPI0_PAGE;                // Switch to the necessary SFRPAGE
 205   1      
 206   1         SPI0CFG = 0x00;                     // Operate in Slave mode
 207   1                                             // CKPHA = '0', CKPOL = '0'
 208   1         SPI0CN = 0x05;                      // 4-wire Slave mode, SPI enabled
 209   1      
 210   1         EIE1 |= 0x01;                       // Enable SPI interrupts
 211   1      
 212   1         SFRPAGE = SFRPAGE_save;             // Restore the SFRPAGE
 213   1      }

⌨️ 快捷键说明

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