一、引脚介绍
1.引脚图
2.引脚描述
二、功能介绍
1.当作输入口,读取I/O口的电平
2.当作输出口,输出高低电平
3.中断功能,检测电平的变化
三、XJ9554的驱动
XJ9554.C
/*
* AT9554.c
*
* Created on: 2024年8月19日
* Author: Administrator
*/
#include "softiic.h"
#include "AT9554.h"
#include "usart.h"
#include <stdio.h>
//XJ9554的IIC读
uint8_t XJ9554ReadOneByte(uint8_t ReadAddr)
{
uint8_t temp=0;
bsp_analog_i2c_start();
bsp_analog_i2c_send_byte(0X40);
bsp_analog_i2c_wait_ack();
bsp_analog_i2c_send_byte(ReadAddr);
bsp_analog_i2c_wait_ack();
bsp_analog_i2c_start();
bsp_analog_i2c_send_byte(0X41);
bsp_analog_i2c_wait_ack();
temp= bsp_analog_i2c_read_byte();
bsp_analog_i2c_nack();
bsp_analog_i2c_stop();
return temp;
}
//XJ9554的IIC写
void XJ9554WriteOneByte(uint8_t WriteAddr,uint8_t DataToWrite)
{
bsp_analog_i2c_start();
bsp_analog_i2c_send_byte(0x40);
bsp_analog_i2c_wait_ack();
bsp_analog_i2c_send_byte(WriteAddr);
bsp_analog_i2c_wait_ack();
bsp_analog_i2c_send_byte(DataToWrite);
bsp_analog_i2c_wait_ack();
bsp_analog_i2c_stop();
}
/***
功能:设置I/O口输出高或者输出低
输入:pin 引脚
state SET为高,RESET为低
返回:无
*****/
void XJ9554_set_pin(uint8_t pin, uint8_t state)
{
unsigned char data0 = XJ9554ReadOneByte(OUTPUT_PORT_REG);
unsigned char data1 = XJ9554ReadOneByte(CONFIGURATION_REG);
if (state)
{
data0 |= 1 << pin;
}
else
{
data0 &= ~(1 << pin);
}
data1 &= ~(1 << pin);
XJ9554WriteOneByte(OUTPUT_PORT_REG, data0);
XJ9554WriteOneByte(CONFIGURATION_REG, data1 );
}
/***
功能:获取I/O口的输入电平
输入:pin 引脚
返回:1 I/O口的电平为高
0 I/O口的电平为低
*****/
uint8_t XJ9554_get_pin(uint8_t pin)
{
unsigned char data0 = XJ9554ReadOneByte(INPUT_PORT_REG);
unsigned char data1 = XJ9554ReadOneByte(CONFIGURATION_REG);
data1 &= ~(1 << pin);
XJ9554WriteOneByte(CONFIGURATION_REG, data1 );
return (data0 & (1 << pin)) != 0;
}
/***
功能:改变I/O口的输入极性
输入:pin 引脚
Value RESET正极性 SET正极性
返回:
*****/
void XJ9554_Polarity(uint8_t pin, uint8_t Value)
{
unsigned char data = XJ9554ReadOneByte(POLARITY_INVERSION_REG);
if (Value)
{
data |= 1 << pin;
}
else
{
data &= ~(1 << pin);
}
XJ9554WriteOneByte(POLARITY_INVERSION_REG, data );
}
XJ9554.H
/*
* AT9554.h
*
* Created on: 2024年8月19日
* Author: Administrator
*/
#ifndef INC_AT9554_H_
#define INC_AT9554_H_
#define INPUT_PORT_REG 0x00
#define OUTPUT_PORT_REG 0x01
#define POLARITY_INVERSION_REG 0x02
#define CONFIGURATION_REG 0x03
#define RESET 0
#define SET 1
uint8_t XJ9554ReadOneByte(uint8_t ReadAddr);
void XJ9554WriteOneByte(uint8_t WriteAddr,uint8_t DataToWrite);
void XJ9554_set_pin(uint8_t pin, uint8_t state);
uint8_t XJ9554_get_pin(uint8_t pin);
void XJ9554_Polarity(uint8_t pin, uint8_t Value);
#endif /* INC_AT9554_H_ */