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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? f32x_spi0_slave.c

?? 8051 SPI code ans 8051 ADC code
?? C
字號(hào):
//-----------------------------------------------------------------------------
// F32x_SPI0_Slave.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This program configures a C8051F32x as a SPI Slave. The 'F32x 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 F320-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) Verify J9 and J10 are populated.
// 4) Run the code.
// 5) 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:         C8051F32x
// Tool chain:     Keil C51 7.50 / Keil EVAL C51
// Command Line:   None
//
// Release 1.0
//    -Initial Revision (TP)
//    -14 DEC 2006
//

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

#include <C8051F320.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
//-----------------------------------------------------------------------------

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
免费日韩伦理电影| 国产一区福利在线| 国产日产欧美一区| 91精品婷婷国产综合久久| 91久久久免费一区二区| 欧美性一区二区| 欧美日韩高清一区二区三区| 欧美精品色综合| 欧美日韩高清一区二区| 91精品久久久久久久久99蜜臂| 欧美疯狂做受xxxx富婆| 精品国产乱码久久久久久免费 | 欧美日韩国产综合视频在线观看| 欧洲国内综合视频| 6080日韩午夜伦伦午夜伦| 日韩精品一区二区三区在线观看| 337p粉嫩大胆噜噜噜噜噜91av| 国产人久久人人人人爽| 亚洲免费观看高清完整版在线观看熊| 亚洲综合在线观看视频| 免费在线观看一区二区三区| 国产精品一区二区三区四区 | 亚洲高清中文字幕| 秋霞午夜av一区二区三区| 国产精品一区二区你懂的| 91在线精品一区二区| 欧美三日本三级三级在线播放| 日韩欧美中文字幕一区| 亚洲国产成人av| 国产999精品久久久久久绿帽| 一本色道久久综合亚洲精品按摩| 在线成人av影院| 欧美精品一区二| 亚洲第一二三四区| 成熟亚洲日本毛茸茸凸凹| 欧美日韩三级在线| 中文字幕视频一区| 经典三级视频一区| 91精品办公室少妇高潮对白| 精品精品国产高清一毛片一天堂| 亚洲黄色片在线观看| 国产成人亚洲综合a∨婷婷| 欧美在线短视频| 国产精品网站在线| 免费高清在线视频一区·| 99在线精品视频| 国产日韩欧美综合一区| 美日韩黄色大片| 欧美体内she精高潮| 中文字幕欧美一| 日韩av在线播放中文字幕| 99久久精品免费看国产免费软件| 精品国产乱码久久久久久久久| 亚洲成av人片一区二区梦乃 | 午夜精品福利一区二区三区蜜桃| 欧美日韩日日摸| 中文在线免费一区三区高中清不卡| 日韩极品在线观看| 欧美精品久久久久久久多人混战| 国产精品欧美一区喷水| 国产成人综合自拍| 久久久久久麻豆| 国产精品77777竹菊影视小说| 欧美一区二区性放荡片| 亚洲少妇中出一区| 97久久超碰精品国产| 国产精品美女久久久久久| 国产大片一区二区| 久久久久久久久久久电影| 国内精品伊人久久久久av一坑 | 国产成人精品影视| 久久精品夜夜夜夜久久| 国产酒店精品激情| 国产精品丝袜在线| 成人动漫精品一区二区| 国产精品乱人伦一区二区| 成人免费观看av| 国产精品乱人伦| 一本色道综合亚洲| 亚洲国产精品一区二区久久恐怖片| 欧洲精品在线观看| 日韩二区在线观看| 欧美mv日韩mv亚洲| 国产在线精品免费| 国产精品久久久久婷婷| 制服丝袜亚洲播放| 国内一区二区视频| 国产精品灌醉下药二区| 色狠狠色狠狠综合| 五月激情综合网| 日韩精品专区在线影院观看| 韩国三级在线一区| 国产精品国产馆在线真实露脸| 色94色欧美sute亚洲线路一久| 午夜不卡在线视频| 精品粉嫩超白一线天av| www.亚洲国产| 亚洲国产视频一区| www日韩大片| 日本韩国一区二区三区| 日本不卡不码高清免费观看| 久久精品一区八戒影视| 一本一本大道香蕉久在线精品 | 爽好久久久欧美精品| 欧美一区二区成人6969| 岛国一区二区在线观看| 亚洲最大的成人av| 久久久久国产精品麻豆| 欧美日韩中文字幕一区| 精品综合免费视频观看| 亚洲精品乱码久久久久久日本蜜臀| 欧美日韩国产首页在线观看| 国产激情视频一区二区三区欧美| 亚洲激情六月丁香| 久久精品无码一区二区三区| 欧美三级视频在线播放| 韩国午夜理伦三级不卡影院| 亚洲国产精品久久久男人的天堂| 26uuu成人网一区二区三区| 在线观看中文字幕不卡| 国产精品88av| 美女www一区二区| 亚洲天堂中文字幕| 国产亚洲欧美激情| 在线不卡中文字幕播放| 91麻豆视频网站| 国产精品自拍网站| 免费看日韩a级影片| 中文字幕第一区第二区| 精品国产乱码久久久久久免费 | 亚洲美女在线一区| 国产精品亲子伦对白| 2020国产精品| 日韩欧美精品在线视频| 69精品人人人人| 欧美精品1区2区| 欧美少妇xxx| 色综合久久久网| eeuss鲁一区二区三区| 国产成人综合视频| 精品一区二区在线免费观看| 天堂在线一区二区| 国产精品亚洲午夜一区二区三区| 日韩经典一区二区| 日韩av一区二区在线影视| 亚洲va欧美va人人爽午夜| 一区二区三区精密机械公司| 玉足女爽爽91| 亚洲色图.com| 一区二区三国产精华液| 亚洲与欧洲av电影| 亚洲电影欧美电影有声小说| 有码一区二区三区| 亚洲二区在线视频| 同产精品九九九| 久久激五月天综合精品| 蜜桃一区二区三区四区| 久久精品国产精品青草| 黄色日韩三级电影| 风间由美一区二区三区在线观看 | 亚洲丝袜自拍清纯另类| 自拍偷拍国产精品| 一区二区三区在线视频观看| 亚洲第一主播视频| 麻豆91免费看| 国产一区二区三区高清播放| 成人网页在线观看| 日本精品裸体写真集在线观看| 在线不卡一区二区| 2021久久国产精品不只是精品| 国产精品你懂的在线欣赏| 亚洲欧美日韩在线不卡| 日韩电影网1区2区| 精品一区二区三区久久| av午夜一区麻豆| 欧美日韩高清一区二区| 久久久午夜精品| 亚洲国产一区二区视频| 乱一区二区av| 成人夜色视频网站在线观看| 91福利在线免费观看| 日韩精品一区国产麻豆| 亚洲欧美日韩在线播放| 美女精品一区二区| 9人人澡人人爽人人精品| 欧美性猛交xxxxxx富婆| 日韩欧美国产系列| 亚洲黄色免费电影| 国产一区二区三区免费播放| 欧洲精品在线观看| 国产欧美日韩视频在线观看| 亚洲一区二区三区在线播放| 国产麻豆一精品一av一免费| 一本一本久久a久久精品综合麻豆| 日韩女优av电影在线观看| 一区二区三区免费网站| 国产在线一区观看| 欧美高清激情brazzers| 成人欧美一区二区三区1314 | 91色porny|