Dfi HD620-H81 User Manual Page 76

  • Download
  • Add to my manuals
  • Print
  • Page
    / 86
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 75
www.d .com
76
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 0x42
#de ne INPUT_PORT 0x00
#de ne OUTPUT_PORT 0x01
#de ne INVERSION_PORT 0x02
#de ne COMFIG_PORT 0x03
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 0x42
#de ne INPUT_PORT 0x00
#de ne OUTPUT_PORT 0x01
#de ne INVERSION_PORT 0x02
#de ne COMFIG_PORT 0x03
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 0x42
#de ne INPUT_PORT 0x00
#de ne OUTPUT_PORT 0x01
#de ne INVERSION_PORT 0x02
#de ne COMFIG_PORT 0x03
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;
Page view 75
1 2 ... 71 72 73 74 75 76 77 78 79 80 81 ... 85 86

Comments to this Manuals

No comments