132 lines
3.4 KiB
C
132 lines
3.4 KiB
C
/*
|
|
******************************************************************************
|
|
*
|
|
* @file user.c
|
|
* @brief user module
|
|
* @ic sy8835
|
|
*
|
|
* @version 1.0
|
|
* @date 2024/11/01 09:59:40
|
|
* @author Alex Xu
|
|
*
|
|
* Copyright (c) 2013-2099,Tkplusemi Technology Co.,Ltd.
|
|
* All Rights Reserved
|
|
*
|
|
* History:
|
|
* Revision Date Author Desc
|
|
* 1.0.0 2024/11/01 Alex Xu build this file
|
|
******************************************************************************
|
|
*/
|
|
/*_____ I N C L U D E S ____________________________________________________*/
|
|
|
|
#include "user.h"
|
|
|
|
|
|
/******************************************************************************\
|
|
Macro definitions
|
|
\******************************************************************************/
|
|
|
|
/******************************************************************************\
|
|
Variables definitions
|
|
\******************************************************************************/
|
|
|
|
/******************************************************************************\
|
|
Functions definitions
|
|
\******************************************************************************/
|
|
|
|
/*******************************************************************************
|
|
* Function Name : ExtSfr_Write
|
|
* Description : ExtSfr Write a Byte
|
|
* Input : Will Send Date
|
|
* Output : None
|
|
* Return : None
|
|
******************************************************************************
|
|
*/
|
|
void ExtSfr_Write(u8 reg_addr,u8 _dat)
|
|
{
|
|
SFRADDR = reg_addr;
|
|
SFRDATA = _dat;
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function Name : ExtSfr_Read
|
|
* Description : ExtSfr Read a Byte
|
|
* Input : Will Send Date
|
|
* Output : None
|
|
* Return : None
|
|
******************************************************************************
|
|
*/
|
|
u8 ExtSfr_Read(u8 reg_addr)
|
|
{
|
|
u8 Data = 0;
|
|
|
|
SFRADDR = reg_addr;
|
|
Data = SFRDATA;
|
|
|
|
return Data;
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function Name : I2cSfr_Write
|
|
* Description : I2cSfr Write a Byte
|
|
* Input : Will Send Date
|
|
* Output : None
|
|
* Return : None
|
|
******************************************************************************
|
|
*/
|
|
void I2cSfr_Write(u8 reg_addr,u8 _dat)
|
|
{
|
|
I2C_Start();
|
|
|
|
//device address
|
|
I2C_SendByte(I2C_SFR_ADDR<<1);//send the address for write
|
|
I2C_WaitAck();
|
|
|
|
//Register address
|
|
I2C_SendByte(reg_addr);
|
|
I2C_WaitAck();
|
|
|
|
//data
|
|
I2C_SendByte(_dat);
|
|
I2C_WaitAck();
|
|
I2C_Stop();
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Function Name : I2cSfr_Read
|
|
* Description : I2cSfr Read a Byte
|
|
* Input : Will Send Date
|
|
* Output : None
|
|
* Return : None
|
|
******************************************************************************
|
|
*/
|
|
u8 I2cSfr_Read(u8 reg_addr)
|
|
{
|
|
uint8_t readdata = 0;
|
|
|
|
I2C_Start();
|
|
|
|
//device address
|
|
I2C_SendByte(I2C_SFR_ADDR<<1);//send the address for write
|
|
I2C_WaitAck();
|
|
|
|
//Register address
|
|
I2C_SendByte(reg_addr);
|
|
I2C_WaitAck();
|
|
|
|
I2C_Start();
|
|
|
|
//device address
|
|
I2C_SendByte((I2C_SFR_ADDR<<1) | 1);//send the address for read
|
|
I2C_WaitAck();
|
|
|
|
//data
|
|
readdata = I2C_ReadByte();
|
|
I2C_NoAck();
|
|
I2C_Stop();
|
|
|
|
return readdata;
|
|
}
|
|
|
|
|