/* EXMP8255.c * * Example program for SBC1190 digital I/O * using the onboard 82C55. */ #include #include #define DIOBASE 0xFE40 #define PORTA DIOBASE+0 #define PORTB DIOBASE+1 #define PORTC DIOBASE+2 #define CTRL55 DIOBASE+3 /* The CTRL55 port determines the directions of Port A, B, and C in mode 0. The simple digital I/O makes mode 0 the most commonly used mode. The following table shows effect of various control byte outputs to CTRL55. Port A Port B Port C Port C Control Byte 7-4 3-0 (CTRL55) Out Out Out Out 0x80 Out Out Out In 0x81 Out Out In Out 0x88 Out Out In In 0x89 Out In Out Out 0x82 Out In Out In 0x83 Out In In Out 0x8A Out In In In 0x8B In Out Out Out 0x90 In Out Out In 0x91 In Out In Out 0x98 In Out In In 0x99 In In Out Out 0x92 In In Out In 0x93 In In In Out 0x9A In In In In 0x9B */ void main(void) { int data; printf("82C55 Digital I/O test\n"); outp(CTRL55,0x8A); /* initialize 82C55 */ /* Port A - output, Port B - input */ /* Port C bits 0-3 output */ /* Port C bits 4-7 input */ outp(PORTA, 0x55); /* output data to Port A */ data = inp(PORTB); /* read data from Port B */ printf("Port B reads %02X\n", data); outp(PORTC, 0x55); /* output data to Port C low nibble */ data = (inp(PORTC)& 0xFF)>>4; /* read data from Port C high nibble */ printf("Port C reads %X\n", data); }