;实验三:
;*******************************;
;* 8255方式0的C口输入,A口输出 *;
;*******************************;
io8255a equ 288h
io8255c equ 28ah
io8255 equ 28bhcode segmentassume cs:code
start: mov dx, 28bH ;设8255为C口输入,A口输出;控制端口地址mov al,8bhout dx,al
inout: mov dx, io8255c ;从C口输入一数据in al,dxmov dx,io8255a ;从A口输出刚才自C口out dx,al ;所输入的数据mov dl,0ffh ;判断是否有按键mov ah,06hint 21hjz inout ;若无,则继续自C口输入,A口输出mov ax,4c00h ;否则返回int 21h
code endsend start
;实验九:
DATA SEGMENT
IO8254_0 EQU 280H
IO8254_K EQU 283H
DATA ENDS
CODE SEGMENTASSUME CS:CODE,DS:DATA
START: MOV AX,DATAMOV DS,AXMOV AL, 14H ;设置8254通道0为工作方式2,二进制计数MOV DX, IO8254_K OUT DX,ALMOV DX,IO8254_0 ;送计数初值为0FHMOV AL, 0FHOUT DX,AL
LLL: IN AL,DX ;读计数初值CALL DISP ;调显示子程序PUSH DX MOV AH,06H MOV DL,0FFHINT 21HPOP DXJZ LLLMOV AX,4C00H ;退出INT 21H
DISP PROC NEAR ;显示子程序PUSH DXAND AL,0fh ;首先取低四位MOV DL,ALCMP DL, 9 ;判断是否<=9JLE NUM ;若是则为'0'-'9',ASCII码加30HADD DL,7 ;否则为'A'-'F',ASCII码加37H
NUM: ADD DL,30HMOV AH,02H ;显示INT 21HMOV DL,0dh ;加回车符INT 21HMOV DL,0ah ;加换行符INT 21HPOP DXRET ;子程序返回
DISP ENDP
CODE ENDSEND START
;************************;
;*8251串行通讯(自发自收)*;
;************************;
data segmentio8253a equ 280hio8253b equ 283hio8251a equ 2b8hio8251b equ 2b9hmes1 db 'you can press a key on the keybord!',0dh,0ah,24hmes2 dd mes1
data ends
code segmentassume cs:code,ds:data
start: mov ax,datamov ds,axmov dx,283h ;设置8253计数器0工作方式mov al,16hout dx,almov dx,280h ;给8253计数器0送初值mov al,52out dx,almov dx,2b9h ;初始化8251xor al,almov cx,03 ;向8251控制端口送3个0delay: call out1loop delaymov al,40h ;向8251控制端口送40H,使其复位call out1mov al,4eh ;设置为1个停止位,8个数据位,波特率因子为16call out1mov al,27h ;向8251送控制字允许其发送和接收call out1lds dx,mes2 ;显示提示信mov ah,09int 21h
waiti: mov dx,2b9hin al,dxtest al,01 ;发送是否准备好jz waitimov ah,01 ;是,从键盘上读一字符int 21hcmp al,27 ;若为ESC,结束jz exitmov dx,io8251ainc alout dx,al ;发送mov cx,40h
s51: loop s51 ;延时
next: mov dx,io8251bin al,dxtest al,02 ;检查接收是否准备好jz next ;没有,等待mov dx,io8251ain al,dx ;准备好,接收mov dl,almov ah,02 ;将接收到的字符显示在屏幕上int 21hjmp waiti
exit: mov ah,4ch ;退出int 21h
out1 proc near ;向外发送一字节的子程序out dx,alpush cxmov cx,40h
gg: loop gg ;延时pop cxret
out1 endp
code ends
end start
;*******************************;
;* DMA传送实验(输入) *;
;*******************************;data segment
indata1 db 8 dup(30h),0dh,0ah,24h ;前面8个30h,然后是0dh 0ah 和24h
data ends
extra segment at 0d400h
indata2 db 11 dup(?) ;开辟11个字节的内存区
extra ends
code segment
assume cs:code,ds:data,es:extra
start:mov ax,datamov ds,axmov ax,extramov es,axlea si,indata1lea di,indata2cldmov cx,11rep movsbmov ax,extramov ds,axmov al,00out 1ch,al ;清字节指针mov al,49h ;写方式字out 1bh,almov al,0dh ;置地址页面寄存器out 83h,almov al,00out 12h,al ;写入基地址的低十六位mov al,40hout 12h,almov ax,7 ;写入传送的8个字节数out 13h,al ;先写低字节mov al,ahout 13h,al ;后写高字节mov al,01 ;清通道屏蔽out 1ah,al ;启动DMA
sss: lea dx,indata2
lll: mov ah,09int 21hmov ah,1int 16hje sss
exit: mov ah,4chint 21hcode endsend start
数字电子时钟
http://www.doczj.com/doc/063226991-5.html
http://www.doczj.com/doc/268944014-13.html
红绿灯
# 8086-by-protues 基于8255,8259,8253的8086简易红绿灯系统 仿真实现结果描述 1)A通道的绿色数码管和B通道的红色数码管从5开始显示数字,B通道的红灯和A通道的绿灯同时点亮5秒钟,数码管显示的数字每秒减一。 2)A通道的绿色数码管和B通道的红色数码管显示的数字变为0后,A通道的蓝色数码管和B通道的红色数码管从3开始显示数字,此时A通道的黄灯亮,B通道持续红灯,持续三秒,数码管显示的数字每秒减一。 3)A通道的黄色数码管和B通道的红色数码管显示的数字变为0后,A通道的红色数码管和B通道的绿色数码管从5开始显示数字,此时A通道的红灯亮, B通道变为绿灯,持续5S,每秒数码管显示的数字减一。 5)A通道的红色数码管和B通道的绿色数码管显示的数字变为0后,A通道的红色数码管和B通道的黄色数码管从3开始显示数字,此时A通道的红灯亮,B通道黄灯亮,持续三秒,数码管显示的数字每秒减一。 6)A通道的红色数码管和B通道的黄色数码管显示的数字变为0后,又转去执行1),重复执行。 7)当按下INT6按钮两次时,所有方向的信号灯都变为红色,所有方向的红色数码管从5开始显示数字,每秒减一。当显示的数字变为0后,红绿灯恢复中断前的状态,继续执行。 8)当按下开关时,能自动从紧急状态中退出,恢复到原来的信号灯状态继续运行。
CODE SEGMENT PUBLIC 'CODE'ASSUME CS:CODE,DS:DATA,SS:STACK
ORG 100H
START:; Write your code hereMOV AX,DATAMOV DS,AXMOV AX,STACKMOV SS,AXMOV AX,TOPMOV SP,AXCLI;中断向量PUSH DSMOV AX,0MOV DS,AXMOV BX,152MOV AX,OFFSET INT6MOV [BX],AXMOV AX,0MOV [BX+2],AXMOV BX,156MOV AX,OFFSET INT7MOV [BX],AXMOV AX,0MOV [BX+2],AXPOP DS;8259初始化MOV DX,CS8259AMOV AL,ICW1OUT DX,ALMOV DX,CS8259BMOV AL,ICW2OUT DX,ALMOV AL,ICW4OUT DX,ALMOV AL,OCW1OUT DX,ALSTI;8255—1MOV AL,80HMOV DX,CT_PORTOUT DX,AL;8255-2MOV AL,80HMOV DX,CT_PORT2OUT DX,AL;8255-3MOV AL,10000010BMOV DX,CT_PORT3OUT DX,AL;8253MOV AL,00110110B;CNT0MOV DX,CTLOUT DX,ALMOV AX,1000MOV DX,CNT0OUT DX,ALMOV AL,AHOUT DX,ALMOV AL,01110110B;CNT1MOV DX,CTLOUT DX,ALMOV AX,1000MOV DX,CNT1OUT DX,ALMOV AL,AHOUT DX,ALMOV AL,10010100B;CNT2MOV DX,CTLOUT DX,ALMOV AL,2MOV DX,CNT2OUT DX,ALMOV SI,1
ENDLESS:NOPSTI;MOV CX,6JMP ENDLESSINT6: ;中断服务PUSH AXPUSH BXPUSH CXPUSH DXSTIMOV DX,CTLMOV AL,01001100BOUT DX,AL;MOV DX,CT_PORT;MOV AL,10000000B;OUT DX,ALMOV DX,A_PORTMOV AL,00001001BOUT DX,ALMOV CX,6
NEXT6: MOV DX,B_PORT3IN AL,DXCMP AL,10000000BJBE EXLEA BX,BLOCK;清零MOV AL,[BX]MOV DX,B_PORTOUT DX,ALMOV DX,C_PORTOUT DX,ALMOV DX,B_PORT2OUT DX,ALMOV DX,A_PORT2OUT DX,AL;MOV AL,CLSUB AL,1XLATMOV DX,C_PORT2OUT DX,ALMOV DX,A_PORT3OUT DX,ALCALL DELAYLOOP NEXT6
EX:LEA BX,BLOCKMOV AL,[BX]MOV DX,C_PORT2OUT DX,ALMOV DX,A_PORT3OUT DX,ALMOV AL,20HMOV DX,CS8259AOUT DX,ALCLIPOP DXPOP CXPOP BXPOP AX;恢复红绿灯MOV AL,00110110B;CNT0MOV DX,CTLOUT DX,ALMOV AX,1000MOV DX,CNT0OUT DX,ALMOV AL,AHOUT DX,ALMOV AL,01110110B;CNT1MOV DX,CTLOUT DX,ALMOV AX,1000MOV DX,CNT1OUT DX,ALMOV AL,AHOUT DX,ALSTIIRETINT7: CLI;中断服务程序PUSH AXPUSH BXPUSH CXPUSH DXMOV CX,FLAGCMP CX,0JG A1MOV FLAG,20A1: ;A绿 B红DEC FLAGCMP CX,10JB B1SUB CX,10CMP CX,3JBE A2MOV AL,00001010BMOV DX,A_PORTOUT DX,ALMOV AL,CLSUB AL,4LEA BX,BLOCKXLATMOV DX,B_PORTOUT DX,ALMOV DX,C_PORT2OUT DX,ALJMP EXITA2: ;A黄 B红MOV AL,00001100BMOV DX,A_PORT OUT DX,AL MOV AL,CLLEA BX,BLOCKXLATMOV DX,C_PORTOUT DX,ALMOV DX,C_PORT2OUT DX,ALJMP EXITB1: ;A红 B绿CMP CX,3JBE B2MOV AL,00010001BMOV DX,A_PORT OUT DX,ALMOV AL,CLSUB AL,4LEA BX,BLOCKXLATMOV DX,A_PORT3OUT DX,ALMOV DX,A_PORT2OUT DX,ALJMP EXITB2: ;A红 B黄MOV AL,00100001BMOV DX,A_PORT OUT DX,AL MOV AL,CLLEA BX,BLOCKXLATMOV DX,A_PORT3OUT DX,ALMOV DX,B_PORT2OUT DX,ALEXIT: MOV DX,CS8259AMOV AL,20HOUT DX,ALCLIPOP DXPOP CXPOP BXPOP AXSTIIRETDELAY PROCPUSH CXMOV CX,0LOOP $LOOP $LOOP $MOV CX,15000LOOP $POP CXRET
DELAY ENDPCODE ENDS
DATA SEGMENT;8255-1A_PORT EQU 0A000H;Y2B_PORT EQU 0A002HC_PORT EQU 0A004HCT_PORT EQU 0A006H;8255-2A_PORT2 EQU 9000H;Y1B_PORT2 EQU 9002HC_PORT2 EQU 9004HCT_PORT2 EQU 9006H;8255-3A_PORT3 EQU 0C000H;Y4B_PORT3 EQU 0C002HC_PORT3 EQU 0C004HCT_PORT3 EQU 0C006H;8259CS8259A EQU 8000H;Y0CS8259B EQU 8002HICW1 EQU 00010011B ;边沿触发,单片,需要ICW4ICW2 EQU 00100000B ;中断向量地址20HICW4 EQU 00000001B ;非特殊全嵌套方式,非缓冲方式,非自动EOI,8086OCW1 EQU 00111111B ;允许6,7中断请求;8253CNT0 EQU 0B000H;Y3CNT1 EQU 0B002HCNT2 EQU 0B004HCTL EQU 0B006HFLAG DW 20TIME DW 5BLOCK DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,67H,77H,7CH,39H,5EH,79H,71H
DATA ENDS
STACK SEGMENTSTA DB 512 DUP(0FFH)TOP EQU $-STA
STACK ENDSEND START