Modern computer Interface Experiment (III.) 8255 experiment

Source: Internet
Author: User

1, A port work in mode 0 input mode, connect 8 switches, B port work in mode 0 output mode, connect8 LEDs, PC7 single pulse generator, input negative pulse, read a port, there is a table singleMeta, and at the same time at the B-port display, read 10 times end.

; 8255cs 288H~28BH
;P C7 Concave
;p b7~pb0-l7~l0
;p a7~pa0-k7~k0
;
;

DATA SEGMENT
PA EQU 288H
PB EQU 289H
PC EQU 28AH
CTL55 EQU 28BH
Ltable DB ten DUP (?)
DATA ENDS

STACK1 SEGMENT PARA STACK
DW 20H DUP (0)
STACK1 ENDS

Cseg SEGMENT
Assume Cs:cseg,ds:data

START:
MOV Ax,data
MOV Ds,ax
MOV cx,10
MOV si,0
MOV dx,ctl55
MOV al,10011000b
Out Dx,al

WAT:
MOV dx,pc; Read C-Port
In AL,DX
and al,80h; detection PC7
JNZ WAT

MOV Dx,pa; Pc7=0, read a mouth.
In AL,DX
MOV DX,PB; send b Port
Out Dx,al
MOV Ltable[si],al; Store the read switch value in the Memory Unit table
INC SI

WAT1:
MOV dx,pc; Read C-Port
In AL,DX
and al,80h; detection PC7
JZ WAT1
LOOP WAT
MOV ah,4ch
INT 21H
Cseg ENDS
END START

2, A port work in mode 0 input mode, connect 8 switches, B port work in mode 0 output mode, connect

8 LEDs, PC0 to generate a 1s pulse of 8253, 8253 input negative pulse, read a port, while at the B port display.

; 8255cs 288H~28BH

; 8253cs-280h~283h
; Clk0-2mhz;  clk1-out0; OUT1-PC0;
;p b7~pb0-l7~l0
;p a7~pa0-k7~k0
;
;

DATA SEGMENT
T0 EQU 280H; T0--ctl the address of the Counter 0--control register
T1 EQU 281H
T2 EQU 282H
CTL1 EQU 283H
PA EQU 288H
PB EQU 289H
PC EQU 28AH
CTL55 EQU 28BH
Ltable DB ten DUP (?)

DATA ENDS

STACK1 SEGMENT PARA STACK
DW 20H DUP (0)
STACK1 ENDS

Cseg SEGMENT
Assume Cs:cseg,ds:data

START:
MOV Ax,data
MOV Ds,ax

MOV dx,ctl55
MOV al,10010001b; PC on output PC under input
Out Dx,al
Call init_8253

WAT:

MOV dx,pc; Read C-Port
In AL,DX
and al,01h; detection PC0
JNZ WAT

MOV Dx,pa; Pc7=0, read a mouth.
In AL,DX
MOV DX,PB; send b Port
Out Dx,al

WAT1:
MOV dx,pc; Read C-Port
In AL,DX
and al,01h; detection PC0
JZ WAT1

JMP WAT
MOV ah,4ch
INT 21H; Initialize 8253
init_8253 PROC
PUSH DX
PUSH AX
/*8253 produces a 1s continuous square wave
MOV DX,CTL1
MOV al,00100101b; Select channel 0, write high byte, Mode 2, with BCD code
Out Dx,al
MOV dx,t0
MOV al,20h
Out Dx,al

MOV DX,CTL1
MOV al,01100111b; Select Channel 1, write high byte, mode 3, with BCD code
Out Dx,al
MOV DX,T1
MOV al,10h
Out Dx,al
; 8253 generate 1S of continuous square wave */

POP AX
POP DX
Ret
init_8253 ENDP
Cseg ENDS
END START

3, A port work in mode 0, input, connect 8 switches, B port work in mode 0, output, and then eight paragraphs

A 1S pulse is generated by 8253, PC7 the pulse, and a pulse will be read a, shown in

On the screen, at the same time; displayed on the eight-segment display, PC0,PC1 as a bit-code signal.

; 8253cs-280h~283h
; 8255CS288H~28BH
; 8255PA7PA0-K7-K0;PB6~B0-GFEDCBA
; Clk0-2mhz;  clk1-out0; OUT1-PC7; Pc0-s0; PC1-S1;
;

DATA SEGMENT
T0 EQU 280H; T0--ctl the address of the Counter 0--control register
T1 EQU 281H
T2 EQU 282H
CTL1 EQU 283H
PA EQU 288H
PB EQU 289H
PC EQU 28AH
CTL EQU 28BH
Ltable DB 3fh,06h,5bh,4fh,66h,6dh,7dh,07h
DB 7fh,6fh,77h,7ch,39h,5eh,79h,71h
; Storing the segment code of the 0~f
DAT DB 21H
DATA ENDS

CODE SEGMENT
Assume Cs:code,ds:data

; Main program
START:
MOV Ax,data
MOV Ds,ax

Call init_8253
Call init_8255
AGAIN:
Call READ_PA
Call Disp_dat
JMP AGAIN

MOV ah,4ch
INT 21H

; Digital Display Character program
Led_1 PROC
LEA si,ltable
ADD SI,BX
MOV Al,[si]
and al,7fh; the highest bit is set to 0 to not show the decimal point
MOV DX,PB
Out Dx,al
Ret
Led_1 ENDP

led_s PROC
PUSH CX
PUSH BX; save

MOV dx,pc; extinguish a bit code
MOV al,0h
Out dx,al; digital tube off

MOV bh,0
and BL,0FH; Show low four-bit ~8421~0-f
Call Led_1
MOV dx,pc; Select low four bit, i.e. PC0 1
MOV al,1h
Out Dx,al

MOV dx,pc; extinguish a bit code
MOV al,0h
Out dx,al; digital tube off

POP BX; Recall the saved number, alternate
PUSH BX; re-save

MOV bh,0
MOV cl,4
SHR BL,CL
and bl,0fh; show high four bits
Call Led_1
MOV dx,pc; Select high four bit, i.e. PC1 1
MOV al,02h
Out Dx,al

MOV dx,pc; extinguish a bit code
MOV al,0h
Out Dx,al

POP BX
POP CX
Ret
led_s ENDP

Read the A-port data.
Read_pa PROC
PUSH DX
PUSH AX

Loop_check:
MOV bh,0
MOV Bl,dat
Call led_s
MOV dx,pc; 8255 C Port Read-in
In AL,DX
TEST al,80h; judging 1s pulses
JNZ Loop_check
MOV DX, PA
In AL,DX
MOV Dat,al

POP AX
POP DX
Ret
Read_pa ENDP

Computer Terminal Display Character program
Disp_dat PROC
PUSH DX
PUSH AX
PUSH CX

MOV Al,dat
MOV cl,4
SHR AL,CL
and AL,0FH

CMP al,0ah; and 10 comparison
JC S1; BCD code correction; 〈10 Direct S1
ADD al,7h;>9 to +7 for rounding
S1:
Add al,30h, plus 0 ASCII code
MOV Dl,al; High four-bit display on the screen
MOV ah,02h
INT 21H

MOV Al,dat
and AL,0FH
CMP al,0ah
JC S2
ADD al,7h
S2:
ADD al,30h
MOV Dl,al; Low four-bit display on the screen
MOV ah,02h
INT 21H
MOV DL, "; Show spaces
MOV ah,02h
INT 21H

POP CX
POP AX
POP DX
Ret
Disp_dat ENDP

; Initialize 8253
init_8253 PROC
PUSH DX
PUSH AX
/*8253 produces a 1s continuous square wave
MOV DX,CTL1
MOV al,00100101b; Select channel 0, write high byte, Mode 2, with BCD code
Out Dx,al
MOV dx,t0
MOV al,20h
Out Dx,al
;
MOV DX,CTL1
MOV al,01100111b; Select Channel 1, write high byte, mode 3, with BCD code
Out Dx,al
MOV DX,T1
MOV al,10h
Out Dx,al
; 8253 generate 1S of continuous square wave */

POP AX
POP DX
Ret
init_8253 ENDP

; Initialize 8255
init_8255 PROC
PUSH DX
PUSH AX

MOV dx,ctl; 8255-way word control word control; 10011000
MOV al,98h
Out Dx,al

POP AX
POP DX
Ret
init_8255 ENDP

CODE ENDS
END START

4, A port work in mode 0 input mode, connect 4 switches, B port work in mode 0 output mode,

After a seven-segment display, the PC7 is connected to a single pulse generator, when the input negative pulse, read a port, while

Shown at b port, read 16 times.

; 8253cs-280h~283h
; 8255CS288H~28BH
; 8255PA3PA0-K3-K0;PB6~B0-GFEDCBA
; 8255pc7-concave, pc0-s1;
;

DATA SEGMENT
T0 EQU 280H; T0--ctl the address of the Counter 0--control register
T1 EQU 281H
T2 EQU 282H
CTL1 EQU 283H
PA EQU 288H
PB EQU 289H
PC EQU 28AH
CTL EQU 28BH
Ltable DB 3fh,06h,5bh,4fh,66h,6dh,7dh,07h
DB 7fh,6fh,77h,7ch,39h,5eh,79h,71h
; Storing the segment code of the 0~f
DAT DB 21H
DATA ENDS

CODE SEGMENT
Assume Cs:code,ds:data

; Main program
START:
MOV Ax,data
MOV Ds,ax

MOV cx,16
Call init_8255
AGAIN:
Call READ_PA
Call Disp_dat
LOOP AGAIN

MOV ah,4ch
INT 21H

; Digital Display Character program
Led_1 PROC
LEA si,ltable
ADD SI,BX
MOV Al,[si]
and al,7fh; the highest bit is set to 0 to not show the decimal point
MOV DX,PB
Out Dx,al
Ret
Led_1 ENDP

led_s PROC
PUSH CX
PUSH BX; save
MOV dx,pc; extinguish a bit code
MOV al,0h
Out dx,al; digital tube off

MOV bh,0
and BL,0FH; Show low four-bit ~8421~0-f
Call Led_1
MOV dx,pc; Select low four bit, i.e. PC0 1
MOV al,1h
Out Dx,al

MOV dx,pc; extinguish a bit code
MOV al,0h
Out dx,al; digital tube off

; POP BX; Recall the saved number, alternate
; PUSH BX; re-save


POP BX
POP CX
Ret
led_s ENDP

Read the A-port data.
Read_pa PROC
PUSH DX
PUSH AX
PUSH CX

Loop_check:
MOV bh,0
MOV Bl,dat
Call led_s
MOV dx,pc; 8255 C Port Read-in
In AL,DX
TEST al,80h; Judge PC7
JNZ Loop_check

MOV Dx,pa
In AL,DX
MOV Dat,al

Loop_c:
MOV bh,0
MOV Bl,dat
Call led_s
MOV dx,pc; 8255 C Port Read-in
In AL,DX
TEST al,80h; Judge PC7
JZ Loop_c


POP CX
POP AX
POP DX
Ret
Read_pa ENDP

Computer Terminal Display Character program
Disp_dat PROC
PUSH DX
PUSH AX
PUSH CX

MOV Al,dat
MOV cl,4
SHR AL,CL
and AL,0FH

CMP al,0ah; and 10 comparison
JC S1; BCD code correction; 〈10 Direct S1
ADD al,7h;>9 to +7 for rounding
S1:
Add al,30h, plus 0 ASCII code
MOV Dl,al; High four-bit display on the screen
MOV ah,02h
INT 21H

MOV AL,DAT;DFFGGFG
and AL,0FH
CMP al,0ah
JC S2
ADD al,7h
S2:
ADD al,30h
MOV Dl,al; Low four-bit display on the screen
MOV ah,02h
INT 21H
MOV DL, "; Show spaces
MOV ah,02h
INT 21H

POP CX
POP AX
POP DX
Ret
Disp_dat ENDP

; Initialize 8255
init_8255 PROC
PUSH DX
PUSH AX

MOV dx,ctl; 8255-way word control word control; 10011000
MOV al,98h
Out Dx,al

POP AX
POP DX
Ret
init_8255 ENDP

CODE ENDS
END START

Modern computer Interface Experiment (III.) 8255 experiment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.