EasyManua.ls Logo

DFI BT253 - Digital I;O Sample Code and Processes

DFI BT253
62 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.df .com
58
Chapter 5 Digital I/O Progr amming 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
#def ne SLAVE_ADDR
#def ne INPUT_PORT
#def ne OUTPUT_PORT
#def ne INVERSION_PORT
#def ne COMFIG_PORT
GpioConf g(int PinNum, int Mode)
{
BYTE Data;
BYTE TempPinNum = PinNum%8;
//Pin0-7 Input/Output Conf 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
#def ne SLAVE_ADDR
#def ne INPUT_PORT
#def ne OUTPUT_PORT
#def ne INVERSION_PORT
#def 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
#def ne SLAVE_ADDR
#def ne INPUT_PORT
#def ne OUTPUT_PORT
#def ne INVERSION_PORT
#def 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