/***************************************************************************** * This sample program will sequentially turn on all bits in port a and then* * seqencially turn them off. Each time it sets a new bit, both port a and * * port b are read and the data displayed. This demonstartaes how to read * * and write to a port, and to use the read back function of the 8255 chip. * * If the port a pins are jumpered to the port b pins, then a board test * * program results, with port b being used to verify what has been written * * to port a. The program will use port 0 of cards with mulitple 8255's. * *****************************************************************************/ #include #include #include unsigned int Address; /* assign Base Address to variable */ /* this typedef allow use to duplicate the boolean type as used in pascal */ typedef enum {FALSE,TRUE} boolean; unsigned AskForBaseAddress(unsigned int OldOne) { char msg[7]; int NewOne = 0, Success = 0, Dummy; int AddrInputPosX, AddrInputPosY; puts("\nPlease enter the Base Address for your card (in hex)"); printf("or press ENTER for %X.\n>", OldOne); AddrInputPosX = wherex(); AddrInputPosY = wherey(); do { gotoxy(AddrInputPosX, AddrInputPosY); clreol(); msg[0] = 5; msg[1] = 0; cgets(msg); sscanf(msg + 2, "%x", &NewOne); Success = 1; Dummy = NewOne; if (msg[1] == 0) { gotoxy(AddrInputPosX, AddrInputPosY); printf("%X", OldOne); Success = 1; Dummy = OldOne; } } while(!Success); return (Dummy); } /* end of AskForBaseAddress */ /***************************************************************************** * FUNCTION: signon -- local routine * * PURPOSE: To display an initial sign on message on the screen. * *****************************************************************************/ void signon() { #define L1 " I O D C A R D S A M P L E P R O G R A M " #define L2 "This sample program will sequentially turn on all bits in port a and then" #define L3 "seqencially turn them off. Each time it sets a new bit, both port a and" #define L4 "port b are read and the data displayed. This demonstrates how to read" #define L5 "and write to a port, and to use the read back function of the 8255 chip." #define L6 "If the port a pins are jumpered to the port b pins, then a board test" #define L7 "program results, with port b being used to verify what has been written" #define L8 "to port a. The program will use port 0 of cards with mulitple 8255's." #define L9 "Connect a loopback cable from PORT A to PORT B of PPI0. (required)" #define L10 " PORT A OUTPUT PORT A INPUT PORT B INPUT " #define L11 " ------------- ------------ ------------ " #define L12 " PRESS ANY KEY TO EXIT PROGRAM " #define L13 " PRESS ANY KEY TO CONTINUE" int index; /* print the string display and ask for the base address */ clrscr(); gotoxy(1,1); printf("%s\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n\n",L1,L2,L3,L4,L5,L6,L7,L8); Address=AskForBaseAddress(0x354); clrscr(); gotoxy(1,3); puts("Board Configuration:\n"); printf(" -- Base Address is %X hex\n",Address); printf(" -- %s\n",L9); puts(" -- Jumper IN5 should be installed. (required)"); puts(" -- Jumper IP should be installed. (required)"); puts(" -- All remaining jumper settings are irrelevant.\n\n\n"); printf("%s", L13); getch (); clrscr(); gotoxy(17,6); printf("%s",L10); gotoxy(17,7); printf("%s",L11); gotoxy(27,10); printf("%s",L12); } /* end signon */ /***************************************************************************** * FUNCTION: write_port_data -- local routine * * PURPOSE: Displays the current port values on the screen. * *****************************************************************************/ void write_port_data(unsigned char current[3]) { unsigned x,y,index1,index; unsigned char value; x = 20; /* x coordinate to write value to screen */ y = 8; for (index = 0;index <= 2;index++) /* for each array member */ { value = current[index]; for (index1 = 0;index1 <= 7;index1++) /* for each bit in array member */ { gotoxy(x,y); if (value % 2) putchar('1'); else putchar('0'); value = value >> 1; /* roll next diaplay bit */ x++; } x+= 10; } } /* end write_port_data */ /***************************************************************************** * FUNCTION: main -- external routine * *****************************************************************************/ void main() { unsigned char current[3]; boolean shift_left; signon(); /* print the start up message */ outportb(Address+3,0x8b); /* send the control byte */ current[0] = 0; shift_left = TRUE; while(!kbhit()) /* loop until key pressed */ { outportb(Address,current[0]); /* write value to port a */ delay(10); current[1] = inportb(Address); /* read back what we wrote to port A */ current[2] = inportb(Address+1); /* read the data on port B */ write_port_data(current); /* write new data to screen */ delay(700); /* compute value to turn on/off nesxt bit in line */ if (current[0] == 0) shift_left = TRUE; if (current[0] == 255) shift_left = FALSE; if (shift_left) current[0] = (current[0] << 1) + 1; else current[0] = (current[0] - 1) >> 1; }; clrscr(); } /* end main program */