標(biāo)題:
stm8單片機(jī)IIC讀寫(xiě)24c32芯片源程序
[打印本頁(yè)]
作者:
王杰
時(shí)間:
2019-8-9 14:02
標(biāo)題:
stm8單片機(jī)IIC讀寫(xiě)24c32芯片源程序
大家一起學(xué)習(xí)探討
單片機(jī)源程序如下:
/*
******************************************************************************
* @file 24c32.c
* @author Wang
* @version V1.0.0
* @date 6-August-2019
* @brief This file contains all the functions for the read or write 24c32
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "24c32.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* Public functions ----------------------------------------------------------*/
/*
* @brief Write data to 24c32 device
* @param addr : slaver address
* @param reg_addr : register address
* @param send_data : send data
* @retval None
*/
void Write_24c32(uint8_t addr , uint8_t reg_addr , uint8_t send_data )
{
Soft_iic_Start();
Soft_iic_Write_Byte(addr);
Soft_iic_Write_Byte(reg_addr>>8); /*High address */
Soft_iic_Write_Byte(reg_addr%256); /*Low address */
Soft_iic_Write_Byte(send_data);
Soft_iic_Stop();
}
/*
* @brief Read data from 24c32 device
* @param addr : slaver address
* @param reg_addr : register address
* @retval return read data from DS1307 device
*/
uint8_t Read_24c32(uint8_t addr , uint8_t reg_addr)
{
uint8_t data = 0;
Soft_iic_Start();
Soft_iic_Write_Byte(addr);
Soft_iic_Write_Byte(reg_addr>>8); /*High address */
Soft_iic_Write_Byte(reg_addr%256); /*Low address */
Soft_iic_Start();
Soft_iic_Write_Byte(addr | 0x01);
data = Soft_iic_Read_Byte(0);
Soft_iic_Stop();
return data;
}
/*
* @brief Test the 24c32 about read and write
* @param None
* @retval None
*/
void Test_24c32(void)
{
uint8_t recv_data;
Write_24c32(0xA0,0,10);
Soft_delay_10us(500); /* need to add delay */
recv_data = Read_24c32(0xA0,0);
if(recv_data == 10)
{
LED_On();
Timer1_Delay_1ms(100);
LED_Off();
Timer1_Delay_1ms(100);
}
}
/****************************END OF FILE**************************************/
復(fù)制代碼
所有資料51hei提供下載:
Project_2.7z
(3.8 MB, 下載次數(shù): 52)
2019-8-9 17:55 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
amwu_1984
時(shí)間:
2019-9-17 10:39
收藏學(xué)習(xí)一下
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1