EasyManua.ls Logo

DFI BT551 - Digital I;O Programming Examples; GPIO Configuration and Code Samples

DFI BT551
64 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
www.d .com
53
Chapter 5 Digital I/O Programming Guide
Chapter 5
Function Description
I2CWriteByte(SlaveAddr, SubAddr, Data):
Write a Byte data to a specified I2C Device.
I2CReadByte(SlaveAddr, SubAddr, *Data):
Read a Byte data from a specified I2C Device.
SetBit(*Data, Bit) :
Set Data bit n as “1”.
ClrBit(*Data, Bit) :
Set Data bit n as “0”.
GetBit(Data, Bit) :
Return the value of data bit n.
Sample Code
GPIO Configuration
#de ne SLAVE_ADDR
#de ne INPUT_PORT
#de ne OUTPUT_PORT
#de ne INVERSION_PORT
#de ne COMFIG_PORT
GpioCon g(int PinNum, int Mode)
{
BYTE Data;
BYTE TempPinNum = PinNum%8;
//Pin0-7 Input/Output Con guration
I2C_ReadByte(SLAVE_ADDR, CONFIG_PORT, &Data);
if(Mode == 1){SetBit(&Data, TempPinNum);} //Input
else {ClrBit(&Data, TempPinNum);} //Output
I2C_WriteByte(SLAVE_ADDR, CONFIG_PORT, Data);
return 1;
GPIO Output Process
#de ne SLAVE_ADDR
#de ne INPUT_PORT
#de ne OUTPUT_PORT
#de ne INVERSION_PORT
#de ne COMFIG_PORT
GpioOut(int PinNum, int Level)
{
BYTE Data;
BYTE TempPinNum = PinNum%8;
//Pin0-7
I2C_ReadByte(SLAVE_ADDR, OUTPUT_PORT, &Data);
if(Level == 0){ClrBit(&Data, TempPinNum);}
else {SetBit(&Data, TempPinNum);}
I2C_WriteByte(SLAVE_ADDR, OUTPUT_PORT, Data);
return 1;
GPIO Iutput Process
#de ne SLAVE_ADDR
#de ne INPUT_PORT
#de ne OUTPUT_PORT
#de ne INVERSION_PORT
#de ne COMFIG_PORT
GpioIn(int PinNum, int *Status)
{
BYTE Data;
BYTE Group = PinNum/8;
BYTE TempPinNum = PinNum%8;
//Pin0-7
I2C_ReadByte(SLAVE_ADDR, INPUT_PORT, &Data);
*Status = GetBit(Data, TempPinNum);
return 1;
0x42
0x00
0x01
0x02
0x03
0x42
0x00
0x01
0x02
0x03
0x42
0x00
0x01
0x02
0x03

Table of Contents

Related product manuals