;--------------------------------------------------------------------------- ; L353.ASM ; ; This program uses the MC146818 Real Time Clock built into the 80C206 ; peripheral to generate a periodic interrupt. LED-6 of port KEY_PC is ; toggled with each interrupt. The Real Time Clock interrupt is turned off ; after LED-6 is toggled 20-times. ; ; ASM code for the SBC188 boards. ; C.P. Diduch, March 1999. ;--------------------------------------------------------------------------- KEY_PC EQU 13CH ; Port Addresses for the 8255A. KEY_CON EQU 13EH ; ; ICW1_MAST EQU 0020H ; Addresses for the 82C206 MASTER 8259A. ICW2_MAST EQU 0021H ; IR0 of the MASTER 8259A is internally ICW3_MAST EQU 0021H ; connected to COUNTER 0 of an on-chip ICW4_MAST EQU 0021H ; 8254A. IR1 of the MASTER is connected OCW1_MAST EQU 0021H ; externally to serial channel 0 of the OCW2_MAST EQU 0020H ; of the 16C452. MAST_TYPE EQU 00F0H ; ; ICW1_SLAV EQU 00A0H ; Port Addresses for the 82C206 SLAVE ICW2_SLAV EQU 00A1H ; (8259A type) interrupt controller. ICW3_SLAV EQU 00A1H ; IR0 of the SLAVE is internally connected ICW4_SLAV EQU 00A1H ; to the output of an on-chip MC146818 type OCW1_SLAV EQU 00A1H ; real time clock. IR1 of the slave is OCW2_SLAV EQU 00A0H ; externally connected to serial channel 1 SLAV_TYPE EQU 00F8H ; of the 16C452. ; TIMER_CON EQU 0043H ; Addresses of the 82C206 Timer Control TIMER_0 EQU 0040H ; Register and COUNTER 0. ; RTC_INDEX EQU 0070H ; Addresses of the 82C206 Real Time Clock RTC_DATA EQU 0071H ; registers. ; I0CON EQU 0FF38H ; 80C188XL interrupt control register 0. EOI EQU 0FF22H ; 80C188XL EOI register. I0_TYPE EQU 12 ; 80C188XL INT0 TYPE NO. IT_TYPE EQU 18 ; 80C188XL Interrupt TYPE no. for TIMER1. TCUCON EQU 0FF32H ; 80C188XL Interrupt control port for TIMERS. ; T1CNT EQU 0FF58H ; 80C188 TIMER1 count register. T2CNT EQU 0FF60H ; 80C188 TIMER2 count register. T1CON EQU 0FF5EH ; 80C188 TIMER1 control register. T2CON EQU 0FF66H ; 80C188 TIMER2 control register. T1CMPA EQU 0FF5AH ; 80C188 TIMER1 maximum count register. T2CMPA EQU 0FF62H ; 80C188 TIMER2 maximum count register. ; TRUE EQU 1 ; ;--------------------------------------------------------------------------- _DATA segment word public 'DATA' assume cs:_TEXT, ds:_DATA ; Program variables and stack. KEY_PC EQU 13CH ; Port Addresses for the 8255A. ; DW 10 DUP(?) ; Reserve stack area TOS LABEL WORD ; Top of stack label N DW ? ; int N; ; _DATA ends ; ;--------------------------------------------------------------------------- _TEXT segment para public 'CODE' assume cs:_TEXT, ds:_DATA ; Program code mov dx, KEY_CON ; outportb(KEY_CON, 0x92); ; ENTRY: mov ax, _DATA ; Initialize segment registers mov ds, ax ; and so variables & stack are in mov ss, ax ; in segment _DATA, program code is mov sp, offset TOS ; in segment _TEXT. ; mov N, 0 ; N = 0; ; mov dx, KEY_CON ; outportb(KEY_CON, 0x92); mov al, 92H ; Initialize PC of 8255A as out dx, al ; a simple O/P port. ; cli ; Turn interrupts off. call INT_VECT_INIT ; Initialize interrupt vector table. sti ; call RTC_INIT ; Initialize real time clock. call INT_CON_INIT ; Initialize interrupt controllers. ; HERE: mov ax, 5000 ; call DELAY ; while(TRUE) { jmp HERE ; delay(5000); ; } and ax, 7FH ; Gracefully return to push ax ; the debug/monitor. xor bx, bx ; mov es, bx ; pushf ; push bx ; push bx ; jmp dword ptr es:[000CH] ;--------------------------------------------------------------------------- RTC_INT_HANDLER proc far push ax push dx mov dx, KEY_PC ; Toggle LED 6 of port KEY_PC. in al, dx ; xor al, 40H ; out dx, al ; ; mov dx, RTC_INDEX ; mov al, 0CH ; out dx, al ; mov dx, RTC_DATA ; in al, dx ; Clear RTC interrupt request. ; add N, 1 ; N++; cmp N, 20 ; if (N > 20) { jc T0 ; ; mov dx, OCW1_SLAV ; mov al, 0FFH ; outportb(OCW1_SLAV, 0xFF) out dx, al ; Mask off interrupts at slave ; mov dx, OCW1_MAST ; mov al, 0FFH ; outportb(OCW1_MAST, 0xFF) out dx, al ; Mask off interrupts at master ; mov dx, I0CON; ; outport(I0CON, 0x0038) mov ax, 0038H ; Mask off interrupts at INT0. out dx, ax ; ; } ; } T0: mov dx, OCW2_MAST ; mov al, 62H ; outportb(OCW2_MAST, 0x62) out dx, al ; Send specific EOI to MASTER for IR2. ; mov dx, OCW2_SLAV ; mov al, 60H ; outportb(OCW2_MAST, 0x60) out dx, al ; Send specific EOI to MASTER for IR0. ; mov dx, EOI ; mov al, 12 ; outport(EOI, 12) out dx, ax ; Send EOI to 80C188XL for INT0. ; pop dx ; pop ax ; iret ; RTC_INT_HANDLER endp ;--------------------------------------------------------------------------- INT_VECT_INIT proc near push ds push bx push ax mov ax, 0 mov ds, ax mov bx, 4*SLAV_TYPE mov word ptr [bx], offset RTC_INT_HANDLER mov word ptr [bx+2], seg RTC_INT_HANDLER pop ax pop bx pop ds ret INT_VECT_INIT endp ;--------------------------------------------------------------------------- RTC_INIT proc near ;{ ; ; mov dx, RTC_INDEX ; Division factor for 32.768 KHz clock. mov al, 0AH ; out dx, al ; ; mov dx, RTC_DATA ; Interrupt period = 500 ms. mov al, 2FH ; out dx, al ; ; mov dx, RTC_INDEX ; Turn periodic interrupt on. mov al, 0BH ; out dx, al ; ; mov dx, RTC_DATA ; mov al, 40H ; out dx, al ; ret ; } ;} RTC_INIT endp ;--------------------------------------------------------------------------- INT_CON_INIT proc near mov dx, ICW1_MAST ; Program master and slave 8259A mov al, 19H ; for level trigger and cascade out dx, al ; operation. ; mov dx, ICW1_SLAV ; mov al, 19H ; out dx, al ; ; mov dx, ICW2_MAST ; Program interrupt base type for mov al, MAST_TYPE ; the 8259A MASTER as 0xF0 - 0xF7. out dx, al ; ; mov dx, ICW2_SLAV ; Program interrupt base type for mov al, SLAV_TYPE ; the 8259A SLAVE as 0xF8 - 0xFF. out dx, al ; ; mov dx, ICW3_MAST ; Slave controller is connected to IR2. mov al, 04H ; out dx, al ; ; mov dx, ICW3_SLAV ; Slave controller is address. mov al, 02H ; out dx, al ; ; mov dx, ICW4_MAST ; Program MASTER for single and normal EOI. mov al, 01H ; out dx, al ; ; mov dx, ICW4_SLAV ; Program SLAVE for single and normal EOI. mov al, 01H ; out dx, al ; ; mov dx, OCW1_MAST ; Mask off all MASTER 8259A interrupts. mov al, 0FFH ; out dx, al ; ; mov dx, OCW1_SLAV ; Mask off all SLAVE 8259A interrupts. mov al, 0FFH ; out dx, al ; ; mov dx, I0CON ; Program 80C188 INT0 for high level trigger, mov ax, 0030H ; cascade mode, not special function nested mode, out dx, ax ; with priority 000, (highest). ; mov dx, OCW1_MAST ; Unmask IR2 in the MASTER 8259A. mov al, 0FBH ; out dx, al ; ; mov dx, OCW1_SLAV ; Unmask IR0 in the SLAVE 8259A. mov al, 0FEH ; out dx, al ; ret INT_CON_INIT endp ;--------------------------------------------------------------------------- DELAY proc near cmp ax, 0 jz D3 D0: mov bx, 375; D1: cmp bx, 0 jz D2 sub bx, 1; jmp D1 D2: sub ax, 1 jnz D0 D3: ret DELAY endp _TEXT ends ; end ENTRY ; ENTRY is the label of the first ; instruction of the program.