/* ********************************************************************** * File S1deb1.C - Rel. 1.1 compile with uC/51 V. 1.10.7 * * GRIFO(R) via Dell'Artigiano 8/6 40016 S. Giorgio di Piano (BO) * * Cards:GPC 324/D d.s.140201 + ETI 324 d.s.101297 and DEB01 or TIO16 * * Tel. +39 051 892052 Fax. +39 051 893661 * * http://www.grifo.com http://www.grifo.it * * sales@grifo.it tech@grifo.it grifo@grifo.it * * by Graziano Gaiba del 16.07.03 * ********************************************************************** Rel. 1.1 - 16.07.2003 by Graziano Gaiba Connect CN1 of GPC(r) 324/D and CN1 of ETI 324 through a flat 26+26 I/O. Connect CN3 of ETI 324 and CN15 of DEB01 or CN1 of TIO16 through a 20 pins flat. Also, all Dips of Dip Switch DSW1 of ETI 324 must be set ON, to select base address 0. For further information please refer to manual of ETI 324. This program shows the hexadecimal code of a key pressed on the PC's keyboard on the (red) LEDs of port A. */ #include #include #include // Clock frequency of CPU used #define FCLOCK 22118400 // On board peripherals registers allocation addresses. // Address of each register is given by: 0xFF00 + baseadd + offset of register // Value of baseadd is set through DSW1 of ETI 324, offsets of the registers // are reported on manual of ETI 324. static unsigned char PORTA @ 0xFF00, PORTB @ 0xFF01, PORTC @ 0xFF02, CNT @ 0xFF03; /********* General purpose utilities and hw sections management ***********/ void iniser(unsigned long baud) /* Initialise serial port with: Bit x chr = 8 Stop bit = 1 Parity = None Baud rate = baud using timer 1 as baud rate generator. */ { SCON=0x052; // Modo 1, receiver enabled TMOD&=0x00F; // Timer 1 in auto-reload mode TMOD|=0x020; TR1=0; // Stop TIMER 1 TH1=256-((2*FCLOCK)/(384*baud)); // baud at 14.7456 MHz PCON=PCON|0x080; // Set SMOD=1 for higher baud rate TR1=1; // Start TIMER 1 } // ************************ Procedure HexAdjust **************************** // This procedure accepts in input an unsigned char and checks that it is // an hexadecimal figure (number from 0 to 9 or letter from 'a' to 'f' or // from 'A' to 'F'. If check is postive, the value of hexadecimal figure is // returned (from 0 to 15) or 16 is returned. // Input parameters: // c, type unsigned char: character code to examine // Returns value of c as hexadecimal figure or 16. unsigned char HexAdjust(unsigned char c) { c-=48; // If c if a figure from '0' to '9', subtract 48 // (ASCII '0') to obtain its value if(c>15) // If c is still greater than 15, maybe it was a // character from 'A' to 'F' { c-=7; // After subtracting 48 and 7 ora, (ASCII 'A', // (65)+10)... if(c<10 || c>15) // ...maybe if was from 'a' to 'f' { c-=32; // Total value subtracted: ASCII of 'a' if(c<10 || c>15) // If still it is not between 0 and 15... { // ...then c was not an hexadecimal figure c=16; // Set to return 16 } } } return c; // Return value of c or 16 } // Wait for signals settling void setup(void) { unsigned int i; for(i=10000; i!=0; i--) ; } // Initialise 82c55 with value in parameter void init8255(unsigned char c) { CNT=c; } // Set port A of 82c55 void setPortA(unsigned char v) { PORTA=v; } // Set port B of 82c55 void setPortB(unsigned char v) { PORTB=v; } // Set port C of 82c55 void setPortC(unsigned char v) { PORTC=v; } // **************************** Main program ***************************** void main(void) { unsigned char tasto; setup(); // Wait for signals settling iniser(19200); TI=0; RI=0; // Comment next two lines if serial port is used in polling (SIOTYPE=p or k) ES=1; // Enable serial port interrupt EA=1; // Enable all interrupts // Initialisation of PPI 8255. init8255(0x80); // PORT A, B, C in OUTPUT. setPortA(0xff); // Clear PORT A. setPortC(0xff); // Clear PORT C. puts("\n********************* Demo S1DEB1 **********************"); puts(""); puts("Set all Dips of DSW1 on ETI 324 ON."); for (;;) // Loop forever { puts("\nPress a key corresponding to an hexadecimal figure."); putc(tasto = getc()); // Wait a key pressed and echo. tasto = HexAdjust(tasto); if(tasto<=15) // Hexadecimal figure? { setPortA(~tasto); // Show its code on PORT A. } else { puts("\nError !"); // Not an hexadecimal figure setPortA(0xff); // Clear PORT A. } } }