亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? f12x_spi0_slave.c

?? 基于C8051F120的SPI總線實現代碼
?? C
字號:
//-----------------------------------------------------------------------------
// F12x_SPI0_Slave.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This program configures a C8051F12x as a SPI Slave. The 'F12x MCU
// is configured in 4-wire Slave Mode.
//
// This example is intended to be used with the SPI0_Master example.
//
// Pinout:
//
// P0.0 - SPI SCK    (digital input, open-drain)
// P0.1 - SPI MISO   (digital output, push-pull)
// P0.2 - SPI MOSI   (digital input, open-drain)
// P0.3 - SPI NSS    (digital input, open-drain)
//
// P1.6 - LED        (digital output, push-pull)
//
// all other port pins unused.
//
//
// How To Test:
//
// 1) Download the code to a F120-TB that is connected as above to
//    another device running the SPI0_Master code.
// 2) Verify that the J3 jumper is populated.
// 3) Run the code.
// 4) If the communication passes, the LEDs on both the Master and Slave
//    boards will blink slowly. If it fails, the LEDs will be OFF.
//
//
// Target:         C8051F12x
// Tool chain:     Keil C51 7.50 / Keil EVAL C51
// Command Line:   None
//
// Release 1.0
//    -Initial Revision (TP)
//    -14 DEC 2006
//

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

#include <C8051F120.h>                 // SFR declarations

//-----------------------------------------------------------------------------
// Global Constants
//-----------------------------------------------------------------------------

#define SYSCLK             24500000    // Internal oscillator frequency in Hz

#define MAX_BUFFER_SIZE    8           // Maximum buffer Master will send

// Instruction Set
#define  SLAVE_LED_ON      0x01        // Turn the Slave LED on
#define  SLAVE_LED_OFF     0x02        // Turn the Slave LED off
#define  SPI_WRITE         0x04        // Send a byte from the Master to the
                                       // Slave
#define  SPI_READ          0x08        // Send a byte from the Slave to the
                                       // Master
#define  SPI_WRITE_BUFFER  0x10        // Send a series of bytes from the
                                       // Master to the Slave
#define  SPI_READ_BUFFER   0x20        // Send a series of bytes from the Slave
                                       // to the Master
#define  ERROR_OCCURRED    0x40        // Indicator for the Slave to tell the
                                       // Master an error occurred

sbit LED = P1^6;                       // LED='1' means ON

//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------

unsigned char SPI_Data = 0xA5;

unsigned char SPI_Data_Array[MAX_BUFFER_SIZE] = {0};

//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------

void Watchdog_Init (void);
void Oscillator_Init (void);
void Port_Init (void);
void SPI0_Init (void);
void Init_Device (void);

//-----------------------------------------------------------------------------
// main() Routine
//-----------------------------------------------------------------------------
void main (void)
{
   Init_Device ();                     // Initializes hardware peripherals

   EA = 1;                             // Enable global interrupts

   LED = 0;

   while (1);                          // Loop forever
}

//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Watchdog_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function disables the watchdog timer.
//
//-----------------------------------------------------------------------------
void Watchdog_Init (void)
{
   unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE

   SFRPAGE = CONFIG_PAGE;              // Switch to the necessary SFRPAGE

   WDTCN     = 0xDE;                   // Disable the Watchdog Timer
   WDTCN     = 0xAD;

   SFRPAGE = SFRPAGE_save;             // Restore the SFRPAGE
}

//-----------------------------------------------------------------------------
// Oscillator_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function initializes the system clock to use the internal oscillator
// at 24.5 MHz.
//
//-----------------------------------------------------------------------------
void Oscillator_Init (void)
{
   unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE

   SFRPAGE = CONFIG_PAGE;              // Switch to the necessary SFRPAGE

   OSCICN = 0x83;                      // Set the internal oscillator to
                                       // 24.5 MHz

   SFRPAGE = SFRPAGE_save;             // Restore the SFRPAGE
}

//-----------------------------------------------------------------------------
// Port_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function configures the crossbar and GPIO ports.
//
// P0.0  -  SCK  (SPI0), Open-Drain, Digital
// P0.1  -  MISO (SPI0), Push-Pull,  Digital
// P0.2  -  MOSI (SPI0), Open-Drain, Digital
// P0.3  -  NSS  (SPI0), Open-Drain, Digital
//
// P1.6  -  LED,         Push-Pull,  Digital (LED D3 on Target Board)
//
//-----------------------------------------------------------------------------
void PORT_Init (void)
{
   unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE

   SFRPAGE = CONFIG_PAGE;              // Switch to the necessary SFRPAGE

   P0MDOUT = 0x02;                     // Make MISO push-pull
   P1MDOUT = 0x40;                     // Make the LED push-pull

   XBR0 = 0x02;                        // Enable the SPI on the XBAR
   XBR2 = 0x40;                        // Enable the XBAR and weak pull-ups

   SFRPAGE = SFRPAGE_save;             // Restore the SFRPAGE
}

//-----------------------------------------------------------------------------
// SPI0_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Configures SPI0 to use 4-wire Slave mode. The SPI timing is
// configured for Mode 0,0 (data centered on first edge of clock phase and
// SCK line low in idle state).
//
//-----------------------------------------------------------------------------
void SPI0_Init()
{
   unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE

   SFRPAGE = SPI0_PAGE;                // Switch to the necessary SFRPAGE

   SPI0CFG = 0x00;                     // Operate in Slave mode
                                       // CKPHA = '0', CKPOL = '0'
   SPI0CN = 0x05;                      // 4-wire Slave mode, SPI enabled

   EIE1 |= 0x01;                       // Enable SPI interrupts

   SFRPAGE = SFRPAGE_save;             // Restore the SFRPAGE
}

//-----------------------------------------------------------------------------
// Init_Device
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Calls all device initialization functions.
//
//-----------------------------------------------------------------------------
void Init_Device (void)
{
   Watchdog_Init ();                       // Disable the Watchdog Timer first
   Oscillator_Init ();
   Port_Init ();
   SPI0_Init ();
}

//-----------------------------------------------------------------------------
// Interrupt Service Routines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// SPI_ISR
//-----------------------------------------------------------------------------
//
// Handles all incoming data and interprets the commands sent from the Master.
//
// Typical Write:
//
//              | 1st sent | 2nd sent | 3rd sent |   ...    | last sent |
//              ---------------------------------------------------------
//  Master NSSv | Command  |   Data1  |   Data2  |   ...    |   DataN   |  NSS^
//  Slave       |   N/A    |    N/A   |    N/A   |   ...    |    N/A    |
//
// Typical Read:
//
//              | 1st sent | 2nd sent | 3rd sent |   ...    | last sent |
//              ---------------------------------------------------------
//  Master NSSv | Command  |   dummy  |   dummy  |   ...    |   dummy   |  NSS^
//  Slave       |   N/A    |   Data1  |   Data2  |   ...    |   DataN   |
//-----------------------------------------------------------------------------
void SPI_ISR (void) interrupt 6
{
   static unsigned char command;
   static unsigned char array_index = 0;
   static unsigned char state = 0;
   unsigned char dummy_byte;

   if (WCOL == 1)
   {
      // Write collision occurred

      SPI0DAT = ERROR_OCCURRED;        // Indicate an error occurred
      WCOL = 0;                        // Clear the Write collision flag
   }
   else if (RXOVRN == 1)
   {
      // Receive overrun occurred

      SPI0DAT = ERROR_OCCURRED;        // Indicate an error occurred
      RXOVRN = 0;                      // Clear the Receive Overrun flag
   }
   else
   {
      // SPIF caused the interrupt

      // Some commands are single-byte commands (SLAVE_LED_ON/SLAVE_LED_OFF)
      // For multiple-byte commands, use the state to determine action
      // <state> == 0: new transfer; a command is being received
      // <state> == 1: writing/reading data
      if (state == 0)
      {
         command = SPI0DAT;            // Read the command

         array_index = 0;              // Reset the array index

         switch (command)
         {
            case SLAVE_LED_ON:
               LED = 1;
               state = 0;              // End of transfer (no bytes to send)

               break;

            case SLAVE_LED_OFF:
               LED = 0;
               state = 0;              // End of transfer (no bytes to send)

               break;

            case SPI_WRITE:
               state = 1;              // Do nothing
                                       // Move to State 1 to read data from
                                       // Master

               break;

            case SPI_READ:
               SPI0DAT = SPI_Data;     // Immediately load SPI0DAT with the
                                       // data requested by the Master, so the
                                       // Master can receive it at the  end of
                                       // the second transfer.
                                       // Because the slave sends the data
                                       // immediately, the Master's SCK is
                                       // limited to a clock slow enough that
                                       // the Slave has time to respond to a
                                       // read.

               state = 0;              // End of transfer (only one byte)

               break;

            case SPI_WRITE_BUFFER:
               state = 1;              // Do nothing
                                       // Move to State 1 to read data from
                                       // Master

               break;

            case SPI_READ_BUFFER:
               SPI0DAT = SPI_Data_Array[array_index]; // Immediately load
                                       // SPI0DAT with the data requested by
                                       // the Master, so the Master can receive
                                       // it at the end of the second transfer.
                                       // Because the slave sends the data
                                       // immediately, the Master's SCK is
                                       // limited to a clock slow enough that
                                       // the Slave has time to respond to a
                                       // read.

               array_index++;

               state = 1;              // Move to State 1 to continue to send
                                       // data to the Master (multiple bytes).

               break;

            default:
               state = 0;
         }

      }
      else if (state == 1)
      {
         switch (command)
         {
            case SPI_WRITE:
               SPI_Data = SPI0DAT;

               state = 0;              // End of transfer (one byte received)

               break;

            case SPI_WRITE_BUFFER:
               SPI_Data_Array[array_index] = SPI0DAT; // Receive the next byte

               array_index++;

               if (array_index == MAX_BUFFER_SIZE) // Check for last data
               {
                  state = 0;           // Reset the state (end of transfer)
               }
               else
               {
                  state = 1;           // Continue to read in data (more
                                       // bytes to receive)
               }

               break;

            case SPI_READ_BUFFER:
               SPI0DAT = SPI_Data_Array[array_index]; // Send the next byte
               dummy_byte = SPI0DAT;   // Read the dummy data the Master is
                                       // sending from SPI0DAT to prevent a
                                       // RXOVRN (Receive overrun) error

               array_index++;

               if (array_index == MAX_BUFFER_SIZE) // Check for last data
               {
                  state = 0;           // Reset the state (end of transfer)
               }
               else
               {
                  state = 1;           // Continue to send out data (more
                                       // bytes to send)
               }

               break;

            default:
               state = 0;
         }
      }

      SPIF = 0;                        // Clear the SPIF flag
   }
}

//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
蜜臀a∨国产成人精品| 91福利小视频| 成人伦理片在线| av一区二区不卡| 欧美精品一卡两卡| 午夜欧美在线一二页| 国内外精品视频| 一本一本久久a久久精品综合麻豆| 色婷婷激情一区二区三区| 欧美日韩国产a| 久久精品在这里| 亚洲精品国产一区二区精华液| 日韩二区在线观看| 成人福利在线看| 欧美一级爆毛片| 亚洲视频网在线直播| 国产一区二区主播在线| 91国偷自产一区二区三区成为亚洲经典| 欧美一区二区三区白人| 亚洲欧洲美洲综合色网| 精品一区二区三区免费| 久久精品亚洲精品国产欧美kt∨| 亚洲欧洲三级电影| 国产精品白丝jk黑袜喷水| 欧美久久一区二区| 一区二区久久久| gogogo免费视频观看亚洲一| 欧美电影免费提供在线观看| 婷婷夜色潮精品综合在线| 成人黄页在线观看| 欧美激情一区在线| 国产在线精品免费| 精品日韩av一区二区| 蜜桃av一区二区在线观看| 欧美专区日韩专区| 夜夜嗨av一区二区三区网页 | 91免费在线播放| 久久久精品免费网站| 色婷婷av一区二区三区大白胸| 久久久久99精品国产片| 精品一区二区三区不卡| 久久久久久久久岛国免费| 精品午夜一区二区三区在线观看| 日韩视频123| 久草中文综合在线| 亚洲国产成人一区二区三区| 国产精品香蕉一区二区三区| 国产精品网站在线播放| 99r国产精品| 亚洲国产一区二区在线播放| 欧美精品v国产精品v日韩精品| 日产国产欧美视频一区精品| 日韩欧美一二三四区| 国产成人欧美日韩在线电影| 国产精品视频第一区| 日本韩国欧美一区二区三区| 日本视频在线一区| 久久精品男人天堂av| 国产欧美日韩精品一区| av在线播放成人| 婷婷成人综合网| 日本一区二区免费在线| 欧美日韩在线播放三区四区| 久久疯狂做爰流白浆xx| 亚洲日本va在线观看| 欧美va在线播放| 日本韩国精品在线| 国产精品夜夜嗨| 亚洲永久免费av| 国产三级久久久| 亚洲欧美电影院| 国产性天天综合网| 欧美欧美欧美欧美首页| 99久久国产综合精品女不卡| 免费成人在线网站| 亚洲国产精品一区二区www在线| 国产欧美一区二区精品性色超碰| 在线日韩av片| 99精品欧美一区| 国产在线日韩欧美| 美洲天堂一区二卡三卡四卡视频| 一区二区三区.www| 亚洲色图欧洲色图婷婷| 中文字幕精品综合| 久久综合狠狠综合久久激情 | 欧美在线高清视频| 本田岬高潮一区二区三区| 国产精品一区久久久久| 久久国产剧场电影| 裸体健美xxxx欧美裸体表演| 亚洲成人先锋电影| 亚洲成人第一页| 亚洲超碰97人人做人人爱| 一区二区三区高清| 亚洲精品第一国产综合野| 亚洲欧美自拍偷拍| 亚洲精品中文在线影院| 亚洲视频一二三| 一区二区三区蜜桃网| 亚洲图片欧美综合| 日韩和的一区二区| 久久国产夜色精品鲁鲁99| 精品亚洲成a人在线观看 | 在线一区二区视频| 欧美视频精品在线观看| 日韩三级.com| 国产夜色精品一区二区av| 国产精品久久久99| 亚洲一区二区黄色| 国产在线一区二区综合免费视频| 国产一区二区在线视频| 91网页版在线| 91精品福利在线一区二区三区 | 久久综合色天天久久综合图片| 久久久久久久av麻豆果冻| 国产精品人人做人人爽人人添| 亚洲精品你懂的| 久久机这里只有精品| 成人黄色免费短视频| 欧美老人xxxx18| 国产精品久久久久久久久久久免费看 | 捆绑变态av一区二区三区| 国产精品一区二区不卡| 在线免费不卡电影| 久久久久久97三级| 午夜精品一区二区三区电影天堂 | 国产在线精品一区二区不卡了 | 91精品国产色综合久久不卡电影| 国产精品三级视频| 美女诱惑一区二区| 欧美视频第二页| 中文字幕一区在线观看视频| 美女在线一区二区| 欧美伊人久久久久久午夜久久久久| 亚洲精品一区二区三区四区高清| 亚洲欧美另类图片小说| 高清不卡一区二区| 欧美精品一区二区在线观看| 99re热视频精品| 亚洲国产精品激情在线观看| 蜜桃视频在线观看一区| 欧美日韩精品一区二区| 亚洲欧美日本韩国| 99这里只有精品| 国产精品久久综合| www.在线成人| 一区二区三区四区在线免费观看 | 成人av在线播放网址| 欧美国产日韩a欧美在线观看| 国产一区二区电影| 国产欧美精品一区二区色综合朱莉 | 在线中文字幕一区| 亚洲精品日日夜夜| 欧美日韩在线观看一区二区 | 91精品国产色综合久久ai换脸| 五月天一区二区三区| 欧美一区二区三区喷汁尤物| 日韩国产精品大片| 久久久久亚洲蜜桃| 国产91在线|亚洲| 亚洲黄色片在线观看| 欧美日本免费一区二区三区| 美脚の诱脚舐め脚责91 | 美女国产一区二区| 久久久三级国产网站| 成人美女视频在线观看18| 亚洲激情图片qvod| 91麻豆精品国产91久久久使用方法| 久久不见久久见免费视频7| 久久―日本道色综合久久| 粗大黑人巨茎大战欧美成人| 国产一区二区在线影院| 国产精品久久网站| 欧美美女bb生活片| 东方欧美亚洲色图在线| 日韩国产精品久久久久久亚洲| 久久影院视频免费| 色婷婷综合激情| 国内精品免费**视频| 亚洲综合视频在线观看| 欧美激情中文字幕| 91精品国产免费| 91成人网在线| 成人丝袜18视频在线观看| 午夜视频一区二区| 亚洲欧美aⅴ...| 国产欧美日本一区视频| 日韩欧美成人午夜| 在线观看日韩av先锋影音电影院| 国内精品免费在线观看| 国产麻豆午夜三级精品| 日韩一区中文字幕| 久久亚洲综合av| 日韩小视频在线观看专区| 在线亚洲一区二区| 成人av在线一区二区三区| 国产老妇另类xxxxx| 免费欧美日韩国产三级电影| 亚洲小少妇裸体bbw| 亚洲欧美日韩人成在线播放|