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

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

?? f34x_spi0_slave.c

?? 此spi程序原創來源于網絡
?? C
字號:
//-----------------------------------------------------------------------------
// F34x_SPI0_Slave.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This program configures a C8051F34x as a SPI Slave. The 'F34x 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)
//
// P2.2 - LED        (digital output, push-pull)
//
// all other port pins unused.
//
//
// How To Test:
//
// 1) Download the code to a F340-TB that is connected as above to
//    another device running the SPI0_Master code.
// 2) Verify that the LED pins on jumper J12 are 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:         C8051F34x
// Tool chain:     Keil C51 7.50 / Keil EVAL C51
// Command Line:   None
//
// Release 1.0
//    -Initial Revision (TP)
//    -14 DEC 2006
//

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

#include <C8051F340.h>                 // SFR declarations

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

#define SYSCLK             12000000    // 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 = P2^2;                       // LED='1' means ON

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

unsigned char SPI_Data = 0xA5;

unsigned char SPI_Data_Array[MAX_BUFFER_SIZE] = {0};

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

void PCA0_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
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// PCA0_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function disables the watchdog timer.
//
//-----------------------------------------------------------------------------
void PCA0_Init (void)
{
   PCA0MD &= ~0x40;                    // Disable the Watchdog Timer
   PCA0MD = 0x00;
}

//-----------------------------------------------------------------------------
// Oscillator_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function initializes the system clock to use the internal oscillator
// at 12 MHz.
//
//-----------------------------------------------------------------------------
void Oscillator_Init (void)
{
   OSCICN = 0x83;                      // Set the internal oscillator to
                                       // 12 MHz
}

//-----------------------------------------------------------------------------
// 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
//
// P2.2  -  Skipped,     Push-Pull,  Digital (LED D4 on Target Board)
//
//-----------------------------------------------------------------------------
void PORT_Init (void)
{
   P0MDOUT = 0x02;                     // Make MISO push-pull
   P2MDOUT = 0x04;                     // Make the LED push-pull

   P2SKIP = 0x04;                      // Skip the LED (P2.2)

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

//-----------------------------------------------------------------------------
// 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()
{
   SPI0CFG = 0x00;                     // Operate in Slave mode
                                       // CKPHA = '0', CKPOL = '0'
   SPI0CN = 0x05;                      // 4-wire Slave mode, SPI enabled

   ESPI0 = 1;                          // Enable SPI interrupts
}

//-----------------------------------------------------------------------------
// Init_Device
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Calls all device initialization functions.
//
//-----------------------------------------------------------------------------
void Init_Device (void)
{
   PCA0_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一区二区三区免费野_久草精品视频
欧美一区二区三区系列电影| 国产呦精品一区二区三区网站| 99re这里只有精品视频首页| 中文字幕av一区二区三区| 夫妻av一区二区| 中文字幕一区二区视频| 色老综合老女人久久久| 日韩精品亚洲专区| 精品久久久久久久人人人人传媒| 精品亚洲aⅴ乱码一区二区三区| 久久久久久一级片| 成人app在线观看| 亚洲成a人片综合在线| 欧美一区二区视频在线观看2022| 久88久久88久久久| 国产精品视频一二三区| 日本伦理一区二区| 蜜臀精品久久久久久蜜臀| 国产欧美一区二区三区网站| 日本精品视频一区二区三区| 日韩影院在线观看| 久久夜色精品一区| 色综合一区二区三区| 奇米影视一区二区三区| 日本一区二区三区国色天香| 欧美综合久久久| 韩国精品主播一区二区在线观看| 欧美国产在线观看| 欧美精品一卡二卡| 国产精品资源站在线| 欧美激情在线一区二区| 欧美亚日韩国产aⅴ精品中极品| 日韩不卡一二三区| 亚洲三级电影网站| 欧美不卡一区二区三区四区| 色哟哟国产精品免费观看| 乱一区二区av| 亚洲视频你懂的| 精品国产一区二区精华 | 国产精品中文字幕欧美| 伊人色综合久久天天| 久久五月婷婷丁香社区| 欧美伊人久久久久久久久影院| 国产综合色在线视频区| 亚洲线精品一区二区三区| 日本一区二区三区高清不卡| 日韩一区二区三区免费看| 波波电影院一区二区三区| 久久99最新地址| 亚洲成a人片综合在线| 中文子幕无线码一区tr| 欧美成人一区二区| 欧美日韩精品一区二区天天拍小说| 国产不卡免费视频| 精品一二线国产| 日本欧美在线看| 午夜久久久久久电影| 亚洲欧美日韩精品久久久久| 国产三级久久久| 久久网站热最新地址| 日韩一区二区在线看| 欧美在线|欧美| 色综合天天综合网国产成人综合天 | 国产精品99久久不卡二区| 午夜欧美电影在线观看| 一区二区三区自拍| 亚洲天堂2016| 综合久久一区二区三区| 亚洲欧洲99久久| 国产精品污污网站在线观看| 国产欧美一区二区精品性色| 久久麻豆一区二区| 久久久久久久久岛国免费| 精品动漫一区二区三区在线观看| 日韩免费视频一区| 日韩一区二区三区观看| 日韩视频一区在线观看| 欧美一区二区三区日韩| 日韩精品最新网址| 精品国产一区二区三区四区四| 欧美成人a∨高清免费观看| 欧美成人猛片aaaaaaa| 日韩免费在线观看| 精品成人在线观看| 国产清纯在线一区二区www| 亚洲国产激情av| 亚洲日本韩国一区| 亚洲制服丝袜一区| 日韩专区一卡二卡| 久久国产日韩欧美精品| 国产麻豆9l精品三级站| 成人av动漫在线| 色香色香欲天天天影视综合网| 日本韩国欧美一区二区三区| 欧美日韩国产精选| 欧美成人a在线| 欧美激情一二三区| 亚洲一区二区三区免费视频| 奇米影视在线99精品| 国产一区日韩二区欧美三区| 高清不卡一区二区| 91福利在线导航| 日韩一区二区三区在线视频| 久久亚洲一级片| 国产成人综合网| 成人国产免费视频| 欧美三级一区二区| 日韩一级二级三级精品视频| 国产日韩欧美制服另类| 一区二区三区日韩精品| 蜜臂av日日欢夜夜爽一区| 国产不卡在线视频| 欧美中文字幕不卡| 久久美女高清视频| 亚洲美女在线国产| 久久精品国产亚洲5555| thepron国产精品| 91精品国产免费| 国产精品久久夜| 青青草国产精品亚洲专区无| 白白色亚洲国产精品| 欧美精品vⅰdeose4hd| 欧美精品一区二区久久久| 中文字幕亚洲区| 精品一区二区三区免费观看| 色香色香欲天天天影视综合网| 精品久久人人做人人爽| 一区二区三区欧美激情| 国产精品系列在线播放| 在线播放中文一区| 中文字幕亚洲电影| 九九视频精品免费| 欧美午夜电影在线播放| 欧美激情资源网| 久久99精品视频| 在线精品亚洲一区二区不卡| 久久久国产精品午夜一区ai换脸| 亚洲bdsm女犯bdsm网站| a在线播放不卡| 久久精品亚洲精品国产欧美kt∨| 五月激情六月综合| 色综合久久久久久久久久久| 久久女同性恋中文字幕| 日本最新不卡在线| 欧美色图片你懂的| 国产精品久久久久一区二区三区 | 久久综合狠狠综合久久综合88| 亚洲精品久久7777| 国产aⅴ精品一区二区三区色成熟| 日韩一区二区影院| 亚洲高清在线精品| 色成年激情久久综合| 国产精品久久久久久久久快鸭 | 欧美精品乱人伦久久久久久| 亚洲精选一二三| 97久久超碰精品国产| 亚洲国产精品v| 国产成人午夜精品影院观看视频 | 在线看国产日韩| 中文字幕日韩av资源站| 成人午夜av电影| 欧美国产乱子伦| 国产精品一区二区男女羞羞无遮挡| 精品乱人伦一区二区三区| 免费在线视频一区| 欧美一级二级三级蜜桃| 免费观看成人鲁鲁鲁鲁鲁视频| 欧美三级蜜桃2在线观看| 亚洲综合在线五月| 在线免费亚洲电影| 亚洲一二三区视频在线观看| 欧美在线免费视屏| 亚洲综合在线视频| 欧美精品v国产精品v日韩精品| 亚洲成人免费影院| 欧美日韩dvd在线观看| 视频精品一区二区| 日韩精品中文字幕一区| 经典三级一区二区| 国产欧美日韩在线看| 成人高清免费在线播放| 亚洲青青青在线视频| 在线观看免费成人| 三级久久三级久久| 日韩精品一区在线| 国产高清无密码一区二区三区| 欧美激情一区二区在线| 91一区二区在线| 亚洲一二三级电影| 日韩欧美一区二区在线视频| 国产一区二区三区四区五区美女| 国产片一区二区三区| 91免费视频大全| 日精品一区二区三区| 久久综合久久综合九色| 91亚洲精品乱码久久久久久蜜桃| 亚洲国产一区在线观看| 欧美va在线播放| 播五月开心婷婷综合| 亚洲电影视频在线|