/* ********************************************************************** * File demo_ppi.C - Rel. 1.1 compile with uC/51 V. 1.10.10 * * GRIFO(R) via Dell'Artigiano 8/6 40016 S. Giorgio di Piano (BO) * * Cards: GPC 554 d.s. 100997 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 26.09.03 * ********************************************************************** Rel. 1.1 - 26.09.2003 by Graziano Gaiba Connect CN5 of GPC(r) 554 to CN15 of DEB01 or CN1 of TIO16 through a 20 pins+26 pins flat. This program allows to manage 16 TTL digital lines. */ #include #include #include // Clock frequency of CPU used #define FCLOCK 22118400 #define FALSE 0x00 // Boolean values #define TRUE 0xFF // On board peripherals registers allocation addresses. near unsigned char P4 @ 0xC0; /********* 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--) ; } // Set port A void setPortA(unsigned char v) { P4=v; } // Set port C void setPortC(unsigned char v) { P1=v; } // Get port A unsigned char getPortA(void) { return P4; } // Get port C unsigned char getPortC(void) { return P1; } void ritardo(unsigned int rit) /* Software delay of rit milliseconds, calibrated for 22.1184 MHz, according to the CPU installed. */ { unsigned int r; do { for (r=0 ; r<380 ; r++); rit--; } while (rit>0); } // **************************** Main program ***************************** void main(void) { unsigned char c; 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 setPortC(0xff); // PORT C in OUTPUT puts("*************************** Demo PPI ***************************"); puts(""); puts("This demo drives the shift activation of the lines of Port A and shows"); puts("continuously the value of Port C, available on CN5.\n"); for (;;) // Loop forever. { // Shift from red LEDs to yellow and green LEDs c=1; while(c) { setPortA(~c); c<<=1; // Delay to make the movement of the LED visible ritardo(1000); printf("%X\r", getPortC()); } c=0x80; while(c) { setPortA(~c); c>>=1; // Delay to make the movement of the LED visible ritardo(1000); printf("%X\r", getPortC()); } } }