找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2872|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

stm8單片機IIC讀寫24c32芯片源程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:125378 發(fā)表于 2019-8-9 14:02 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
大家一起學(xué)習(xí)探討

單片機源程序如下:
  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**************************************/
復(fù)制代碼

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


評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:612010 發(fā)表于 2019-9-17 10:39 | 只看該作者
收藏學(xué)習(xí)一下
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表