
INSTALLATIONS
26
MB770 User’s Manual
Digital I/O Sample Code
Filename
:
Main.cpp
//---------------------------------------------------------------------------
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//
//---------------------------------------------------------------------------
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include "W697HF.H"
//---------------------------------------------------------------------------
void ClrKbBuf(void);
int main (int argc, char *argv[]);
void SetDioInupt(unsigned char);
unsigned char GetDioOutpt(void);
//---------------------------------------------------------------------------
int main (int argc, char *argv[])
{
if (Init_W697HF() == 0)
{
printf("Can not detect Winbond 83697HF, program abort.\n");
return(1);
}
printf("Current DIO input is 0x%X\n|, GetDioOutpt());
printf("Set DIO output to high\n");
SetDioInupt(0x0F);
printf("Set DIO output to low\n");
SetDioInupt(0x00);
return
0;
}
//---------------------------------------------------------------------------
void SetDioInupt(unsigned char data)
{
Set_W697HF_LD(
0x07);
//switch to logic device 7
Set_W697HF_Reg(0xF1, ((data & 0x0F) << 4));
}
//---------------------------------------------------------------------------
unsigned char GetDioOutpt(void)
{
unsigned char result;
Set_W697HF_LD(
0x07);
//switch to logic device 7
result = Get_W697HF_Reg(0xF1, (data & 0x0F));
return
(result);
}
//---------------------------------------------------------------------------
void ClrKbBuf(void)
{
while(kbhit())
{
getch(); }
}
//---------------------------------------------------------------------------