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

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

?? f32x_spi0_master.c

?? 8051 SPI code ans 8051 ADC code
?? C
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------
// F32x_SPI0_Master.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This program configures a C8051F32x as a 4-wire SPI Single Master.
//
// The SPI clock in this example is limited to 250 kHz 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 the
// SPI_READ_BUFFER command with a clock greater than 250 kHz.  For faster SPI
// clocks, a dummy byte between the command and the first byte of Read data
// 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)
//
// 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_Slave 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 SPI_CLOCK          250000      // Maximum SPI clock
                                       // The SPI clock is a maximum of 250 kHz
                                       // 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 = P2^2;                       // 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 PCA0_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;

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

//-----------------------------------------------------------------------------
// 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), Push-Pull,  Digital
// P0.1  -  MISO (SPI0), Open-Drain, Digital
// P0.2  -  MOSI (SPI0), Push-Pull,  Digital
// P0.3  -  NSS  (SPI0), Push-Pull,  Digital
//
// P2.2  -  Skipped,     Push-Pull,  Digital (LED D4 on Target Board)
//
//-----------------------------------------------------------------------------
void PORT_Init (void)
{
   P0MDOUT = 0x0D;                     // Make SCK, MOSI, and NSS 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 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()
{
   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;

   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 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)

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文在线资源观看网站视频免费不卡| 91精品啪在线观看国产60岁| 午夜国产不卡在线观看视频| 久久久久国色av免费看影院| 91久久久免费一区二区| 日日摸夜夜添夜夜添亚洲女人| 精品91自产拍在线观看一区| av资源网一区| 首页欧美精品中文字幕| 中文字幕免费不卡| 色综合久久天天| 久久成人久久鬼色| 日本一区二区三级电影在线观看 | 亚洲va欧美va天堂v国产综合| 91免费观看在线| 精品一区二区三区不卡| 中文字幕第一区综合| 91麻豆免费观看| 六月丁香综合在线视频| 中文字幕中文字幕一区| 色婷婷亚洲精品| 国产一区二区在线影院| 亚洲一区二区在线播放相泽 | 91麻豆精品国产91久久久更新时间 | 91福利资源站| 国产成人午夜精品影院观看视频| 亚洲成人av电影| 亚洲国产成人在线| 日韩免费观看高清完整版| 91麻豆免费看| 国产不卡免费视频| 欧美bbbbb| 午夜精品久久久久久久久久| 成人欧美一区二区三区白人| 亚洲精品一区二区精华| 欧美精品乱码久久久久久按摩| av欧美精品.com| 国产成人综合在线| 久久精品国产99国产精品| 亚洲成人免费影院| 亚洲精品国产成人久久av盗摄| 久久久777精品电影网影网| 欧美一区二区视频网站| 欧美亚洲国产一区二区三区| 99久久婷婷国产精品综合| 国产宾馆实践打屁股91| 久热成人在线视频| 蜜桃av一区二区在线观看 | 国产精品麻豆视频| 国产香蕉久久精品综合网| 精品国产一区二区三区久久影院| 337p亚洲精品色噜噜噜| 欧美日韩美少妇| 欧美日韩在线不卡| 欧美在线啊v一区| 色婷婷国产精品综合在线观看| 成人黄色在线网站| 成人永久aaa| 不卡视频免费播放| 成人午夜精品在线| 久久 天天综合| 国产在线视频精品一区| 久久狠狠亚洲综合| 国产精品一区二区91| 五月天激情综合网| 美女在线视频一区| 精品一区二区三区香蕉蜜桃| 日本欧美在线看| 久久精品72免费观看| 国产美女在线观看一区| 国产精品99久| 91网站在线观看视频| 色噜噜狠狠成人中文综合| 欧美综合一区二区| 91麻豆精品国产91久久久更新时间| 欧美一区二区日韩一区二区| 日韩欧美一区二区在线视频| 精品国一区二区三区| 久久久久久久综合狠狠综合| 国产精品乱人伦| 一区二区三区在线高清| 午夜伊人狠狠久久| 麻豆精品久久久| 福利视频网站一区二区三区| 91看片淫黄大片一级在线观看| 欧美图片一区二区三区| 欧美亚洲另类激情小说| 欧美一区二区三区视频免费播放| 久久蜜桃av一区精品变态类天堂| 国产精品久久久久四虎| 亚洲午夜精品网| 精品一区二区三区免费视频| 99久久99久久精品免费观看| 欧美中文字幕亚洲一区二区va在线 | 久久婷婷国产综合国色天香| 中文字幕av一区二区三区高 | 久久久.com| 亚洲乱码中文字幕| 日本一区中文字幕| 国产精品一区免费视频| 成人avav影音| 欧美高清www午色夜在线视频| 精品国产1区二区| 亚洲精品日韩综合观看成人91| 日韩成人伦理电影在线观看| 国产成人99久久亚洲综合精品| 欧美午夜精品久久久久久孕妇| 日韩写真欧美这视频| 中文字幕欧美一区| 秋霞午夜av一区二区三区| 成人做爰69片免费看网站| 911精品国产一区二区在线| 国产亚洲一区二区三区四区| 天天综合网天天综合色| 成人午夜av在线| 欧美一区午夜精品| 亚洲人成在线播放网站岛国| 精品一区二区在线免费观看| 色视频成人在线观看免| 国产亚洲人成网站| 日韩电影一区二区三区| 97精品国产97久久久久久久久久久久 | 国产高清一区日本| 欧美一级xxx| 一二三区精品福利视频| 国产精品一卡二卡| 91精品福利在线一区二区三区| 国产精品第13页| 国产精品一区二区视频| 1024国产精品| 久久精品99国产精品日本| 欧美日韩日日夜夜| 洋洋成人永久网站入口| 成人短视频下载| 国产欧美日韩视频在线观看| 久久66热偷产精品| 欧美一级理论性理论a| 亚洲主播在线播放| 91丨porny丨国产| 国产精品免费人成网站| 狠狠网亚洲精品| 精品少妇一区二区三区| 日本不卡123| 欧美一区二区三区在线| 亚洲第四色夜色| 欧美色爱综合网| 亚洲精品日韩专区silk| 99精品热视频| 国产网红主播福利一区二区| 亚洲成a人v欧美综合天堂| 在线免费观看日本欧美| 一区二区三区四区不卡在线 | 欧美一二三区在线观看| 美女尤物国产一区| 欧美mv和日韩mv国产网站| 免费成人你懂的| 欧美sm极限捆绑bd| 九九九久久久精品| 精品美女一区二区三区| 久久激情五月激情| 久久精品亚洲麻豆av一区二区| 国产成人av电影在线观看| 国产亚洲人成网站| 北岛玲一区二区三区四区| 亚洲欧美日韩综合aⅴ视频| 色综合色狠狠综合色| 一区二区三区四区不卡在线 | 国产一区二区精品在线观看| 久久久精品国产99久久精品芒果| 国产一区二三区| 久久久久久**毛片大全| 成人一区二区三区视频在线观看| 国产精品网曝门| 色婷婷国产精品| 污片在线观看一区二区| 欧美亚洲丝袜传媒另类| 亚洲成人高清在线| 欧美日本精品一区二区三区| 欧美aⅴ一区二区三区视频| 3d动漫精品啪啪1区2区免费 | 亚洲免费在线观看视频| 欧美日韩电影一区| 国内精品伊人久久久久av一坑| 国产丝袜在线精品| 91视频在线观看免费| 亚洲一区二区三区四区的| 这里是久久伊人| 高清在线不卡av| 夜夜爽夜夜爽精品视频| 6080午夜不卡| 国产成人欧美日韩在线电影| 亚洲精品国产成人久久av盗摄| 91精品国产福利| 国产成人h网站| 午夜久久久久久久久久一区二区| 精品国产制服丝袜高跟| 亚洲精品一区二区三区蜜桃下载| 99riav一区二区三区| 日韩黄色免费电影| 国产日韩精品一区二区三区在线|