鸿蒙硬件HI3861-I2C-MCP23017

如果有什么问题可以来B站问我

https://space.bilibili.com/309103931

1.什么是MCP23017

我是一款基于I2C接口控制的I/O扩展模块,可外扩16个I/O口,支持同时使用多达8个扩展模块,即可扩至128个I/O口,兼容3.3V和5V电平。

I2C接口控制,仅需2根信号线,即可扩展出16个I/O口,I2C通信地址可设置,短接A0/A1/A2焊点可修改通信地址

提供PH2.0端子和焊盘两种接口类型,支持并联多个I2C模块,板载电平转换电路,可兼容3.3V/5V的工作电平

【我的参数】

工作电压:5V/3.3V,控制接口:I2C,中断引脚:INTA、INTB,扩展I/O口数量:16个

2.目录结构

3.MCP23017函数

MCP23017.h

#ifndef MCP23017_H
#define MCP23017_H#include <hi_types_base.h>//-------------------------------定义MCP017内部寄存器地址------------------------------
#define MCP23017_IODIR          0x00
#define MCP23017_IPOL           0x02
#define MCP23017_GPINTEN        0x04
#define MCP23017_DEFVAL         0x06
#define MCP23017_INTCON         0x08
#define MCP23017_IOCON          0x0A
#define MCP23017_GPPU           0x0C
#define MCP23017_INTF           0x0E
#define MCP23017_INTCAP         0x10
#define MCP23017_GPIO           0x12
#define MCP23017_OLAT           0x14
//-------------------------------定义MCP017内部寄存器地址------------------------------ //-------------------------------定义辅助宏定义----------------------------------------
#define MCP23017_PORTA          0x00
#define MCP23017_PORTB          0x01
//-------------------------------定义辅助宏定义---------------------------------------- //-------------------------------定义输入输出------------------------------------------
#define INPUT                   0x01
#define OUTPUT                  0x00
//-------------------------------定义输入输出------------------------------------------//-------------------------------定义使能或除能----------------------------------------
#define ENABLE                  0x01
#define DISABLE                 0x00
#define SET                     0x01
#define RESET                   0x00
//-------------------------------定义使能或除能----------------------------------------//-------------------------------定义是否对端口极性取反---------------------------------
//-------------------------------当设置为取反时,读取的端口状态与实际输入状态极性相反------
#define POLARITY_REVERSE        0x01
#define POLARITY_NON_REVERSE    0x00
#define PIN0                    0x01
#define PIN1                    0x02
#define PIN2                    0x04
#define PIN3                    0x08
#define PIN4                    0x10
#define PIN5                    0x20
#define PIN6                    0x40
#define PIN7                    0x80
#define ALLPIN                  0xFF
//-------------------------------定义是否对端口极性取反---------------------------------//-------------------------------定义中断的类型----------------------------------------
#define DIS_INTERRUPT           0x00       //关闭中断
#define HIGHLEVEL_INTERRUPT     0x01       //高电平中断
#define LOWLEVEL_INTERRUPT      0x02       //低电平中断
#define CHANGE_INTERRUPT        0x03       //电平变化中断
//-------------------------------定义中断的类型----------------------------------------//-------------------------------定义INTA、INTB是否关联--------------------------------
#define INTA_INTB_CONJUNCTION   0x00        //AB关联
#define INTA_INTB_INDEPENDENT   0x01        //AB独立
//-------------------------------定义INTA、INTB是否关联--------------------------------//-------------------------------定义硬件地址是否使能----------------------------------
#define HWA_EN                  0x00        //A0、A1、A2、硬件地址使能
#define HWA_DIS                 0x01        //A0、A1、A2、硬件地址禁用
//-------------------------------定义硬件地址是否使能----------------------------------//-------------------------------定义INTA、INTB引脚的输出类型--------------------------
#define INT_OD                  0x00
#define INT_PUSHPULL_HIGH       0x01
#define INT_PUSHPULL_LOW        0x02
//-------------------------------定义INTA、INTB引脚的输出类型--------------------------#define I2C_READ      0x01      // 读指令代码
#define I2C_WRITE     0x00      // 写指令代码
#define DRIVER_ID     0x40      // 地址//----------------------------------函数原型------------------------------------------//初始化指定地址的MCP23017器件
int MCP23017_INIT(hi_u8 deviceAddr,hi_u8 intab,hi_u8 hwa,hi_u8 o);
//设置制定地址的MCP23017的指定端口的指定引脚为输入或输出状态
int MCP23017_IO_DIR(hi_u8 deviceAddr,hi_u8 port,hi_u8 pin,hi_u8 dir);
//设置指定地址的MCP23017的指定端口的指定引脚是否开启上拉电阻
int MCP23017_IO_PU(hi_u8 deviceAddr,hi_u8 port,hi_u8 pin,hi_u8 pu);
//设置指定地址的MCP23017的指定端口的指定引脚是否对端口极性取反
int MCP23017_IO_POLARITY(hi_u8 deviceAddr,hi_u8 port,hi_u8 pin,hi_u8 polarity);
//设置指定地址的MCP23017的指定端口的指定引脚是否开启中断功能及中断的类型
int MCP23017_IO_INT(hi_u8 deviceAddr,hi_u8 port,hi_u8 pin,hi_u8 intKind);
//读取指定地址的MCP23017的指定端口的中断标志寄存器
hi_u8 MCP23017_READ_INTF(hi_u8 deviceAddr,hi_u8 port);
//读取指定地址的MCP23017的指定端口发生中断时中断捕捉寄存器捕捉到的端口值
hi_u8 MCP23017_READ_INTCAP(hi_u8 deviceAddr,hi_u8 port);
//读取指定地址的MCP23017的指定端口值
hi_u8 MCP23017_READ_GPIO(hi_u8 deviceAddr,hi_u8 port);
//向指定地址的MCP23017的指定端口写值
int MCP23017_WRITE_GPIO(hi_u8 deviceAddr,hi_u8 port,hi_u8 val);
//设置指定地址的MCP23017的指定端口的指定引脚
int MCP23017_SET_GPIO_PIN(hi_u8 deviceAddr,hi_u8 port,hi_u8 pin,hi_u8 s);
//读取指定地址的MCP23017的指定端口的输出锁存寄存器
hi_u8 MCP23017_READ_OLAT(hi_u8 deviceAddr,hi_u8 port);
//写指定地址的MCP23017的指定端口的输出锁存寄存器
int MCP23017_WRITE_OLAT(hi_u8 deviceAddr,hi_u8 port,hi_u8 val);
//从指定地址的MCP23017器件的指定寄存器读一字节数据
int I2C_Read_Byte_MCP23017(hi_u8 deviceAddr, hi_u8 regAddress, hi_u8* recv);
//向指定地址的MCP23017器件的指定寄存器写一字节数据
int I2C_Write_Byte_MCP23017(hi_u8 deviceAddr, hi_u8 regAddress, hi_u8 content);//----------------------------------函数原型------------------------------------------#endif

MCP23017.c

#include "MCP23017.h"
#include <stdio.h>
#include "cmsis_os2.h"
#include "wifiiot_i2c.h"
#include "wifiiot_gpio.h"
#include "wifiiot_gpio_ex.h"
#include <hi_stdlib.h>#define MCP23017_I2C_IDX WIFI_IOT_I2C_IDX_0
#define MCP23017_I2C_ADDRESS 0x40//--------------------------------------------------------------------------------------
//  函数名称:bit MCP23017_INIT(unsigned char deviceAddr,unsigned char ab,unsigned char hwa,unsigned char o)
//  函数功能:初始化指定地址的MCP23017器件
//  参数:deviceAddr——设备地址,有A0,A1,A2决定
//        intab——配置INTA、INTB是否关联,取值INTA_INTB_CONJUNCTION、INTA_INTB_INDEPENDENT
//        hwa——配置A0、A1、A2硬件地址是否使能,取值HWA_EN、HWA_DIS
//        o——配置INTA、INTB的输出类型,取值INT_OD、INT_PUSHPULL_HIGH、INT_PUSHPULL_LOW
//--------------------------------------------------------------------------------------
int MCP23017_INIT(hi_u8 deviceAddr,hi_u8 intab,hi_u8 hwa,hi_u8 o){hi_u8 state = 0x2E;int res;if(intab==INTA_INTB_CONJUNCTION){state |= 0x40;}if(hwa==HWA_DIS){state &= (~0x08);}if(o==INT_PUSHPULL_HIGH){state &= (~0x04);state |= 0x02;}if(o==INT_PUSHPULL_LOW){state &= (~0x04);state &= (~0x02);}res = I2C_Write_Byte_MCP23017(deviceAddr,MCP23017_IOCON,state);return res;
}//--------------------------------------------------------------------------------------
//  函数名称:MCP23017_IO_DIR(unsigned char deviceAddr,unsigned char port,unsigned char pin,unsigned char dir)
//  函数功能:设置制定地址的MCP23017的指定端口的指定引脚为输入或输出状态
//  参数:deviceAddr——设备地址,有A0,A1,A2决定
//        port——端口名称,取值MCP23017_PORTA、MCP23017_PORTB
//        pin——引脚号,取值PIN0-PIN7对应端口的8个引脚,ALLPIN包括端口所有8个引脚
//        dir——输入输出方向,取值INPUT、OUTPUT
//--------------------------------------------------------------------------------------
int MCP23017_IO_DIR(hi_u8 deviceAddr,hi_u8 port,hi_u8 pin,hi_u8 dir){hi_u8 portState = 0;int res;res = I2C_Read_Byte_MCP23017(deviceAddr,MCP23017_IODIR+port,&portState);//如果出错则返回if(res == 0){return res;}if(dir==INPUT){portState |= pin;}else{portState &= (~pin);}//写回方向寄存器res = I2C_Write_Byte_MCP23017(deviceAddr,MCP23017_IODIR+port,portState);return res;
}//--------------------------------------------------------------------------------------
//  函数名称:bit MCP23017_IO_PU(unsigned char deviceAddr,unsigned char port,unsigned char pin,unsigned char pu)
//  函数功能:设置指定地址的MCP23017的指定端口的指定引脚是否开启上拉电阻
//  参数:deviceAddr——设备地址,有A0,A1,A2决定
//        port——端口名称,取值MCP23017_PORTA、MCP23017_PORTB
//        pin——引脚号,取值PIN0-PIN7对应端口的8个引脚,ALLPIN包括端口所有8个引脚
//        pull——输入输出方向,取值ENABLE、DISABLE
//--------------------------------------------------------------------------------------
int MCP23017_IO_PU(hi_u8 deviceAddr,hi_u8 port,hi_u8 pin,hi_u8 pu){hi_u8 portState = 0;int res;//首先读取当前端口方向的配置状态//因为B端口的地址比A端口的寄存器的地址都是大1,所以采用+的技巧切换寄存器res = I2C_Read_Byte_MCP23017(deviceAddr,MCP23017_GPPU+port,&portState);//如果出错则返回if(res == 0){return res;}if(pu==ENABLE){portState |= pin;}else{portState &= (~pin);}//写回方向寄存器res = I2C_Write_Byte_MCP23017(deviceAddr,MCP23017_GPPU+port,portState);return res;
}//--------------------------------------------------------------------------------------
//  函数名称:bit MCP23017_IO_POLARITY(unsigned char deviceAddr,unsigned char port,unsigned char pin,unsigned char polarity)
//  函数功能:设置指定地址的MCP23017的指定端口的指定引脚是否对端口极性取反
//            当设置为取反时,读取的端口状态与实际输入状态极性相反
//  参数:deviceAddr——设备地址,有A0,A1,A2决定
//        port——端口名称,取值MCP23017_PORTA、MCP23017_PORTB
//        pin——引脚号,取值PIN0-PIN7对应端口的8个引脚,ALLPIN包括端口所有8个引脚
//        polarity——是否取反,取值POLARITY_REVERSE、POLARITY_NON_REVERSE
//--------------------------------------------------------------------------------------
int MCP23017_IO_POLARITY(hi_u8 deviceAddr,hi_u8 port,hi_u8 pin,hi_u8 polarity){hi_u8 portState = 0;int res;//首先读取当前端口极性的配置状态//因为B端口的地址比A端口的寄存器的地址都是大1,所以采用+的技巧切换寄存器res = I2C_Read_Byte_MCP23017(deviceAddr,MCP23017_IPOL+port,&portState);//如果出错则返回if(res == 0){return res;}if(polarity==POLARITY_REVERSE){portState |= pin;}else{portState &= (~pin);}//写回方向寄存器res = I2C_Write_Byte_MCP23017(deviceAddr,MCP23017_IPOL+port,portState);return res;
}//--------------------------------------------------------------------------------------
//  函数名称:bit MCP23017_IO_INT(unsigned char deviceAddr,unsigned char port,unsigned char pin,unsigned char Interupt)
//  函数功能:设置指定地址的MCP23017的指定端口的指定引脚是否开启中断功能及中断的类型
//            可以设置位不开启中断、高电平中断、低电平中断、电平变化中断
//  参数:deviceAddr——设备地址,有A0,A1,A2决定
//        port——端口名称,取值MCP23017_PORTA、MCP23017_PORTB
//        pin——引脚号,取值PIN0-PIN7对应端口的8个引脚,ALLPIN包括端口所有8个引脚
//        intKind——中断的类型,取值DIS_INTERRUPT、HIGHLEVEL_INTERRUPT,LOWLEVEL_INTERRUPT,CHANGE_INTERRUPT
//--------------------------------------------------------------------------------------
int MCP23017_IO_INT(hi_u8 deviceAddr,hi_u8 port,hi_u8 pin,hi_u8 intKind){hi_u8 portState_GPINTEN = 0;    //中断使能寄存器hi_u8 portState_DEFVAL = 0;   //中断默认值寄存器hi_u8 portState_INTCON = 0;      //中断控制寄存器int res;//首先读取当前配置状态//因为B端口的地址比A端口的寄存器的地址都是大1,所以采用+的技巧切换寄存器res = I2C_Read_Byte_MCP23017(deviceAddr,MCP23017_GPINTEN+port,&portState_GPINTEN);//如果出错则返回if(res == 0){return res;}res = I2C_Read_Byte_MCP23017(deviceAddr,MCP23017_DEFVAL+port,&portState_DEFVAL);//如果出错则返回if(res == 0){return res;}res = I2C_Read_Byte_MCP23017(deviceAddr,MCP23017_INTCON+port,&portState_INTCON);//如果出错则返回if(res == 0){return res;}//判断中断的类型//如果是关闭中断if(intKind==DIS_INTERRUPT){portState_GPINTEN &= (~pin);      }//如果是变化中断if(intKind==CHANGE_INTERRUPT){portState_GPINTEN |= pin;portState_INTCON &= (~pin);        }//如果是高电平中断if(intKind==HIGHLEVEL_INTERRUPT){portState_GPINTEN |= pin;portState_INTCON |= pin;portState_DEFVAL &= (~pin);       }//如果是高电平中断if(intKind==LOWLEVEL_INTERRUPT){portState_GPINTEN |= pin;portState_INTCON |= pin;portState_DEFVAL |=pin;        }//写回寄存器res = I2C_Write_Byte_MCP23017(deviceAddr,MCP23017_GPINTEN+port,portState_GPINTEN);//如果出错则返回if(res == 0){return res;}res = I2C_Write_Byte_MCP23017(deviceAddr,MCP23017_INTCON+port,portState_INTCON);//如果出错则返回if(res == 0){return res;}res = I2C_Write_Byte_MCP23017(deviceAddr,MCP23017_DEFVAL+port,portState_DEFVAL);//如果出错则返回if(res == 0){return res;}return res;
}//--------------------------------------------------------------------------------------
//  函数名称:unsigned char MCP23017_READ_INTF(unsigned char deviceAddr,unsigned char port)
//  函数功能:读取指定地址的MCP23017的指定端口的中断标志寄存器
//  参数:deviceAddr——设备地址,有A0,A1,A2决定
//        port——端口名称,取值MCP23017_PORTA、MCP23017_PORTB
//  返回值:值中为1的位表示产生中断
//--------------------------------------------------------------------------------------
hi_u8 MCP23017_READ_INTF(hi_u8 deviceAddr,hi_u8 port){hi_u8 portState = 0;int res;//首先读取当前端口状态//因为B端口的地址比A端口的寄存器的地址都是大1,所以采用+的技巧切换寄存器res = I2C_Read_Byte_MCP23017(deviceAddr,MCP23017_INTF+port,&portState);//如果出错则返回0if(res == 0){return 0;}else{return portState;}
}//--------------------------------------------------------------------------------------
//  函数名称:unsigned char MCP23017_READ_INTCAP(unsigned char deviceAddr,unsigned char port)
//  函数功能:读取指定地址的MCP23017的指定端口发生中断时中断捕捉寄存器捕捉到的端口值
//  参数:deviceAddr——设备地址,有A0,A1,A2决定
//        port——端口名称,取值MCP23017_PORTA、MCP23017_PORTB
//  返回值:中断发生时,当时端口的值
//--------------------------------------------------------------------------------------
hi_u8 MCP23017_READ_INTCAP(hi_u8 deviceAddr,hi_u8 port){hi_u8 portState = 0;int res;//首先读取当前端口状态//因为B端口的地址比A端口的寄存器的地址都是大1,所以采用+的技巧切换寄存器res = I2C_Read_Byte_MCP23017(deviceAddr,MCP23017_INTCAP+port,&portState);//如果出错则返回0if(res == 0){return 0;}else{return portState;}
}//--------------------------------------------------------------------------------------
//  函数名称:unsigned char MCP23017_READ_GPIO(unsigned char deviceAddr,unsigned char port)
//  函数功能:读取指定地址的MCP23017的指定端口值
//  参数:deviceAddr——设备地址,有A0,A1,A2决定
//        port——端口名称,取值MCP23017_PORTA、MCP23017_PORTB
//  返回值:中断发生时,当时端口的值
//--------------------------------------------------------------------------------------
hi_u8 MCP23017_READ_GPIO(hi_u8 deviceAddr,hi_u8 port){hi_u8 portState = 0;int res;//首先读取当前端口状态//因为B端口的地址比A端口的寄存器的地址都是大1,所以采用+的技巧切换寄存器res = I2C_Read_Byte_MCP23017(deviceAddr,MCP23017_GPIO+port,&portState);//如果出错则返回0if(res == 0){return 0;}else{return portState;}
}//--------------------------------------------------------------------------------------
//  函数名称:bit MCP23017_WRITE_GPIO(unsigned char deviceAddr,unsigned char port,unsigned char val)
//  函数功能:向指定地址的MCP23017的指定端口写值
//  参数:deviceAddr——设备地址,有A0,A1,A2决定
//        port——端口名称,取值MCP23017_PORTA、MCP23017_PORTB
//        val——要写入端口寄存器的值
//--------------------------------------------------------------------------------------
int MCP23017_WRITE_GPIO(hi_u8 deviceAddr,hi_u8 port,hi_u8 val){int res;//因为B端口的地址比A端口的寄存器的地址都是大1,所以采用+的技巧切换寄存器res = I2C_Write_Byte_MCP23017(deviceAddr,MCP23017_GPIO+port,val);return res;
}//--------------------------------------------------------------------------------------
//  函数名称:bit MCP23017_SET_GPIO_PIN(unsigned char deviceAddr,unsigned char port,unsigned char pin,unsigned char s)
//  函数功能:设置指定地址的MCP23017的指定端口的指定引脚
//  参数:deviceAddr——设备地址,有A0,A1,A2决定
//        port——端口名称,取值MCP23017_PORTA、MCP23017_PORTB
//        pin——引脚号,取值PIN0~PIN7,ALLPIN包括端口所有8个引脚
//        s——取值SET、RESET
//--------------------------------------------------------------------------------------
int MCP23017_SET_GPIO_PIN(hi_u8 deviceAddr,hi_u8 port,hi_u8 pin,hi_u8 s){hi_u8 portState = 0;int res;//首先读取当前端口方向的配置状态//因为B端口的地址比A端口的寄存器的地址都是大1,所以采用+的技巧切换寄存器res = I2C_Read_Byte_MCP23017(deviceAddr,MCP23017_GPIO+port,&portState);//如果出错则返回if(res == 0){return res;}if(s ==SET){portState |= pin;}else{portState &= (~pin);}//写回方向寄存器res = I2C_Write_Byte_MCP23017(deviceAddr,MCP23017_GPIO+port,portState);return res;
}//--------------------------------------------------------------------------------------
//  函数名称:unsigned char MCP23017_READ_OLAT(unsigned char deviceAddr,unsigned char port)
//  函数功能:读取指定地址的MCP23017的指定端口的输出锁存寄存器
//  参数:deviceAddr——设备地址,有A0,A1,A2决定
//        port——端口名称,取值MCP23017_PORTA、MCP23017_PORTB
//  返回值:输出锁存寄存器值,而不是端口值
//--------------------------------------------------------------------------------------
hi_u8 MCP23017_READ_OLAT(hi_u8 deviceAddr,hi_u8 port){hi_u8 portState = 0;int res;//首先读取当前端口状态//因为B端口的地址比A端口的寄存器的地址都是大1,所以采用+的技巧切换寄存器res = I2C_Read_Byte_MCP23017(deviceAddr,MCP23017_OLAT+port,&portState);//如果出错则返回0if(res == 0){return 0;}else{return portState;}
}//--------------------------------------------------------------------------------------
//  函数名称:bit MCP23017_WRITE_OLAT(unsigned char deviceAddr,unsigned char port,unsigned char val)
//  函数功能:写指定地址的MCP23017的指定端口的输出锁存寄存器
//  参数:deviceAddr——设备地址,有A0,A1,A2决定
//        port——端口名称,取值MCP23017_PORTA、MCP23017_PORTB
//        val——要写入端口寄存器的值
//--------------------------------------------------------------------------------------
int MCP23017_WRITE_OLAT(hi_u8 deviceAddr,hi_u8 port,hi_u8 val){int res;//因为B端口的地址比A端口的寄存器的地址都是大1,所以采用+的技巧切换寄存器res = I2C_Write_Byte_MCP23017(deviceAddr,MCP23017_OLAT+port,val);return res;
}//--------------------------------------------------------------------------------------
//  函数名称:bit I2C_Read_Byte_MCP23017(unsigned char deviceAddr, unsigned char regAddress, unsigned char* recv)
//  函数功能:从设备读一个字节的数据
//  说明:deviceAddr——设备地址,regAddress——读出地址,recv——接收读取的内容
//--------------------------------------------------------------------------------------
int I2C_Read_Byte_MCP23017(hi_u8 deviceAddr, hi_u8 regAddress, hi_u8* recv){uint8_t writeBuf[1] = {0};WifiIotI2cIdx id = MCP23017_I2C_IDX;WifiIotI2cData i2cData = {0};writeBuf[0] = regAddress;i2cData.sendBuf = writeBuf;i2cData.sendLen = 1;I2cWrite(id, (DRIVER_ID | (deviceAddr<<1) | I2C_WRITE), &i2cData);uint8_t readBuf[1] = {0};WifiIotI2cData i2cRData = {0};i2cRData.receiveBuf = readBuf;i2cRData.receiveLen = 1;uint32_t Rresult = I2cRead(id, (DRIVER_ID | (deviceAddr<<1) | I2C_READ),&i2cRData);printf("[MCP23017 READ]%d \r\n",Rresult);*recv = readBuf[0];if(Rresult == 0){Rresult = 1;}return Rresult;
}//--------------------------------------------------------------------------------------
//  函数名称:bit I2C_Write_Byte_MCP23017(unsigned char deviceAddr, unsigned char regAddress, unsigned char content)
//  函数功能:向设备写一个字节的数据
//  说明:deviceAddr——设备地址,regAddress——寄存器地址,content——写入的内容
//--------------------------------------------------------------------------------------
int I2C_Write_Byte_MCP23017(hi_u8 deviceAddr, hi_u8 regAddress, hi_u8 content){uint8_t write_data[3] = {regAddress,content};WifiIotI2cIdx id = MCP23017_I2C_IDX;WifiIotI2cData i2cData = {0};i2cData.sendBuf = write_data;i2cData.sendLen = 2;uint32_t result = I2cWrite(id, (DRIVER_ID | (deviceAddr<<1) | I2C_WRITE), &i2cData);printf("[MCP23017 WRITE]%d \r\n",result);if(result == 0){result = 1;}return result;
}

4,测试

MCP23017Test.c

#include "MCP23017.h"
#include "MCP23017Test.h"
#include <stdio.h>
#include "cmsis_os2.h"
#include "wifiiot_i2c.h"
#include "wifiiot_gpio.h"
#include "wifiiot_gpio_ex.h"
#include <hi_stdlib.h>unsigned char deviceAddr = 0x00;static void * MCP23017Task(const char *arg){(void)arg;//初始化MCP23017,INTA和INTB独立,使能硬件地址,INTA和INTB设置为开漏输出MCP23017_INIT(deviceAddr,INTA_INTB_INDEPENDENT,HWA_EN,INT_OD);//将PORTA和PORTB都设置为输出MCP23017_IO_DIR(deviceAddr,MCP23017_PORTA,ALLPIN,OUTPUT);MCP23017_IO_DIR(deviceAddr,MCP23017_PORTB,ALLPIN,OUTPUT);while(1){MCP23017_WRITE_GPIO(deviceAddr,MCP23017_PORTA,0x00);osDelay(1000);MCP23017_WRITE_GPIO(deviceAddr,MCP23017_PORTA,0xFF);osDelay(1000);}return NULL;
}void MCP23017TaskInit(void){osThreadAttr_t attr;attr.name = "MCP23017Task";attr.attr_bits = 0U;attr.cb_mem = NULL;attr.cb_size = 0U;attr.stack_mem = NULL;attr.stack_size = 10240;attr.priority = 26;osDelay(12);if (osThreadNew((osThreadFunc_t)MCP23017Task, NULL, &attr) == NULL) {printf("[MCP23017TaskDEMO] Falied to create Ssd1306TestTask!\n");}
}

MCP23017Test.h

#ifndef MCP23017TEST_H
#define MCP23017TEST_Hvoid MCP23017TaskInit(void);#endif

鸿蒙硬件HI3861-I2C-MCP23017相关推荐

  1. 鸿蒙硬件HI3861开发环境搭建-串口2测试

    鸿蒙硬件HI3861开发环境搭建-串口2测试 鸿蒙硬件HI3861开发环境搭建-串口2测试 - 哔哩哔哩 鸿蒙其他教程请看https://blog.csdn.net/qq_33259323/categ ...

  2. 鸿蒙硬件HI3861点灯

    鸿蒙硬件HI3861点灯 鸿蒙其他教程请看https://blog.csdn.net/qq_33259323/category_10520249.html 创建文件 BUILD.gn static_l ...

  3. 鸿蒙硬件HI3861开发环境搭建

    鸿蒙HI3861开发环境搭建 最新的环境搭建教程请看:https://blog.csdn.net/qq_33259323/article/details/117854579 鸿蒙其他教程请看https ...

  4. 鸿蒙硬件开发:Hi3861开发环境搭建及Windows下编译下载程序

    Windows开发环境准备 可参考官方文档Windows开发环境准备进行配置. 安装VS Code https://code.visualstudio.com/Download 安装Python ht ...

  5. 鸿蒙硬件HI3861-OLED扫雷版本1

    鸿蒙硬件HI3861-OLED扫雷版本 使用HI3861实现在OLED1602上面实现扫雷 效果请看:https://www.bilibili.com/video/BV1U54y1r78j/ 1.OL ...

  6. 鸿蒙OS Hi3861的芯片实际开发中遇到的问题

    鸿蒙OS Hi3861的芯片实际开发中遇到的问题 优点: 比较适合开发者快速开发,上面的硬件操作的函数封装很简单,非常适合初学者使用封装好的函数调用硬件管脚,比如I2c gpio spi sdio 都 ...

  7. 鸿蒙硬件HI3861-MQTT

    警告:MQTT移植不匹配,此文章作废,后续有鸿蒙高版本MQTT移植 鸿蒙硬件HI3861-MQTT 鸿蒙其他教程请看https://blog.csdn.net/qq_33259323/category ...

  8. 鸿蒙硬件HI3861-连接WIFI

    鸿蒙硬件HI3861-连接WIFI 鸿蒙其他教程请看https://blog.csdn.net/qq_33259323/category_10520249.html 目录是这样的 BUILD.gn s ...

  9. 鸿蒙硬件HI3861-INA226-电压测量(外挂方案)

    鸿蒙硬件HI3861-INA226-电压测量(外挂方案) ina226.c #include "ina226.h" #include <stdio.h> #includ ...

最新文章

  1. pytorch系列 -- 9 pytorch nn.init 中实现的初始化函数 uniform, normal, const, Xavier, He initialization...
  2. 使用EHPC实现“完美并行”的高效批处理方案
  3. python 统计分析apache日志_python切分apache日志文件
  4. bleve搜索引擎源码分析之索引——mapping和lucene一样,也有_all
  5. Windows虚拟地址转物理地址(原理+源码实现,附简单小工具)
  6. ajax请求web服务返回json格式
  7. 互联网晚报 | 2月20日 星期日 | 天猫回应“改名转自营”;上汽奥迪正式进驻成都;谷爱凌在抖音开启直播首秀...
  8. 雷军:哈哈哈哈哈哈 网友:小米9要来了!
  9. 服务器开机信号,机柜服务器BMC开关机控制系统及方法
  10. 2022-2028全球与中国移动卫星通信市场现状及未来发展趋势
  11. Python如何对图片进行缩放,旋转,翻转,添加文字以及如何截取并粘贴图像到图片中
  12. 学术之声 | 专访北航教授洪晟:区块链应该管也能够管,而且要学会管
  13. 3dmax安装后破解Couldn't write to disk !
  14. ASP.NET WebForm 回传机制
  15. 【计算机组成原理】计算机系统结构笔记:合集
  16. Android的计量单位px,in,mm,pt,dp,dip,sp
  17. 取消超时订单及延迟处理方案
  18. python系列教程143——行缩进
  19. 本周白银价格走势仍关注美经济数据
  20. 四路抢答器c语言编程,基于单片机的四路抢答器设计

热门文章

  1. linux g++ undefined reference to `dlopen'类问题
  2. linux下overcommit_memory的问题
  3. openGL与openGL ES 的区别
  4. 2019 年编写现代 JavaScript 代码的5个小技巧
  5. haproxy安装配置及haproxy+keepalived简单配置
  6. 流行的9个Java框架介绍:优点、缺点等等
  7. Chrome用户想哭:因重大缺陷成黑客取款机
  8. 算法笔记_096:蓝桥杯练习 算法提高 求最大值(Java)
  9. PHP如何获取文件行数
  10. [LeetCode]:116:Populating Next Right Pointers in Each Node