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

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

?? f12x_spi0_master.c

?? 基于C8051F120的SPI總線實現代碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------
// F12x_SPI0_Master.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This program configures a C8051F12x as a 4-wire SPI Single Master.
//
// The SPI clock in this example is limited to 500 kHz (with a SYSCLK of 24.5
// MHz)when used with the SPI0_Slave code example.  During a SPI_Read, the
// slave needs some time to interpret the command and write the appropriate
// data to the SPI0DAT register, and the slave no longer has enough time to
// complete theSPI_READ_BUFFER command with a clock greater than 500 kHz.  For
// faster SPI clocks, a dummy byte between the command and the first byte of
// Read data or a faster SYSCLK will be required.
//
// This example is intended to be used with the SPI0_Slave example.
//
// Pinout:
//
// P0.0 - SPI SCK    (digital output, push-pull)
// P0.1 - SPI MISO   (digital input, open-drain)
// P0.2 - SPI MOSI   (digital output, push-pull)
// P0.3 - SPI NSS    (digital output, push-pull)
//
// 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_Slave 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 SPI_CLOCK          500000      // Maximum SPI clock
                                       // The SPI clock is a maximum of 500 kHz
                                       // with a SYSCLK of 24.5 MHz when this
                                       // example is used with the SPI0_Slave
                                       // code example.

#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};

bit Error_Flag = 0;

unsigned char Command = 0x00;

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

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

void SPI_LED_On (void);
void SPI_LED_Off (void);
void SPI_Byte_Write (void);
void SPI_Byte_Read (void);
void SPI_Array_Write (void);
void SPI_Array_Read (void);

void Delay(void);

//-----------------------------------------------------------------------------
// main() Routine
//-----------------------------------------------------------------------------
void main (void)
{
   unsigned char test_value = 0x55;
   unsigned char test_array[MAX_BUFFER_SIZE] = {1,2,3,4,5,6,7,8};
   unsigned char i;

   Init_Device ();                     // Initializes hardware peripherals

   EA = 1;                             // Enable global interrupts

   LED = 0;

   SFRPAGE = LEGACY_PAGE;

   // TEST BEGIN --------------------------------------------------------------

   SPI_Data = test_value;

   // Write a value
   SPI_Byte_Write ();

   while (!NSSMD0);                    // Wait until the Write transfer has
                                       // finished

   // Read the same value back
   SPI_Data = 0x00;
   SPI_Byte_Read ();

   while (!NSSMD0);                    // Wait until the Read transfer has
                                       // finished

   // Check if the sent value and returned value match
   if (SPI_Data != test_value)
   {
      Error_Flag = 1;
   }

   // Copy test_array into SPI_Data_Array
   for (i = 0; i < MAX_BUFFER_SIZE; i++)
   {
      SPI_Data_Array[i] = test_array[i];
   }

   // Send the array to the slave
   SPI_Array_Write ();

   while (!NSSMD0);                    // Wait until the Write transfer has
                                       // finished

   // Clear SPI_Data_Array for the SPI_Buffer_Read function
   for (i = 0; i < MAX_BUFFER_SIZE; i++)
   {
      SPI_Data_Array[i] = 0;
   }

   // Read the array back from the slave
   SPI_Array_Read ();

   while (!NSSMD0);                    // Wait until the Read transfer has
                                       // finished

   // Check if the received array matches the sent array
   for (i = 0; i < MAX_BUFFER_SIZE; i++)
   {
      if (SPI_Data_Array[i] != test_array[i])
      {
         Error_Flag = 1;
      }
   }

   // END OF TEST -------------------------------------------------------------

   while (1)
   {
      // If no error has occurred, blink the LEDs on the Master and Slave
      // boards
      if (Error_Flag == 0)
      {
         LED = 1;

         SPI_LED_On ();

         while (!NSSMD0);

         Delay ();

         SPI_LED_Off ();

         LED = 0;

         while (!NSSMD0);

         Delay ();
      }
   };
}

//-----------------------------------------------------------------------------
// 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), Push-Pull,  Digital
// P0.1  -  MISO (SPI0), Open-Drain, Digital
// P0.2  -  MOSI (SPI0), Push-Pull,  Digital
// P0.3  -  NSS  (SPI0), Push-Pull,  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 = 0x0D;                     // Make SCK, MOSI, and NSS 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 Single Master 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   = 0x40;                   // Enable the SPI as a Master
                                       // CKPHA = '0', CKPOL = '0'
   SPI0CN    = 0x0D;                   // 4-wire Single Master, SPI enabled

   // SPI clock frequency equation from the datasheet
   SPI0CKR   = (SYSCLK/(2*SPI_CLOCK))-1;

   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 error checks and single-byte writes.
//
// Note: SPI_WRITE_ARRAY is not handled by this ISR in order to take
// advantage of double-buffering (checking the TXBMT flag) using polling.
//
//
// 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 array_index = 0;
   static char state = 0;

   if (WCOL == 1)
   {
      // Write collision occurred
      WCOL = 0;                        // Clear the write collision flag

      Error_Flag = 1;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩一区精品视频| 国产精品色在线| 污片在线观看一区二区| 在线日韩一区二区| 亚洲在线视频一区| 欧美日韩一本到| 日韩av网站免费在线| 日韩欧美中文一区二区| 国模一区二区三区白浆| 国产欧美va欧美不卡在线| 成人精品国产一区二区4080| 成人免费在线视频| 欧美色图激情小说| 美女视频黄久久| 午夜精品福利视频网站| 欧美一级黄色片| 国产精品一品二品| 综合激情成人伊人| 欧美肥胖老妇做爰| 国产成人免费视频网站| 一区二区三区产品免费精品久久75| 色狠狠色噜噜噜综合网| 三级欧美韩日大片在线看| 日韩片之四级片| caoporn国产精品| 丝袜亚洲另类欧美综合| 国产日本欧美一区二区| 色哟哟一区二区三区| 日韩激情一二三区| 日本一二三不卡| 欧美日韩亚洲综合一区二区三区 | 久久久久久夜精品精品免费| 国产一区二区主播在线| 亚洲日本在线观看| 日韩一二在线观看| 91色九色蝌蚪| 激情综合色丁香一区二区| 日韩理论片网站| 欧美tk丨vk视频| 在线观看国产91| 国产成人av网站| 丝袜脚交一区二区| 亚洲日本va午夜在线电影| 日韩一区二区三区免费观看| 色综合久久久久综合99| 激情六月婷婷久久| 日日夜夜精品视频免费| 国产精品伦理在线| 欧美成人一级视频| 欧美日韩美少妇| 91蝌蚪国产九色| 国产成人亚洲综合a∨猫咪| 丝袜美腿亚洲综合| 中文字幕亚洲在| 国产视频一区在线播放| 日韩午夜在线观看| 欧美日韩成人一区| 欧美在线看片a免费观看| 国产91露脸合集magnet| 精品制服美女丁香| 日韩在线观看一区二区| 亚洲曰韩产成在线| 一区二区三区四区激情| 国产精品欧美一级免费| 久久人人爽爽爽人久久久| 91精品福利在线一区二区三区 | 国产美女精品一区二区三区| 午夜不卡av在线| 一区二区三区小说| 国产精品国产三级国产三级人妇| 精品国产区一区| 精品国产1区二区| 日韩亚洲欧美一区| 欧美日韩免费高清一区色橹橹| 色哟哟国产精品| 99re热这里只有精品视频| 成人一级视频在线观看| 粉嫩aⅴ一区二区三区四区| 国产美女主播视频一区| 国产激情精品久久久第一区二区 | 国产毛片精品一区| 精品无人码麻豆乱码1区2区| 蜜臀av性久久久久蜜臀av麻豆| 日一区二区三区| 天天综合天天做天天综合| 亚洲国产精品一区二区尤物区| 亚洲精品国产a| 亚洲综合在线视频| 亚洲gay无套男同| 亚洲777理论| 性久久久久久久久| 日韩高清一区在线| 精品亚洲porn| 成人免费观看男女羞羞视频| 91老师片黄在线观看| 欧美性大战久久久久久久蜜臀| 欧美精品三级日韩久久| 日韩一级视频免费观看在线| 久久影院视频免费| 国产精品看片你懂得| 亚洲精品videosex极品| 天天色天天操综合| 久久精品99国产国产精| 国产99久久久久| 在线观看视频一区| 日韩一区二区三区视频在线观看| 久久久一区二区三区| 亚洲视频一二三| 日韩专区一卡二卡| 粉嫩av一区二区三区粉嫩| 欧亚洲嫩模精品一区三区| 日韩一区二区电影网| 国产午夜精品一区二区三区四区| 亚洲女同女同女同女同女同69| 亚洲综合久久av| 精品午夜久久福利影院| 99视频在线观看一区三区| 在线电影国产精品| 国产欧美一区二区三区沐欲| 一区二区三区在线高清| 狠狠色丁香婷婷综合| 99热精品一区二区| 日韩手机在线导航| 综合精品久久久| 免费久久精品视频| 91丨国产丨九色丨pron| 欧美一二三在线| 亚洲男人天堂av| 国产原创一区二区| 欧美日本韩国一区二区三区视频| 国产肉丝袜一区二区| 亚洲妇女屁股眼交7| 国产黄色精品网站| 欧美一区二区三区四区久久| 亚洲免费观看高清完整版在线观看 | 欧美电影免费观看完整版| 自拍av一区二区三区| 国内外成人在线| 欧美乱妇20p| 自拍偷拍国产精品| 国内外精品视频| 日韩欧美资源站| 亚洲bdsm女犯bdsm网站| 色婷婷av一区二区三区大白胸| 精品国产免费人成电影在线观看四季| 一区二区三区在线观看动漫| 国产91高潮流白浆在线麻豆| 日韩精品专区在线影院观看| 午夜不卡在线视频| 欧洲一区二区av| 亚洲人被黑人高潮完整版| 国产电影精品久久禁18| 欧美成人免费网站| 天天综合网 天天综合色| 色狠狠桃花综合| 日韩久久一区二区| 99这里只有精品| 国产精品福利一区二区三区| 国产精品一区二区在线看| 精品久久99ma| 久久av中文字幕片| 日韩欧美一区二区免费| 免费久久99精品国产| 欧美妇女性影城| 日日夜夜精品视频免费| 欧美日本韩国一区二区三区视频| 亚洲国产欧美日韩另类综合| 欧美在线你懂的| 亚洲国产一二三| 欧美美女一区二区在线观看| 亚洲图片自拍偷拍| 欧美乱熟臀69xxxxxx| 奇米精品一区二区三区四区| 这里是久久伊人| 美女视频免费一区| 久久免费偷拍视频| 国产精品自拍网站| 国产精品理论片| 色美美综合视频| 日韩影视精彩在线| 精品99一区二区| 丁香另类激情小说| 亚洲免费视频中文字幕| 欧美私模裸体表演在线观看| 亚洲国产精品尤物yw在线观看| 欧美电影在哪看比较好| 久久99最新地址| 中国色在线观看另类| 色综合中文综合网| 97久久精品人人做人人爽| 亚洲欧美激情视频在线观看一区二区三区 | 91精品国产乱码久久蜜臀| 日本中文字幕一区二区视频| 欧美精品一区二区在线播放| 成人丝袜视频网| 亚洲图片欧美综合| 欧美不卡一区二区三区四区| 国产成人精品1024| 樱花影视一区二区| 日韩一区二区在线免费观看|