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

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

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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
97精品久久久午夜一区二区三区| 成人av在线播放网址| 一区二区日韩av| 亚洲国产精品成人综合 | 国产精品美女久久久久久久网站| 91精品国产入口| 欧美一区二区久久| 欧美一区午夜精品| 精品免费国产一区二区三区四区| 久久综合久久久久88| 精品国产91久久久久久久妲己| 欧美成人在线直播| 欧美国产日韩一二三区| 国产精品久久二区二区| 一区二区三国产精华液| 青青草成人在线观看| 精品一区二区成人精品| 国产成人午夜高潮毛片| 91香蕉国产在线观看软件| 欧美日韩中文精品| 精品国产乱码久久| 中文字幕欧美一| 亚洲成人手机在线| 久久99久久99| 色香蕉成人二区免费| 91精品国产综合久久香蕉的特点| 日韩亚洲欧美成人一区| 综合网在线视频| 日本不卡中文字幕| 成人av网址在线观看| 3atv一区二区三区| 国产精品视频免费| 日日摸夜夜添夜夜添亚洲女人| 国产一级精品在线| 在线观看一区二区精品视频| 2020国产精品自拍| 亚洲国产精品天堂| 国产馆精品极品| 欧美一区二区三区在线电影| 中文欧美字幕免费| 老司机午夜精品| 91麻豆免费观看| 2020国产精品久久精品美国| 性欧美疯狂xxxxbbbb| 成人免费看黄yyy456| 欧美剧情片在线观看| 国产精品久久网站| 极品尤物av久久免费看| 欧美日韩在线综合| 国产精品超碰97尤物18| 美女视频黄a大片欧美| 色域天天综合网| 欧美激情一区二区三区四区| 麻豆91精品视频| 欧美日韩精品一区二区天天拍小说| 国产欧美一区二区精品性色 | 91精品国产手机| 一区二区三区精品在线| 成人app网站| 国产日产欧美一区二区三区| 另类中文字幕网| 日韩欧美电影在线| 美女在线观看视频一区二区| 91久久精品网| 亚洲精品乱码久久久久久黑人| 国产大片一区二区| 久久久久久97三级| 久久精品国产一区二区| 欧美精品丝袜中出| 爽爽淫人综合网网站| 欧美视频在线一区二区三区| 一区二区三区蜜桃网| 欧美性视频一区二区三区| 亚洲品质自拍视频| 一道本成人在线| 亚洲激情图片一区| 欧美中文字幕一区二区三区亚洲| 亚洲麻豆国产自偷在线| 一本到高清视频免费精品| 亚洲激情在线播放| 欧美天天综合网| 青娱乐精品视频| 久久众筹精品私拍模特| 国产成人综合在线播放| 国产精品久久久久久久久免费樱桃 | 色综合一区二区三区| 亚洲另类春色国产| 欧美久久一二区| 日韩福利视频导航| 精品日韩成人av| 欧美日韩在线播放一区| 亚洲成a人在线观看| 在线不卡免费av| 欧美日韩国产小视频在线观看| 一区二区三区在线播放| 欧美综合天天夜夜久久| 秋霞成人午夜伦在线观看| 精品国产乱码久久久久久牛牛| 国产精品一级片在线观看| ●精品国产综合乱码久久久久| 91麻豆6部合集magnet| 五月天精品一区二区三区| 日韩亚洲欧美在线| 大尺度一区二区| 亚洲一区二区在线视频| 精品国产露脸精彩对白 | 国产精品一区二区三区99| 国产精品你懂的| 91麻豆精品国产91久久久| 国产精品 日产精品 欧美精品| 亚洲欧洲日产国产综合网| 8x福利精品第一导航| 大白屁股一区二区视频| 手机精品视频在线观看| 国产精品国产自产拍在线| 欧美日韩成人一区| 99久久婷婷国产| 精品一区二区三区香蕉蜜桃| 亚洲欧美日韩中文字幕一区二区三区 | 成人黄色综合网站| 亚洲1区2区3区4区| 国产精品私人影院| 日韩精品一区二区三区四区视频| 成人国产在线观看| 美女一区二区久久| 亚洲综合色网站| 欧美国产日韩在线观看| 欧美一区二区三区日韩| 成人理论电影网| 国产精品99久久久久久有的能看| 亚洲一区二区三区视频在线播放| 国产亚洲欧美日韩在线一区| 制服丝袜在线91| 色综合av在线| 91亚洲精品久久久蜜桃| 国产精品538一区二区在线| 免费看黄色91| 日韩电影网1区2区| 亚洲第一福利视频在线| 专区另类欧美日韩| 中文字幕一区二区三中文字幕| 26uuu色噜噜精品一区二区| 欧美高清激情brazzers| 欧美日韩高清不卡| 欧美日韩国产首页在线观看| 欧美在线不卡视频| 欧美午夜宅男影院| 欧美午夜精品一区| 欧美日韩在线一区二区| 欧美午夜免费电影| 制服丝袜激情欧洲亚洲| 欧美久久久一区| 91精品国产综合久久久久久漫画 | 不卡区在线中文字幕| 国产成人免费在线视频| 风间由美一区二区三区在线观看| 国模无码大尺度一区二区三区| 美女免费视频一区二区| 久久国内精品自在自线400部| 日本视频免费一区| 奇米精品一区二区三区在线观看| 日本成人在线一区| 精品一区二区免费| 粉嫩一区二区三区性色av| 成人av动漫在线| 日本道色综合久久| 欧美精品一卡两卡| 日韩欧美国产系列| 久久你懂得1024| 亚洲国产电影在线观看| 日韩国产高清影视| 日日噜噜夜夜狠狠视频欧美人 | 大胆欧美人体老妇| 欧美自拍丝袜亚洲| 日韩免费视频一区二区| 国产亚洲一二三区| 亚洲欧美另类在线| 男人的天堂亚洲一区| 国产成人精品免费在线| 91免费看视频| 日韩一区二区三区免费看| 国产亚洲美州欧州综合国| 亚洲精品国产品国语在线app| 午夜欧美2019年伦理| 国内精品视频一区二区三区八戒| 91网站最新地址| 日韩三级中文字幕| 亚洲欧美综合另类在线卡通| 午夜免费久久看| 国产成人午夜99999| 欧美精品久久99| 国产精品青草综合久久久久99| 亚洲国产视频在线| 国产成人午夜片在线观看高清观看| 在线观看亚洲精品| 国产偷国产偷亚洲高清人白洁 | 韩国女主播成人在线| 91黄色激情网站| 久久九九久精品国产免费直播| 亚洲欧美日本韩国|