Pitx-sp software guide 6.2.2 digital i/o example – Kontron pITX-SP User Manual

Page 24

Advertising
background image

KTD-S0003-C

Page 20

CPLD Interface


p

ITX-SP Software Guide

6.2.2

Digital I/O Example

BIOS Setup settings (entry

Advanced/Onboard Device Configuration/GPIO Configuration):

GPIO Pin 0 - 3

Input

GPIO Pin 4 - 7

Output

Default

Output

State

Low

#include <stdio.h>
#include <dos.h>
#include <conio.h>

#define CPLD_BASE_ADDR

0xA80

#define GPIO_INPUT_INDEX

0xA0

#define GPIO_OUTPUT_INDEX

0xA1

#define GPIO_INPUT_MASK

0x0F


void WriteDigitalIO (unsigned char value)
{

outp (CPLD_BASE_ADDR, GPIO_OUTPUT_INDEX);

outp (CPLD_BASE_ADDR+1, value);

}

unsigned char ReadDigitalIO (void)
{
unsigned

char

value;

outp (CPLD_BASE_ADDR, GPIO_INPUT_INDEX);

value = inp (CPLD_BASE_ADDR+1);

return

value;

}

void main (void)
{
unsigned

char

val;

WriteDigitalIO

(0x50);

getch

();

WriteDigitalIO

(0xA0);

getch

();

val = ReadDigitalIO () & GPIO_INPUT_MASK;

printf ("\nInput value = %02X\n", val);

}

Advertising