//--------------------------------------------------------------- // L313.C // Using the 80C188XL Internal Timer. // // C Code for the SBC188 Board. // C.P. Diduch, Dec 1999. //--------------------------------------------------------------- #define KEY_PA 0x138 // 82C55A port addresses for PA, #define KEY_PB 0x13A // PB, #define KEY_PC 0x13C // PC and the #define KEY_CON 0x13E // Control Register. //--------------------------------------------------------------- // Details of the 80C188XL timer-counter unit can be found // on pages 9-1 though 9-23 of the Intel 80C186/80C188XL // Users Manual available in the lab and online at: // http://developer.intel.com/design/intarch/manuals/ #define T1CNT 0xFF58 // 80C188 TIMER1 count register. #define T2CNT 0xFF60 // 80C188 TIMER2 count register. #define T1CON 0xFF5E // 80C188 TIMER1 control register. #define T2CON 0xFF66 // 80C188 TIMER2 control register. #define T1CMPA 0xFF5A // 80C188 TIMER1 maximum count register. #define T2CMPA 0xFF62 // 80C188 TIMER2 maximum count register. #include // conio.h contains prototypes for // inportb() and outportb(). void TIMER_INIT(void); // Function declarations (prototypes). void PPI_INIT(void); //--------------------------------------------------------------- void main() { unsigned time; unsigned char C; PPI_INIT(); do { TIMER_INIT(); do { time = inport(T1CNT); } while (time <= 50000); C = C + 1; outportb(KEY_PC, C); } while (C < 255); } //--------------------------------------------------------------- void PPI_INIT(void) { outportb(KEY_CON, 0x82); // Initialize KEY_PC and KEY_PA } // as OP ports and KEY_PB as IP. //--------------------------------------------------------------- void TIMER_INIT(void) { outport(T2CNT, 0); // Clear timer count registers outport(T1CNT, 0); // before programming mode. outport(T2CMPA, 4); // Timer2 is clocked at 4 MHz / 4 // causing a time-out once every // microsecond. Each time-out on outport(T1CMPA, 0xFFFF); // timer2 triggers timer1. // T1CMPA is set to MAX. outport(T2CON, 0xC001); // Enable Timer2 for continuous mode. outport(T1CON, 0xC009); // Enable Timer1 for continous mode and // internally clocked by a time-out on } // Timer 2. //---------------------------------------------------------------