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

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

?? i2c_master.c

?? STM32F10xx的LCD驅動源碼
?? C
字號:
/**************************************************************************************
In this case we use I2C1 as the I2C communication master->

   By default, it operates in slave mode. The interface automatically switches from slave to
master, after it generates a START condition and from master to slave, if an arbitration loss
or a Stop generation occurs, allowing multimaster capability.
   In Master mode, the I2C interface initiates a data transfer and generates the clock signal. A
serial data transfer always begins with a start condition and ends with a stop condition. Both
start and stop conditions are generated in master mode by software.
***************************************************************************************/

#include "I2C.h"
#include "stm32f10x_map.h"
#include "stm32f10x_rcc.h"


#define I2C1                ((I2C_TypeDef *) I2C1_BASE)
/************************************************************************************8
Function Name:I2C_MasterIni()
     Function:To initiate the I2C controllor as an I2C master->
    Parameter:I2C_TypeDef *I2C1:The target I2C controllor->
       Return:none
         Note:The following is the required sequence in master mode:
              1.Program the peripheral input clock in I2C_CR2 Register in order to generate correct timings.
              2.Configure the clock control registers.
              3.Configure the rise time register.TRISE[5:0] must be configured only when the I2C is disabled (PE = 0).
              4.Program the I2C_CR1 register to enable the peripheral.
              5.Set the START bit in the I2C_CR1 register to generate a Start condition.
              
*************************************************************************************/
void I2C_MasterIni(void)
{
   I2C1->CR2     =0x0104;       //The peripheral`s input clock is 36 MHz
   I2C1->CCR     =0x821C;       //cinfigure the clock control rigester as:Standard Mode,100KHz.Because the input clock is 36MHz,so to meet the 100KHZ bus clock demand ,TCK=1s/36MHZ,Tow=Thigh=5000ns,CCR[11:0]=Tow/TCK=180d=B4h
   I2C1->TRISE   =0x0022;       //configure the rise time rigester as :The maximum rising time in standard mode is 1000 ns.So TRISE=(1000ns/(1s/36MHz))+1
   I2C1->CR1    |=0x0401;       //Set ACK (Acknowledge returned after a byte is received (matched address or data)).Set PE bit to enable this peripheral.
}
/*void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct)
{
  u16 tmpreg = 0, freqrange = 0;
  u16 result = 0x04;
  u32 pclk1clock = 12000000;
  RCC_ClocksTypeDef  RCC_Clocks;

  /* Check the parameters */
/*  assert_param(IS_I2C_MODE(I2C_InitStruct->I2C_Mode));
  assert_param(IS_I2C_DUTY_CYCLE(I2C_InitStruct->I2C_DutyCycle));
  assert_param(IS_I2C_OWN_ADDRESS1(I2C_InitStruct->I2C_OwnAddress1));
  assert_param(IS_I2C_ACK_STATE(I2C_InitStruct->I2C_Ack));
  assert_param(IS_I2C_ACKNOWLEDGE_ADDRESS(I2C_InitStruct->I2C_AcknowledgedAddress));
  assert_param(IS_I2C_CLOCK_SPEED(I2C_InitStruct->I2C_ClockSpeed));

/*---------------------------- I2Cx CR2 Configuration ------------------------*/
  /* Get the I2Cx CR2 value */
 /* tmpreg = I2Cx->CR2;
  /* Clear frequency FREQ[5:0] bits */
 /* tmpreg &= CR2_FREQ_Reset;
  /* Get PCLK1Clock frequency value */
 /* RCC_GetClocksFreq(&RCC_Clocks);
  pclk1clock = RCC_Clocks.PCLK1_Frequency;
  /* Set frequency bits depending on PCLK1Clock value */
 /* freqrange = (u16)(pclk1clock / 1000000);
  tmpreg |= freqrange;
  /* Write to I2Cx CR2 */
//  I2Cx->CR2 = tmpreg;

/*---------------------------- I2Cx CCR Configuration ------------------------*/
  /* Disable I2Cx to configure TRISE */
 // I2C_Cmd(I2Cx, DISABLE);

  /* Reset tmpreg value */
  /* Clear F/S, DUTY and CCR[11:0] bits */
 // tmpreg = 0;

  /* Configure speed in standard mode */
 /* if (I2C_InitStruct->I2C_ClockSpeed <= 100000)
  {
    /* Standard mode speed calculate */
   // result = (u16)(pclk1clock / (I2C_InitStruct->I2C_ClockSpeed << 1));
    /* Test if CCR value is under 0x4*/
  /*  if (result < 0x04)
    {
      /* Set minimum allowed value */
    /*  result = 0x04;  
    }
    /* Set speed value for standard mode */
  //  tmpreg |= result;	  
    /* Set Maximum Rise Time: ((1000/(1000000000/pclk1clock))+1 */
  /*  I2Cx->TRISE = freqrange + 1; 
  }
  /* Configure speed in fast mode */
 // else /*(I2C_InitStruct->I2C_ClockSpeed <= 400000)*/
 /* {
    if (I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_2)
    {
      /* Fast mode speed calculate: Tlow/Thigh = 2 */
    /*  result = (u16)(pclk1clock / (I2C_InitStruct->I2C_ClockSpeed * 3));
    }
    else /*I2C_InitStruct->I2C_DutyCycle == I2C_DutyCycle_16_9*/
    //{
      /* Fast mode speed calculate: Tlow/Thigh = 16/9 */
     // result = (u16)(pclk1clock / (I2C_InitStruct->I2C_ClockSpeed * 25));
      /* Set DUTY bit */
     /* result |= I2C_DutyCycle_16_9;
    }
    /* Test if CCR value is under 0x1*/
   /* if ((result & CCR_CCR_Set) == 0)
    {
      /* Set minimum allowed value */
     /* result |= (u16)0x0001;  
    }
    /* Set speed value and set F/S bit for fast mode */
    /*tmpreg |= result | CCR_FS_Set;
    /* Set Maximum Rise Time: ((300/(1000000000/pclk1clock))+1 */
   /* I2Cx->TRISE = (u16)(((freqrange * 300) / 1000) + 1);  
  }
  /* Write to I2Cx CCR */
  //I2Cx->CCR = tmpreg;

  /* Enable I2Cx */
  //I2C_Cmd(I2Cx, ENABLE);

/*---------------------------- I2Cx CR1 Configuration ------------------------*/
  /* Get the I2Cx CR1 value */
 // tmpreg = I2Cx->CR1;
  /* Clear ACK, SMBTYPE and  SMBUS bits */
  //tmpreg &= CR1_CLEAR_Mask;
  /* Configure I2Cx: mode and acknowledgement */
  /* Set SMBTYPE and SMBUS bits according to I2C_Mode value */
  /* Set ACK bit according to I2C_Ack value */
 // tmpreg |= (u16)((u32)I2C_InitStruct->I2C_Mode | I2C_InitStruct->I2C_Ack);
  /* Write to I2Cx CR1 */
 // I2Cx->CR1 = tmpreg;

/*---------------------------- I2Cx OAR1 Configuration -----------------------*/
  /* Set I2Cx Own Address1 and acknowledged address */
  ///I2Cx->OAR1 = (I2C_InitStruct->I2C_AcknowledgedAddress | I2C_InitStruct->I2C_OwnAddress1);
//}*/
/*********************************************************************************
Function Name:I2C_Start( )
     Function:This function will be used by the master to generate a start signal
    Parameter:I2C_TypeDef *I2C1:The target I2C controllor->
       Return:none
         Note:Setting the START bit causes the interface to generate a Start condition and to switch to
              Master mode (M/SL bit set) when the BUSY bit is cleared(BUSY: Bus Busy,Set by hardware on
              detection of SDA or SCL low,cleared by hardware on detection of a Stop condition.).
**********************************************************************************/
void I2C_Start(void)
{  
   I2C1->CR1 = 0x0401 ; 
   I2C1->CR1 |= 0x0100 ;                         //Set START bit to generate a start condition->
   while((!(I2C1->SR1&0x0001)));                   //Wait for start condition generation finishment.Or, the peripheral enter master mode(M/SL bit set.). 
}
/**********************************************************************************************************************************************
Function Name:Address_Sending( )
     Function:To send the slave address->
    Parameter:u8 Dataphase_Mode:Reciver or Transmitter
              u8 AddressHeader :In 10_bit address mode ,here is the address header->
              u8 Low_Address   :The address to be sent in 7_bit address mode or the lower 8 bits address to be sent in 10_bit address mode->
              u8 Addring_Mode  :Addring_Mode_10 to indicate here is a 10_bit address or Addring_Mode_7 to indicate here is a 7_bit address->
              I2C_TypeDef  I2C1:The target I2C controllor->
       Return:none
         Note:
*********************************************************************************************************************************************/
void Address_Sending(u8 Dataphase_Mode,u8 AddressHeader,u8 Low_Address,u8 Addring_Mode)
{
   if(Addring_Mode==Addring_Mode_10)
    {
      I2C1->DR=AddressHeader;
      while(!(I2C1->SR1&0x0008));
      I2C1->DR=Low_Address;
      if(Dataphase_Mode==Reciver)
       {
        while (!(I2C1->SR1&0x0002));
        I2C_Start(); 
        I2C1->DR = AddressHeader;
       }
    }else
     {
      if(Dataphase_Mode==Reciver)
       {
          Low_Address |= 0x01;
          I2C1->DR     = Low_Address;                     //Send the slave address with LSB set->
             while(!(I2C1->SR1&0x0002)) ;                //Wait till the ADDR bit set->Clear the ADDR bit by read SR1 followed by a DR read or write.
            while((I2C1->SR2 &0x0004)) ;
       }else
         {
           Low_Address &= 0xFE;
           I2C1->DR     = Low_Address;                    //Send the slave address with LSB reset->
              while(!(I2C1->SR1&0x0002)) ;                //Wait till the ADDR bit set->Clear the ADDR bit by read SR1 followed by a DR read or write.
              while(!(I2C1->SR2&0x0004)) ;
         }
    }

}
/****************************************************************************************
Function Name:I2C_ReciveByte( )
     Function:To process the reciption of a byte->
    Parameter:none
       Return:         u8 RecivedByte:The recived byte->
              I2C_TypeDef *I2C1:The target I2C controllor->
         Note:
****************************************************************************************/
u8 I2C_ReciveByte(void)
{
  while (!( I2C1->SR1&0x0040)) ;                      //Wail for RxNE set , indicates that a byte has been recived successfully->                            // So, read ou the recived byte to ready for use->
  return I2C1->DR;
}

/****************************************************************************************
Function Name:I2C_SendByte( )
     Function:To send a byte of data->
    Parameter:         u8 ByteToSend
              I2C_TypeDef *I2C1:The target I2C controllor->
       Return:none
         Note:
****************************************************************************************/
void I2C_SendByte(u8 ByteToSend)
{
	I2C1->DR=ByteToSend;                                 //Write a byte to the DR to ready for sending-> 
  while (!( I2C1->SR1&0x0080));                        //Wait till TxE   set indicates that the byte sent finisheed successfully->
}
/**********************************************************************************************************************************************
Function Name:I2C_SendBlock( )
     Function:To send a data block->
    Parameter:         u8 *BlockToSend:The address of the first byte of the block to be sent->
                       u8 Total_Btyes :The size of the block in byte->
              I2C_TypeDef *I2C1        :The target I2C controllor->
       Return:none
         Note:
*********************************************************************************************************************************************/
void I2C_SendBlock(u8 *BlockToSend,u8 Total_Bytes)
{
	 I2C1->DR=*BlockToSend;                              //Write a byte to the DR to ready for senting-> 
         BlockToSend++;                                      //Point to the next to be sent byte->
         Total_Bytes--;                                      //Total of the bytes to be sent decriment by 1->
     
  while (Total_Bytes)                                      //If all the bytes have been sent,than continue->
   {
     if(I2C1->SR1&0x0080)                                  //TxE  set indicates that the byte sent finisheed successfully->
     {
       I2C1->DR=*BlockToSend;                              //So , write anther byte to the DR to ready for senting-> 
       BlockToSend++;                                      //Point to the next to be sent byte->
       Total_Bytes--;                                      //Total of the bytes to be sent decriment by 1->
     }
   }
}
/**************************************************************************************
Function Name:I2C_Stop()
     Function:This function will be used by the master to generate a stop signal of the transmittion
    Parameter:I2C_TypeDef *I2C1:The target I2C controllor->
       Return:none
         Note:
****************************************************************************************/
void I2C_Stop_Write(void)
{
  while(!( I2C1->SR1&0x0080));                    //Wait till the last byte sent succesfully->
  I2C1->CR1 |=0x0200  ;                         //Set STOP bit to generate a start condition->
  
}
void I2C_Stop_Read(void)
{
  /* Send I2C1 STOP Condition */
      while(!( I2C1->SR1&0x0040));                    //Wait till the last byte sent succesfully->
       I2C1->CR1 |=0x0200  ;  
}
/**********************************************************************************************************************************************
Function Name:Recive_Data_From_A_slave()
     Function:To send the slave address->
    Parameter:u8 AddressHeader :In 10_bit address mode ,here is the address header->
              u8 Low_Address   :The address to be sent in 7_bit address mode or the lower 8 bits address to be sent in 10_bit address mode->
              u8 Addring_Mode  :Addring_Mode_10 to indicate here is a 10_bit address or Addring_Mode_7 to indicate here is a 7_bit address->
              u8 *Buffer       :The recived data buffer address->
              u8 Total         :The total number of bytes to be recived from a slave->
       Return:u8 ERR_Flag      :The erro type if occured ->
         Note:
*********************************************************************************************************************************************/
u8 Recive_Data_From_A_slave(u8 *Buffer,u8 Total,u8 Header,u8 Low_Address,u8 Addring_Mode)
{
	u8 ERR_Flag=0;
	I2C_MasterIni();
	I2C_Start();
	Address_Sending(Reciver,Header,Low_Address,Addring_Mode);
	while(Total>1)
	{
		*Buffer=I2C_ReciveByte();
		Buffer++;
		Total--;
	}
	I2C_Stop_Read();                                                         //Set the stop bit wright after the second last byte recived successfully,to generate a stop condition after the last byte reciption->
	*Buffer=I2C_ReciveByte();                                           //Recive the last byte->
	return ERR_Flag;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲人成网站色在线观看| 欧美视频一区在线| 午夜激情一区二区| 亚洲国产精品综合小说图片区| 国产欧美日韩三区| 久久久美女毛片| 久久久91精品国产一区二区精品| 日韩欧美中文字幕一区| 欧美一区二区在线免费观看| 欧美精品777| 欧美v日韩v国产v| 久久一区二区视频| 国产精品人成在线观看免费| 国产清纯白嫩初高生在线观看91| 国产精品美女久久久久aⅴ国产馆| 国产亚洲自拍一区| 国产精品污污网站在线观看| 中文字幕中文在线不卡住| 最新成人av在线| 亚洲1区2区3区4区| 蜜桃视频第一区免费观看| 国产激情偷乱视频一区二区三区 | 国产精品女同互慰在线看| 中文字幕乱码久久午夜不卡| 亚洲色图欧洲色图婷婷| 日韩中文字幕1| 国产一区二区三区四区五区入口| 99久久综合精品| 欧美日韩精品欧美日韩精品| 精品国产一区二区三区不卡| 国产精品久久综合| 亚洲综合久久av| 国内不卡的二区三区中文字幕| 91美女片黄在线观看91美女| 日韩一区二区电影| 国产精品久久久久四虎| 日韩精品一级中文字幕精品视频免费观看 | 亚洲柠檬福利资源导航| 日日噜噜夜夜狠狠视频欧美人| 麻豆精品一二三| 国产高清不卡一区| 在线观看免费成人| 久久久综合视频| 亚洲一级二级三级| 国产丶欧美丶日本不卡视频| 欧美日本一道本| 国产精品久久毛片a| 久久精品国产一区二区三| 99国产精品一区| 久久你懂得1024| 日韩精品欧美成人高清一区二区| 成人小视频在线| 精品国产乱码久久久久久影片| 亚洲一区中文在线| 高清国产一区二区| 日韩免费观看高清完整版| 亚洲国产成人精品视频| 夫妻av一区二区| www久久久久| 国内欧美视频一区二区| 欧美日韩三级一区| 亚洲欧美日韩国产手机在线| 福利一区二区在线| 久久综合九色欧美综合狠狠| 青青草97国产精品免费观看无弹窗版| 色乱码一区二区三区88| 国产精品欧美一区喷水| 国产大陆亚洲精品国产| 日韩午夜激情电影| 男人的j进女人的j一区| 欧美视频你懂的| 亚洲国产一区二区视频| 欧美丝袜丝交足nylons| 亚洲精品国产一区二区精华液| 成人激情免费网站| 国产精品每日更新| 成人深夜在线观看| 国产精品美女久久久久久久久 | 自拍偷拍国产亚洲| av不卡一区二区三区| 自拍偷在线精品自拍偷无码专区| aa级大片欧美| 亚洲欧美另类图片小说| 色就色 综合激情| 一区二区欧美在线观看| 欧洲中文字幕精品| 亚洲成av人**亚洲成av**| 欧美精品高清视频| 麻豆91在线播放免费| 日韩美女一区二区三区| 男男成人高潮片免费网站| 欧美va天堂va视频va在线| 国产综合色在线视频区| 国产欧美精品区一区二区三区| 国产成人a级片| 亚洲人精品午夜| 欧美日本一区二区| 久久精品国产第一区二区三区| 久久久91精品国产一区二区精品| 成人av资源站| 亚洲国产综合91精品麻豆| 欧美一级欧美三级在线观看 | 亚洲欧美电影一区二区| 欧美日韩成人高清| 极品少妇一区二区| 中文字幕亚洲一区二区va在线| 99精品在线免费| 日日嗨av一区二区三区四区| 在线播放一区二区三区| 丁香婷婷深情五月亚洲| 亚洲自拍偷拍欧美| 日韩欧美卡一卡二| 91在线精品一区二区| 久久国产精品99精品国产| 中文字幕亚洲一区二区av在线| 9191成人精品久久| 韩国三级中文字幕hd久久精品| 亚洲天堂2016| 91精品国产欧美一区二区成人| 丁香网亚洲国际| 日韩高清一区二区| 中文字幕人成不卡一区| 日韩一区二区三区四区| 国产成人免费9x9x人网站视频| 亚洲国产精品精华液网站| 国产精品无人区| 精品国产一区二区三区av性色| 91亚洲永久精品| 国模少妇一区二区三区| 日日夜夜精品视频天天综合网| 亚洲欧美aⅴ...| 精品sm捆绑视频| 欧美在线观看禁18| 成人不卡免费av| 国产老妇另类xxxxx| 亚洲午夜久久久久久久久电影院 | 成人91在线观看| 日本不卡视频一二三区| 亚洲摸摸操操av| 久久久久久久久免费| 在线观看一区日韩| 美洲天堂一区二卡三卡四卡视频 | 欧美精品日韩精品| aaa欧美日韩| 成人免费毛片app| 国产高清精品在线| 久久国产精品99久久人人澡| 午夜国产精品影院在线观看| 自拍偷拍亚洲综合| 欧美极品美女视频| 久久久久久久久久电影| 久久综合给合久久狠狠狠97色69| 欧美电影一区二区三区| 欧美精品xxxxbbbb| 777午夜精品免费视频| 欧美日产国产精品| 欧美中文字幕亚洲一区二区va在线 | 一区二区三区四区在线| 国产精品久久久久影院亚瑟| 亚洲国产精品99久久久久久久久| 91精品国产综合久久久久久漫画| 欧美三片在线视频观看| 欧美视频在线一区| 欧美日韩国产色站一区二区三区| 成人国产免费视频| 色婷婷精品久久二区二区蜜臂av| 欧美自拍偷拍午夜视频| 欧美午夜电影一区| 欧美精品色一区二区三区| 欧美人与性动xxxx| 日韩你懂的电影在线观看| 26uuu欧美日本| 综合中文字幕亚洲| 亚洲影视资源网| 日韩高清中文字幕一区| 麻豆成人久久精品二区三区红| 成人综合婷婷国产精品久久蜜臀| 国产东北露脸精品视频| 日韩高清不卡在线| 国产高清精品在线| 91福利资源站| 久久精品免费在线观看| 亚洲你懂的在线视频| 麻豆国产一区二区| 成人免费不卡视频| 欧美日韩一区中文字幕| 欧美精品一区二区三区久久久| 国产精品久久久久四虎| 日韩影院在线观看| 丁香一区二区三区| 欧美酷刑日本凌虐凌虐| 国产亚洲va综合人人澡精品 | 欧美高清视频www夜色资源网| 精品剧情在线观看| 亚洲乱码国产乱码精品精的特点 | 国产大片一区二区| 欧美日韩国产美女| 久久精品一区八戒影视| 综合激情成人伊人| 国产在线不卡一卡二卡三卡四卡|