29
void Dio3SetDirection(unsigned char);
unsigned char Dio3GetDirection(void);
//---------------------------------------------------------------------------
int main (void)
{
char SIO;
SIO = Init_W627DHG();
if (SIO == 0)
{
printf("Can not detect Winbond 83627DHG, program abort.\n");
return(1);
}
Dio2Initial();
Dio3Initial();
//for GPIO30..37
Dio3SetDirection(0x0F);
//GP30..33 = input, GP34..37=output
printf("Current DIO direction = 0x%X\n", Dio3GetDirection());
printf("Current DIO status = 0x%X\n", Dio3GetInput());
printf("Set DIO output to high\n");
Dio3SetOutput(0x0F);
printf("Set DIO output to low\n");
Dio3SetOutput(0x00);
return 0;
}
//---------------------------------------------------------------------------
void Dio2Initial(void)
{
unsigned char ucBuf;
//switch GPIO multi-function pin
ucBuf = Get_W627DHG_Reg(0x24);
ucBuf &= 0xFE;
Set_W627DHG_Reg(0x24, ucBuf);
Set_W627DHG_LD(0x09);
//switch to logic device 9
//enable the GP2 group
ucBuf = Get_W627DHG_Reg(0x30);
ucBuf |= 0x01;
Set_W627DHG_Reg(0x30, ucBuf);
}
//---------------------------------------------------------------------------
void Dio2SetOutput(unsigned char)
{
Set_W627DHG_LD(0x09);
//switch to logic device 9
Set_W627DHG_Reg(0xE4, NewData);
}
//---------------------------------------------------------------------------
unsigned char Dio2GetInput(void)
{
unsigned char result;
Set_W627DHG_LD(0x09);
//switch to logic device 9
result = Get_W627DHG_Reg(0xE4);
return (result);
}
//---------------------------------------------------------------------------
void Dio2SetDirection(unsigned char)
{
//NewData : 1 for input, 0 for output
Set_W627DHG_LD(0x09);
//switch to logic device 9
Set_W627DHG_Reg(0xE3, NewData);
}
//---------------------------------------------------------------------------
unsigned char Dio2GetDirection(void)
{
unsigned char result;
Set_W627DHG_LD(0x09);
//switch to logic device 9
result = Get_W627DHG_Reg(0xE0);
return (result);
}
//---------------------------------------------------------------------------
void Dio3Initial(void)
{
unsigned char ucBuf;