/* ********************************************************************** * File demo_ppi.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 552 d.s. 180796 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 10.09.03 * ********************************************************************** Rel. 1.1 - 10.09.2003 by Graziano Gaiba Connect CN15 of DEB01 or CN1 of TIO16 through a 20 pins flat to CN2 (for output) or CN1 (for input) of GPC(r) 552. This program allows to manage all the 24 TTL digital lines of PPI 82c55, at the same time a sound indicates output setting. */ #include #include #include // Clock frequency of CPU used #define FCLOCK 22118400 #define FALSE 0x00 // Boolean values #define TRUE 0xFF near unsigned char CKCON @ 0x8E; // SFR of DALLAS // On board peripherals registers allocation addresses. static unsigned char PORTA @ 0xFFF8, PORTB @ 0xFFF9, PORTC @ 0xFFFA, CNT @ 0xFFFB, DSW1 @ 0xFFFD; static unsigned char BUZ @ 0xFFFC; // Variables used by the program near unsigned char dallas; /********* 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 } // 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; } // Get port A of 82c55 unsigned char getPortA(void) { return PORTA; } // Get port B of 82c55 unsigned char getPortB(void) { return PORTB; } // Get port C of 82c55 unsigned char getPortC(void) { return PORTC; } // Get value of DSW1 unsigned char getDSW1(void) { return DSW1; } void init_cpu(void) /* Checks which CPU is installed on the card and stores the information. */ { unsigned char dr; dr=CKCON; // Legge registro del DALLAS 80C320 if (CKCON==0x01) { CKCON=0x01; // Setta accesso area dati a 3 cicli macchina dallas=TRUE; // E` un DALLAS 80C320 } else dallas=FALSE; // E` un 80C32 //endif } void ritardo(unsigned int rit) /* Software delay of rit milliseconds, calibrated for 22.1184 MHz, according to the CPU installed. */ { unsigned int r,rit1ms; if (dallas==TRUE) rit1ms=380; // 1 msec. for 80c320 else rit1ms=150; // 1 msec. for 80c32 do { for (r=0 ; r0); } // Makes a short noise by on-board buzzer void bip(void) { BUZ |= 0x04; // Turn on buzzer. ritardo(300); BUZ &= ~0x04; // Turn off buzzer. } // Makes a short noise and performs about three seconds of total delay void ritardo_bip(void) { bip(); ritardo(700); } // **************************** Main program ***************************** void main(void) { unsigned char c; setup(); // Wait for signals settling init_cpu(); // Check CPU installed 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(0x82); // PORT A and C in OUTPUT, PORT B in INPUT. puts("*************************** Demo PPI ***************************"); puts(""); puts("This demo drives the shift activation of the lines of Port A and C available on"); puts("connector CN2 and shows continuously the value of Port B, available on CN1.\n"); for (;;) // Loop forever. { // Shift from red LEDs to yellow and green LEDs c=1; setPortC(0xff); // Clears Port C while(c) { setPortA(~c); c<<=1; // Delay to make the movement of the LED visible ritardo_bip(); printf("%X\r", getPortB()); } c=1; setPortA(0xff); // Clears Port A while(c) { setPortC(~c); c<<=1; // Delay to make the movement of the LED visible ritardo_bip(); printf("%X\r", getPortB()); } // Shift from yellow and green LEDs to red LEDs c=0x80; setPortA(0xff); // Clears Port A while(c) { setPortC(~c); c>>=1; // Delay to make the movement of the LED visible ritardo_bip(); printf("%X\r", getPortB()); } c=0x80; setPortC(0xff); // Clears Port A while(c) { setPortA(~c); c>>=1; // Delay to make the movement of the LED visible ritardo_bip(); printf("%X\r", getPortB()); } } }