欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: stm8單片機IIC讀寫24c32芯片源程序 [打印本頁]

作者: 王杰    時間: 2019-8-9 14:02
標題: stm8單片機IIC讀寫24c32芯片源程序
大家一起學習探討

單片機源程序如下:
  1. /*
  2.   ******************************************************************************
  3.   * @file    24c32.c
  4.   * @author  Wang
  5.   * @version V1.0.0
  6.   * @date    6-August-2019
  7.   * @brief   This file contains all the functions for the read or write 24c32  
  8.   ******************************************************************************
  9. */

  10. /* Includes ------------------------------------------------------------------*/
  11. #include "24c32.h"

  12. /* Private typedef -----------------------------------------------------------*/
  13. /* Private define ------------------------------------------------------------*/
  14. /* Private macro -------------------------------------------------------------*/
  15. /* Private variables ---------------------------------------------------------*/
  16. /* Private function prototypes -----------------------------------------------*/
  17. /* Private functions ---------------------------------------------------------*/

  18. /* Public functions ----------------------------------------------------------*/


  19. /*
  20.   * @brief  Write data to 24c32 device
  21.   * @param  addr : slaver address
  22.   * @param  reg_addr : register address
  23.   * @param  send_data : send data
  24.   * @retval None
  25. */
  26. void Write_24c32(uint8_t addr , uint8_t reg_addr , uint8_t send_data )
  27. {
  28.         Soft_iic_Start();
  29.         Soft_iic_Write_Byte(addr);
  30.         Soft_iic_Write_Byte(reg_addr>>8);        /*High address */
  31.         Soft_iic_Write_Byte(reg_addr%256);        /*Low address */
  32.         Soft_iic_Write_Byte(send_data);
  33.         Soft_iic_Stop();
  34. }

  35. /*
  36.   * @brief  Read data from 24c32 device
  37.   * @param  addr : slaver address
  38.   * @param  reg_addr : register address
  39.   * @retval return read data from DS1307 device
  40. */
  41. uint8_t Read_24c32(uint8_t addr , uint8_t reg_addr)
  42. {
  43.         uint8_t data = 0;
  44.         Soft_iic_Start();
  45.         Soft_iic_Write_Byte(addr);
  46.         Soft_iic_Write_Byte(reg_addr>>8);        /*High address */
  47.         Soft_iic_Write_Byte(reg_addr%256);        /*Low address */
  48.        
  49.         Soft_iic_Start();
  50.         Soft_iic_Write_Byte(addr | 0x01);
  51.         data = Soft_iic_Read_Byte(0);
  52.         Soft_iic_Stop();
  53.         return data;
  54. }

  55. /*
  56.   * @brief  Test the 24c32 about read and write
  57.   * @param  None
  58.   * @retval None
  59. */

  60. void Test_24c32(void)
  61. {
  62.         uint8_t recv_data;
  63.         Write_24c32(0xA0,0,10);
  64.         Soft_delay_10us(500);  /* need to add delay */
  65.         recv_data = Read_24c32(0xA0,0);
  66.        
  67.         if(recv_data == 10)
  68.                 {
  69.                         LED_On();
  70.                         Timer1_Delay_1ms(100);
  71.                         LED_Off();
  72.                         Timer1_Delay_1ms(100);
  73.                 }
  74. }

  75. /****************************END OF FILE**************************************/
復制代碼

所有資料51hei提供下載:
Project_2.7z (3.8 MB, 下載次數: 52)



作者: amwu_1984    時間: 2019-9-17 10:39
收藏學習一下




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1