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

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

?? f50x_lin_slave.c

?? C8051F500開發編程:MCU全部資源應用實例
?? C
字號:
//-----------------------------------------------------------------------------
// F50x_LIN_Slave.c
//-----------------------------------------------------------------------------
// Copyright 2008 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
// This program's purpose is to communicate between the A and B sides of the 
// C8051F50x target board through the Local Interconnect Network (LIN).
// 
// Pressing the P1.4_A switch will trigger the P1.3_B LED to light up. 
// Releasing the P1.4_A switch will turn off the P1.3_B LED. 
// Alternatively, pressing the P1.4_B switch will turn on the P1.3_A LED 
// while releasing the P1.4_B switch will turn off the P1.3_A LED.
//
// This example is intended to be used with the LIN_Master example.
//
// How To Test:
//
// 1) Verify the LED and switch pin jumpers are populated 
//    (J19 for device A and J11 for device B).
//
// 2) Make sure the LIN jumpers in J17 (for A side) and J26 (for B side)
//    are connected.
//
// 3) If you wish to change the baud rate of the LIN, change the following
//    global constant after disabling AUTO_BAUD constant: LIN_BAUD_RATE
// 
// 3) Download the code to a F50x-TB (either device A or device B) that is
//    connected as above to another device running the LIN0_Master code.
//
// 4) Run the code.
//
// 5) If the communication passes, when a switch on a side of the target board
//    is pressed, the LED on the opposite side will light up. When said switch 
//    is released, the LED will turn off. 
//
// Target:         C8051F50x (C8051F500 TB)
// Tool chain:     Keil C51 8 / Keil EVAL C51
// Command Line:   None
//
// Revision History:
//
// Release 1.0 / 09 JUNE 2008 (ADT)
//    -Initial Revision
//
// Obs1: When the master sends a request frame, the ID sent from the master
//       is the same as the ID read by the master after a slave transmit frame,
//       even if the slave tries to edit the ID before transmitting.
//
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

#include <compiler_defs.h>
#include <c8051f500_defs.h>                 
#include <stdio.h>

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

SBIT (SW1, P1, 4);                     // SW1 = '0' means switch pressed
SBIT (LED, P1, 3);                     // LED = '1' means LED on

#define SYSCLK 24000000                // Clock speed in Hz

#if (SYSCLK < 8000000)                 // For the slowest baud rate
#error Minimum system clock needed to operate LIN peripheral is 8Mhz.
#endif

#define  AUTO_BAUD   1                 // 0 = disable autobaud
                                       // 1 = enable autobaud
#define  LIN_BAUD_RATE 10000           // Baud Rate to run LIN peripheral
                                       // 625 < LIN_BAUD_RATE < 20000

//-----------------------------------------------------------------------------
// LIN #defines
//-----------------------------------------------------------------------------

//------ Control register ------
#define  STREQ       0x01              // LIN Master Start transmission request
#define  WUPREQ      0x02              // Wake-Up request
#define  RSTERR      0x04              // Error reset request
#define  RSTINT      0x08              // Interrupt reset request
#define  DTACK       0x10              // Slave Data ACK
#define  TXRX        0x20              // Master selection of TX or RX mode
#define  SLEEP       0x40              // Slave flag set by master to inform
                                       // the peripheral that either a sleep
                                       // mode frame or bus idle timeout
                                       // was reached
#define  STOP        0x80              // Slave flag, to be set by the
                                       // application so no processing is to be
                                       // done until next SYNCH BREAK
//------ Status Register ------
#define  DONE        0x01              // Msg. processing completed
#define  WAKEUP      0x02              // Wake-Up signal
#define  ERROR       0x04              // Error detected
#define  LININTREQ   0x08              // Interrupt request
#define  DTREQ       0x10              // ID detected
#define  ABORT       0x20              // Abort requested
#define  IDLTOUT     0x40              // Time-out detected
#define  ACTIVE      0x80              // Interface active (communicating)

#if (AUTO_BAUD == 0)                   // If running in manual baud rate mode

 #define LIN_MULTIPLIER ((20000.0 / LIN_BAUD_RATE) - 1)

 #if (SYSCLK >= 16000000)
  #define LIN_PRESCALAR 1
  #define LIN_DIVIDER (SYSCLK / (4 * (LIN_MULTIPLIER + 1) * LIN_BAUD_RATE))
 #else
  #define LIN_PRESCALAR 0
  #define LIN_DIVIDER (SYSCLK / (2 * (LIN_MULTIPLIER + 1) * LIN_BAUD_RATE))
 #endif

#else                                  // If running in auto baud rate mode

   #if (SYSCLK >= 16000000)
      #define LIN_PRESCALAR 1
      #define LIN_DIVIDER (U16)(SYSCLK / (4 * 20000))
   #else
      #define LIN_PRESCALAR 0
      #define LIN_DIVIDER (U16)(SYSCLK / (2 * 20000))
   #endif

#endif

// Instruction Set
#define ID_SW1_SLAVE_QUERY 0x01
#define ID_LED_SLAVE       0x02        //LED on the slave side
#define ID_LED_SLAVE_OFF   0x02          
#define ID_LED_SLAVE_ON    0x03

#define LED_MASTER_OFF     0x04
#define LED_MASTER_ON      0x05 

//-----------------------------------------------------------------------------
// Global VARIABLES
//-----------------------------------------------------------------------------

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

void Oscillator_Init (void);           // Configure the system clock
void Port_Init (void);                 // Configure the Crossbar and GPIO
void LIN0_Slave_Init (void);           // Configure LIN for slave

INTERRUPT_PROTO (LIN0_ISR, INTERRUPT_LIN0);


//-----------------------------------------------------------------------------
// main() Routine
//-----------------------------------------------------------------------------

void main (void) 
{
   SFRPAGE = ACTIVE_PAGE;

   PCA0MD &= ~0x40;                    // Disable Watchdog timer

   Oscillator_Init ();                 // Initialize the system clock
   Port_Init ();                       // Initialize crossbar and GPIO
   LIN0_Slave_Init ();                 // Initialize LIN

   EA = 1;                             // Enable interrupts

   LED = 0;                            // Initialize LED to be off


   while (1);                          // Infinite while loop waiting for
                                       // instructions from Master
}

//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// OSCILLATOR_Init
//-----------------------------------------------------------------------------
//
// Return Value:  None
// Parameters:    None
//
// Configure the internal oscillator to maximum internal frequency of 24 Mhz
//
//-----------------------------------------------------------------------------
void OSCILLATOR_Init (void)
{
   U8 SFRPAGE_save = SFRPAGE;
   SFRPAGE = CONFIG_PAGE;

   OSCICN = 0x87;

   SFRPAGE = SFRPAGE_save;
}

//-----------------------------------------------------------------------------
// Port_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function configures the crossbar and GPIO ports.
//
// P0.0  -  Skipped,     Open-Drain, Digital
// P0.1  -  Skipped,     Open-Drain, Digital
// P0.2  -  Skipped,     Open-Drain, Digital
// P0.3  -  Skipped,     Open-Drain, Digital
// P0.4  -  Skipped,     Open-Drain, Digital
// P0.5  -  Skipped,     Open-Drain, Digital
// P0.6  -  Skipped,     Open-Drain, Digital
// P0.7  -  Skipped,     Open-Drain, Digital

// P1.0  -  TX    (LIN), Push-Pull,  Digital
// P1.1  -  RX    (LIN), Open-Drain, Digital
// P1.2  -  Unassigned,  Open-Drain, Digital
// P1.3  -  LED    ,     Push-Pull,  Digital
// P1.4  -  SW1   ,      Open-Drain, Digital
// P1.5  -  Unassigned,  Open-Drain, Digital
// P1.6  -  Unassigned,  Open-Drain, Digital
// P1.7  -  Unassigned,  Open-Drain, Digital
//
//-----------------------------------------------------------------------------
void Port_Init (void)
{
   U8 SFRPAGE_save = SFRPAGE;
   SFRPAGE = CONFIG_PAGE;

   P1MDOUT   = 0x09;                   // Set P1.0 to push-pull
                                       // Set P1.1 to open-drain
                                       // Set P1.3 to push-pull
                                       // Set P1.4 to open-drain

   P0SKIP    = 0xFF;                   // Skip to place LIN on 1.0 and 1.1             

   XBR2      = 0x41;                   // Enable LIN, crossbar and weak pullups

   SFRPAGE = SFRPAGE_save;

}

//-----------------------------------------------------------------------------
// LIN0_Slave_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Intializes the LIN peripheral to slave mode.
//
// LIN is an asynchronous, serial communications interface. All LIN registers
// besides the control mode register (LIN0CF) are indirectly accessed; 
// the address is specified in the LINADDR register which points to a specific
// data register which can be accessed through the LINDATA register. 
// Waveforms and additional specifications can be found in the LIN consortium
// (http:\\www.lin-subbus.com).
//-----------------------------------------------------------------------------

void LIN0_Slave_Init (void)
{
   U8 SFRPAGE_save = SFRPAGE;
   SFRPAGE = CONFIG_PAGE;
// Enable interface, configure the device for LIN Slave, maunal baud rate
   LIN0CF = 0x80;
#if (AUTO_BAUD == 1)
   LIN0CF |= 0x20;                     // Automatic baud rate
#endif

   SFRPAGE = ACTIVE_PAGE;
   // Load the least significant byte of the divider.
   LIN0ADR = LIN0DIV;
   LIN0DAT = (U8) LIN_DIVIDER;

   LIN0ADR = LIN0MUL;
      
#if (AUTO_BAUD == 0)
   // Load the multiplier, prescalar, and most significant bit of the divider.
   LIN0DAT = (U8) ((LIN_PRESCALAR << 6) | (LIN_MULTIPLIER << 1) 
               | (LIN_DIVIDER >> 8));   
#else
   // Load the prescalar and most significant bit of the divider
   LIN0DAT = (U8) ((LIN_PRESCALAR << 6) | (LIN_DIVIDER >> 8));
#endif

   LIN0ADR = LIN0SIZE;
   LIN0DAT = 0x80;                     // Enhanced checksum

   EIE1 |= 0x80;                       // Enable LIN interrupts

   LIN0ADR = LIN0CTRL;
   LIN0DAT = 0x0C;                     // Reset LININT and LIN0ERR

   SFRPAGE = SFRPAGE_save;
}

//-----------------------------------------------------------------------------
// Interrupt Service Routines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// LIN0_ISR
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This ISR triggers when recieving a transmission from the master. Depending
// on what message is sent, LED P1^4_B will turn on/off. If the master sends 
// a request frame, it will check the status of SW1 and send back the 
// information.
//
//-----------------------------------------------------------------------------

INTERRUPT (LIN0_ISR, INTERRUPT_LIN0)
{
   U8 ID, status, error;
   static U8 num_error = 0;
   U8 SFRPAGE_save = SFRPAGE;
   SFRPAGE = ACTIVE_PAGE;

   LIN0ADR = LIN0ST;
   status = LIN0DAT;

   if (status & LININTREQ)             // If LIN interrupt request
   {
      if(status & DTREQ)               // If ID field received
      {
         LIN0ADR = LIN0ID;
         ID = LIN0DAT;

         if ((ID & ID_LED_SLAVE) == ID_LED_SLAVE)  // ID is to mess with slave
         {
            LIN0ADR = LIN0CTRL;        
            LIN0DAT &= ~TXRX;          // Select to receive data
         
            if (ID == ID_LED_SLAVE_ON)
            {
               LED = 1;                   
            }
            else if (ID == ID_LED_SLAVE_OFF) 
            {
               LED = 0;
            }
         }
         else                          // ID is to mess with master LED
         {

            LIN0ADR = LIN0CTRL;
            LIN0DAT |= TXRX;           // Select to transmit data

            LIN0ADR = LIN0SIZE;
            LIN0DAT = (LIN0DAT & 0xF0) | 0x01;  //transmit 1 data byte
            
            LIN0ADR = LIN0DT1;

            if (SW1 == 0)              // Switch is pressed
            {
               LIN0DAT = LED_MASTER_ON;
            }
            else                       // Switch is not pressed
            {
               LIN0DAT = LED_MASTER_OFF;
            }

         }            
      }
      else if (status & ERROR)         // If an error was detected
      {

         LIN0ADR = LIN0ERR;
         error = LIN0DAT;              // Check the error register
         // Keep track of the number of errors received
         num_error++;
         // Handle your errors here, application dependent

      }
      else if(status & DONE)           // If reception completed
      {
         // Transmission complete
      }
   }

   LIN0ADR = LIN0CTRL;          
   LIN0DAT |= DTACK;                   // Acknowledge data
   
   LIN0ADR = LIN0CTRL;
   LIN0DAT |= 0x0C;                    // Reset interrupt request, error flag
   
   SFRPAGE = SFRPAGE_save;

}

//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91在线视频18| 国产资源精品在线观看| 亚洲国产成人私人影院tom| 欧美高清www午色夜在线视频| 一本久道久久综合中文字幕| 成人免费毛片a| eeuss鲁片一区二区三区在线观看 eeuss鲁片一区二区三区在线看 | 91亚洲国产成人精品一区二区三 | 麻豆国产欧美日韩综合精品二区| 亚洲精品成人悠悠色影视| 国产精品第13页| 国产欧美日韩卡一| 国产精品久久久久影院| 日韩一区日韩二区| 一区二区三区毛片| 五月天婷婷综合| 蜜桃在线一区二区三区| 国内外成人在线| 白白色 亚洲乱淫| 91免费看视频| 欧美色综合网站| 日韩欧美一区在线| 欧美激情一二三区| 亚洲精品亚洲人成人网| 亚洲高清三级视频| 精品一区二区三区蜜桃| 国产成a人亚洲| 日本电影欧美片| 欧美片网站yy| 国产午夜精品久久| 一区二区三区在线播| 日韩影院精彩在线| 国产福利一区在线| 91久久免费观看| 日韩欧美中文一区| ●精品国产综合乱码久久久久| 一区二区三区在线影院| 久久99在线观看| av一本久道久久综合久久鬼色| 欧洲视频一区二区| 欧美va亚洲va在线观看蝴蝶网| 国产精品久久久久影院| 青草av.久久免费一区| 成人午夜电影小说| 91精品国产aⅴ一区二区| 欧美国产禁国产网站cc| 日韩成人伦理电影在线观看| 国产成人在线网站| 欧美一区永久视频免费观看| 国产精品人成在线观看免费| 日日摸夜夜添夜夜添国产精品| 国产69精品一区二区亚洲孕妇| 欧美日韩黄视频| 中文字幕永久在线不卡| 老司机一区二区| 91精品福利视频| 欧美国产欧美综合| 精品一区二区三区视频在线观看 | 亚洲国产精品精华液网站| 国产一区免费电影| 91精品视频网| 亚洲成人激情av| 97久久超碰国产精品| 久久久精品影视| 麻豆精品在线看| 欧美浪妇xxxx高跟鞋交| 亚洲手机成人高清视频| 粗大黑人巨茎大战欧美成人| 日韩欧美电影一区| 免费视频一区二区| 91精品国产综合久久福利| 亚洲一区二区三区自拍| 一本大道av一区二区在线播放| 国产亚洲一区二区三区| 国内成人自拍视频| 日韩一级高清毛片| 日本欧洲一区二区| 欧美色电影在线| 亚洲精品视频一区| 91蝌蚪porny| 中文字幕av资源一区| 成人一区二区三区在线观看 | 国产麻豆视频精品| 欧美高清hd18日本| 日韩高清不卡一区| 欧美一区二区三区免费视频| 26uuu国产在线精品一区二区| 天天免费综合色| 久久99久久久欧美国产| 欧美一区二区三区不卡| 亚洲影院理伦片| 911精品产国品一二三产区| 亚洲综合偷拍欧美一区色| 欧美日韩aaaaaa| 久久国产欧美日韩精品| 精品国产乱码久久| 成人av片在线观看| 亚洲永久精品大片| 日韩欧美二区三区| 成人激情动漫在线观看| 亚洲欧洲日韩在线| 欧美精选一区二区| 国产自产2019最新不卡| 国产精品久久99| 在线欧美小视频| 久久丁香综合五月国产三级网站| 久久久久久久综合狠狠综合| 成人av免费在线播放| 亚洲自拍偷拍欧美| 精品国产一区二区三区四区四| 大美女一区二区三区| 亚洲第一搞黄网站| 2020国产精品| 在线观看亚洲一区| 精品制服美女久久| 亚洲免费伊人电影| 日韩一区二区免费在线观看| 成人免费高清视频| 亚洲.国产.中文慕字在线| 亚洲国产精品t66y| 欧美精品 国产精品| 成人少妇影院yyyy| 石原莉奈在线亚洲三区| 国产精品久久网站| 日韩午夜小视频| 91在线一区二区三区| 国产在线视频一区二区三区| 一区二区在线观看免费视频播放| 精品国产乱码久久久久久闺蜜| 99久精品国产| 国产高清无密码一区二区三区| 一个色综合av| 国产精品传媒入口麻豆| 精品久久久久久综合日本欧美| 欧洲视频一区二区| www.日韩在线| 粉嫩在线一区二区三区视频| 青椒成人免费视频| 亚洲高清免费一级二级三级| 日韩码欧中文字| 久久精品水蜜桃av综合天堂| 91麻豆精品91久久久久同性| 在线免费一区三区| 在线一区二区视频| 97久久精品人人做人人爽50路| 国内精品伊人久久久久av影院 | 蜜桃在线一区二区三区| 亚洲韩国一区二区三区| 亚洲精品高清在线观看| 中文字幕在线一区| 欧美国产精品一区| 中国色在线观看另类| 国产人久久人人人人爽| 国产日韩一级二级三级| 国产午夜亚洲精品不卡| 日韩欧美一级二级三级| 日韩你懂的在线播放| 欧美一区二区视频免费观看| 欧美日韩一级片在线观看| 欧美乱熟臀69xxxxxx| 7777精品伊人久久久大香线蕉最新版 | 亚洲精品成人a在线观看| 亚洲另类在线制服丝袜| 亚洲女性喷水在线观看一区| 亚洲精品国产一区二区精华液 | 色综合久久综合中文综合网| aa级大片欧美| 97久久人人超碰| 日本道免费精品一区二区三区| www.视频一区| 欧美综合视频在线观看| 欧美三级日韩三级| 日韩视频一区二区三区| 337p日本欧洲亚洲大胆色噜噜| 亚洲精品在线免费播放| 国产精品美女一区二区三区| 日韩伦理电影网| 亚洲第一电影网| 久久精品国产99久久6| 国产精品一区二区在线观看不卡| 国产剧情在线观看一区二区| 波多野结衣亚洲| 欧美色网一区二区| 精品三级在线观看| 中文字幕一区二区三中文字幕| 男男视频亚洲欧美| 国产成人亚洲综合a∨婷婷| 91婷婷韩国欧美一区二区| 欧美日韩一区视频| 国产视频亚洲色图| 亚洲国产精品麻豆| 国产久卡久卡久卡久卡视频精品| 91免费看片在线观看| 91精品国产91久久久久久最新毛片| 26uuu久久综合| 亚洲国产日产av| 成人福利视频在线看| 欧美高清视频在线高清观看mv色露露十八 | 国产精品伦一区| 天堂蜜桃91精品|