beautypg.com

D. digital i/o sample code – IBASE MI802 User Manual

Page 57

background image

APPENDIX

MI802 User’s Manual

53

D. Digital I/O Sample Code

Files of the MAIN.CPP
//---------------------------------------------------------------------------
#include
#include
#include
#include
#include "F81866.H"
#define BIT0 0x01
#define BIT1 0x02
#define BIT2 0x04
#define BIT3 0x08
#define BIT4 0x10
#define BIT5 0x20
#define BIT6 0x40
#define BIT7 0x80
//---------------------------------------------------------------------------
int main (void);

void Dio3Initial(void);
void Dio3SetOutput(unsigned char);
unsigned char Dio3GetInput(void);
void Dio3SetDirection(unsigned char);
unsigned char Dio3GetDirection(void);
//---------------------------------------------------------------------------
int main (void)
{

char SIO;

unsigned char DIO;


printf("Fintek 81866 digital I/O test program. Ver 2.0\n");


SIO = Init_F81866();

if (SIO == 0)

{

printf("Can not detect Fintek 81866, program abort.\n");

return(1);

}//if (SIO == 0)


Dio3Initial();

/*

//for GPIO30..37

Dio3SetDirection(0xF0); //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);

*/

//for GPIO30..37

Dio3SetDirection(0xF0); //GP30..33 = input, GP34..37=output


Dio3SetOutput(0x00);

//clear

//

DIO = Dio3GetInput() & 0x0F;