📄 pcf8563.c
字号:
/*
*CopyRight Reserved: MR QIU
*文件名:PCF8563.c
*描述:提供8563的底层驱动。
*
*版本:v1.0
*作者:ktop
*日期:2004/12/31
*/
#define PCF8563_C
#include "PCF8563.h"
#include "stm32f10x_it.h"
/*******************************************************
*Name:I2C_8563_PageWrite
* input:u8* pBuffer, u8 WriteAddr, u8 NumByteToWrite
* output:none
*
*********************************************************/
void I2C_8563_PageWrite(u8* pBuffer, u8 WriteAddr, u8 NumByteToWrite)
{
/* Send START condition */
I2C_GenerateSTART(I2C_MASTER, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C_MASTER, I2C_EVENT_MASTER_MODE_SELECT));
/* Send 8563 address for write */
I2C_Send7bitAddress(I2C_MASTER, WRITE_ADDR, I2C_Direction_Transmitter);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C_MASTER, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
/* Send the 8563's internal address to write to */
I2C_SendData(I2C_MASTER, WriteAddr);
/* Test on EV8 and clear it */
while(! I2C_CheckEvent(I2C_MASTER, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* While there is data to be written */
while(NumByteToWrite--)
{
/* Send the current byte */
I2C_SendData(I2C_MASTER, *pBuffer);
/* Point to the next byte to be written */
pBuffer++;
/* Test on EV8 and clear it */
while (!I2C_CheckEvent(I2C_MASTER, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
}
/* Send STOP condition */
I2C_GenerateSTOP(I2C_MASTER, ENABLE);
}
/******************************************************************************
* name: 2C_8563_BufferRead
* input: pBuffer read to it,ReadAddr read address,NumByteToRead the number
* of ready to read
* output: None
*******************************************************************************/
void I2C_8563_BufferRead(u8* pBuffer, u8 ReadAddr, u16 NumByteToRead)
{
/* Send START condition */
I2C_GenerateSTART(I2C_MASTER, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C_MASTER, I2C_EVENT_MASTER_MODE_SELECT));
/* In the case of a single data transfer disable ACK before reading the data */
if(NumByteToRead==1)
{
I2C_AcknowledgeConfig(I2C_MASTER, DISABLE);
}
/* Send 8563 address for write */
I2C_Send7bitAddress(I2C_MASTER, WRITE_ADDR, I2C_Direction_Transmitter);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C_MASTER, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
/* Clear EV6 by setting again the PE bit */
I2C_Cmd(I2C_MASTER, ENABLE);
/* Send the 8563's internal address to write to */
I2C_SendData(I2C_MASTER, ReadAddr);
/* Test on EV8 and clear it */
while(!I2C_CheckEvent(I2C_MASTER, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STRAT condition a second time */
I2C_GenerateSTART(I2C_MASTER, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C_MASTER, I2C_EVENT_MASTER_MODE_SELECT));
/* Send 8563 address for read */
I2C_Send7bitAddress(I2C_MASTER, READ_ADDR, I2C_Direction_Receiver);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C_MASTER, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
/* While there is data to be read */
while(NumByteToRead)
{
/* Test on EV7 and clear it */
if(I2C_CheckEvent(I2C_MASTER, I2C_EVENT_MASTER_BYTE_RECEIVED))
{
if(NumByteToRead == 2)
{
/* Disable Acknowledgement */
I2C_AcknowledgeConfig(I2C_MASTER, DISABLE);
}
if(NumByteToRead == 1)
{
/* Send STOP Condition */
I2C_GenerateSTOP(I2C_MASTER, ENABLE);
}
/* Read a byte from the 8563 */
*pBuffer = I2C_ReceiveData(I2C_MASTER);
/* Point to the next location where the byte read will be saved */
pBuffer++;
/* Decrement the read bytes counter */
NumByteToRead--;
}
}
/* Enable Acknowledgement to be ready for another reception */
I2C_AcknowledgeConfig(I2C_MASTER, ENABLE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -