Mikroprocesorski sistemi

RES_TAB SEGMENT AT 0FFFF0H
JMP FAR PTR START
RES_TAB ENDS
;
DAT SEGMENT AT 0 ; Tabela vektora prekida
IDIV0 DW 2 DUP(?)
ISS DW 2 DUP(?)
INMI DW 2 DUP(?)
IOST DW 2*253 DUP(?)
; Pocetak radnog prostora
ST_TOP EQU 04000h
;Na vrh RAM memorije
DAT ENDS
;
PROG SEGMENT AT 0FC000H
ASSUME CS:PROG,DS:DAT,ES:DAT,SS:DAT
RDIV0: IRET
RNMI: IRET
START: XOR AX,AX
MOV DS,AX ;RAM je na 0
MOV ES,AX
MOV SS,AX
MOV SP,ST_TOP
MOV AX,OFFSET RDIV0 ;Postavi vektor za DIV0
MOV IDIV0,AX
MOV AX,SEG RDIV0
MOV IDIV0+2,AX
MOV AX,OFFSET RNMI ;Postavi vektor za NMI
MOV INMI,AX
MOV AX,SEG RNMI
MOV INMI+2,AX
; Nastavak programa neobuhvacen prvim zadatkom
; Inicijalizacija periferija
call init59
call init54
call init51
mov ax,offset PORUKA
push ax
mov ax,seg PORUKA
push ax
STI ;Omogucavanje prekida
stani: jmp stani
PORUKA: db 'Pozdravna poruka',0
;
;
;Portovi za 8259A
P59ICW1 EQU 1010H
P59ICW EQU 1012H
;Upravljacke reci
ICW1 EQU 00010011b ;Ivicno, sam, ICW4
ICW2 EQU 20h ;Tipovi od 32 do 39
ICW4 EQU 00000001b ;8086 rezim
OCW1 EQU 11100111b ;IR3 i IR4 dozvoljeni
OCW2 EQU 00100000b ;ne specificni EOI
;
INIT59 PROC NEAR
MOV DX,P59ICW1
MOV AL,ICW1
OUT DX,AL
MOV DX,P59ICW
MOV AL,ICW2
OUT DX,AL
MOV AL,ICW4
OUT DX,AL
MOV AL,OCW1
OUT DX,AL
RET INIT59
ENDP PROG ENDS
;
DAT SEGMENT SAT
DW 2 DUP(?)
DAT ENDS
PROG SEGMENT
;Portovi za 8259A
P59ICW1 EQU 1010H
;Portovi za 8254
P54CTRL EQU 1026H
P54T0 EQU 1020H
P54T1 EQU 1022H
;Adresa vektora prekida
TVEK EQU (20H+3)*4 ;32+IR3
;
;Upravljacke reci za PCLK 2.5MHz
CRT0 EQU 00010111b ;T0,LSB,SQW,BCD
T0DIV EQU 16 ;2500000/(9600*16)
CRT1 EQU 01110001b ;T1,LSB,MSB,BIN
T1DIVLSB EQU A8h
T1DIVMSB EQU 61h
;
OCW2 EQU 00100000b ;ne specificni EOI
;
INIT54 PROC NEAR
ASSUME CS:PROG
; Inicijalizacija vektora prekida tajmera
XOR AX,AX
MOV DS,AX ;RAM je na 0
MOV AX,OFFSET TINT
MOV DS:TVEK,AX
MOV AX,SEG TINT
MOV DS:TVEK+2,AX
; Inicijalizacija tajmera
MOV DX,P54CTRL
MOV AL,CRT0
OUT DX,AL
MOV DX,P54T0
MOV AL,T0DIV
OUT DX,AL
MOV DX,P54CTRL
MOV AL,CRT1
OUT DX,AL
MOV DX,P54T1
MOV AL,T1DIVLSB
OUT DX,AL
MOV AL, T1DIVMSB
OUT DX, AL
RET
INIT54 ENDP
;
;Prekidna rutina tajmera 1
TINT PROC FAR
PUSH AX
PUSH DX
MOV AX,SAT
ADD AX,1
MOV SAT,AX
JNC T_1
INC SAT+2
T_1:
;Postavi tajmer
MOV DX,P54CTRL
MOV AL,CRT1
OUT DX,AL
MOV DX,P54T1
MOV AL,T1DIVLSB
OUT DX,AL
MOV AL, T1DIVMSB
OUT DX, AL
MOV AL,OCW2 ;EOI kontroleru
MOV DX,P59ICW1
OUT DX,AL
POP DX
POP AX
IRET TINT
ENDP PROG ENDS
;
DAT SEGMENT
POINTP DW ? ;pomeraj
POINTS DW ? ;i segment poruke
EOM DB ?
DAT ENDS
;
PROG SEGMENT
;Portovi za 8259A
P59ICW1 EQU 1010H
P59ICW EQU 1012H
;Portovi za 8251A
P51CTRL EQU 1031H
P51DAT EQU 1033H
;Adresa vektora prekida
SVEK EQU (20H+4)*4 ;32+IR4
;
;Upravljacke reci za asinc,9600,8b,np,*16,1stop
SMOD EQU 01001110b
SCOM EQU 00110111b
TxRDY EQU 00000001b
;Maska za predajnik spreman
RxRDY EQU 00000010b
;Msaka za podatak primljen
;
OCW2 EQU 00100000b ;ne specificni EOI
;
INIT51 PROC NEAR
ASSUME CS:PROG
; Inicijalizacija vektora prekida
XOR AX,AX
MOV DS,AX ;RAM je na 0
MOV AX,OFFSET SINT
MOV DS:SVEK,AX
MOV AX,SEG SINT
MOV DS:SVEK+2,AX
; Inicijalizacija 8251A
MOV DX,P51CTRL
MOV AL,0
OUT DX,AL
MOV CX,2
S_0: LOOP S_0
OUT DX,AL
MOV CX,2
S_1: LOOP S_1
OUT DX,AL
MOV CX,2
S_2: LOOP S_2
MOV AL,40H ;RESET
OUT DX,AL
MOV CX,2
S_3: LOOP S_3
MOV AL,SMOD
OUT DX,AL
MOV CX,2
S_4: LOOP S_4
MOV AL,SCOM
OUT DX,AL ; RET
INIT51 ENDP
;
;Prekidna rutina 8251A
SINT PROC FAR
PUSH AX
PUSH DX
PUSH BX
PUSH DS
MOV DX,P51CTRL
IN AL,DX
AND AL,TxRDY
JZ PRIJEM
MOV BX,POINTP
MOV AX,POINTS
MOV DS,AX
MOV AL,[BX] ;Bazni ili indeksni reg
OR AL,AL ;Test za kraj povorke
JZ KRAJ
INC POINTP
MOV DX,P51DAT
OUT DX,AL ;
KR1: MOV AL,OCW2 ;EOI kontroleru
MOV DX,P59ICW1
OUT DX,AL
POP DS
POP BX
POP DX
POP AX
IRET ;
KRAJ: INC EOM
MOV DX,P59ICW
IN AL,DX ;Ocitaj IMR
OR AL,10H ;IR4 zabrani
OUT DX,AL JMP KR1 ;
PRIJEM:
;Nije obuhvacen zadatkom
JMP KR1
SINT ENDP
;
SOUT PROC NEAR
;Startovanje procesa slanja poruke
;Pocetna adresa stavljena na stek pre poziva
;Poruka je u istom DS segmentu
;Cuva sve registre
PUSH BP
MOV BP,SP
PUSHF
PUSH AX
PUSH DX
MOV AX,[BP+4]
MOV POINTS,AX
MOV AX,[BP+6]
MOV POINTP,AX
XOR AL,AL
MOV EOM,AL ;
MOV DX,P59ICW
IN AL,DX ;Ocitaj IMR
AND AL,NOT 10H ;IR4 dozvoli
OUT DX,AL ;
POP DX
POP AX
POPF
POP BP
RET SOUT
ENDP PROG
ENDS END



Gore
Glavna