西南交大 微机接口 实验代码
《西南交大 微机接口 实验代码》由会员分享,可在线阅读,更多相关《西南交大 微机接口 实验代码(10页珍藏版)》请在装配图网上搜索。
1、开关实验: io8255a equ 288h io8255c equ 28ah io8255z equ 28bh code segment assume cs:code start: mov dx,io8255z mov al,8bh out dx,al inout: mov dx,io8255c in al,dx mov dx,io8255a out dx,al mov dl,0ffh mov ah,06h int 21h jz inout mov ah,4ch int 21h code ends
2、 end start 交通灯控制实验: data segment io8255c equ 28Ah io8255z equ 28Bh portc1 db 21h db 81h,01h,81h,01h,81h,01h,81h,01h,81h,01h,81h,01h db 44h db 42h,40h,42h,40h,42h,40h,42h,40h,42h,40h,42h,40h db 0ffh data ends code segment assu
3、me cs:code,ds:data start: mov ax,data mov ds,ax mov dx,io8255z mov al,90h out dx,al mov dx,io8255c re_on: mov bx,0; on: mov al,portc1[bx] cmp al,0ffh jz re_on out dx,al inc bx mov cx,200 test al,24h jz de1 mov cx,10000 de
4、1: mov di,9000 de0: dec di jnz de0 loop de1 push dx mov ah,06h mov dl,0ffh int 21h pop dx jz on exit:mov ah,4ch int 21h code ends end start 七段数码管静态显示实验: io8255a equ 288h io8255z equ 28bh data segment led db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6f
5、h mesg1 db 0dh,0ah,’Input a num(0-9),other key is exit’,0dh,0ah,’$’ data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov dx,io8255z mov ax,80h out dx,al sss: mov dx,offset mesg1 mov ah,09h int 21h mov ah,01 int 21h cmp al,’0’ jl exit cmp
6、 al,’9’ jg exit sub al,30h mov bx,offset led xlat mov dx,io8255a out dx,al jmp sss exit: mov ah,4ch int 21h code ends end start 数码管循环显示00—99 data segment io8255a equ 288h io8255b equ 289h io8255c equ 28ah io8255z equ 28bh led db 3fh,06h,5bh,4fh,6
7、6h,6dh,7dh,07h,7fh,6fh buffer1 db 0,0 bz dw 01,00 data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov dx,io8255b ;将8255设为A口输出 mov al,80h out dx,al mov di,offset buffer1 ;设di为显示缓冲区 loop1: mov cx,0300h;循环次数 loop2: mov bh,02 lll: mov byte pt
8、r bz,bh push di dec di add di,bz mov bl,[di] ;bl为要显示的数 pop di mov bh,0 mov si,offset led;置led数码管偏移地址为SI add si,bx;求出对应的led码 mov al,byte ptr[si] mov dx,io8255c;自8255A的口输出 out dx,al mov al,byte ptr bz ;使相应的数码管亮 mov dx,io8255c out dx,al push cx mov cx,3000 ;若显示过快,可更改cx值
9、最大为0ffffh delay: loop delay ;延时 pop cx mov bh,byte ptr bz shr bh,1 jnz lll loop loop2 ;循环延时 mov ax,word ptr[di] mov ah,01 int 16h jne exit ;有键按下转exit mov ax,word ptr[di] inc al aaa mov [di],al;al中为十位 mov [di+1],ah;ah中为个位 jmp loop1 exit: mov dx,io8255a mov a
10、l,0;关掉数码管显示 out dx,al mov ah,4ch;返回DOS int 21h code ends end start 键盘接口实验(行扫描法) data segment io8255a equ 288h io8255c equ 28ah io8255z equ 28bh key db 37h,38h,39h,41h,54h,52h db 34h,35h,36h,42h,53h,4dh db 31h,32h,33h,43h,48h,4ch db 30h,46h,45h,44h,58h,4eh data ends
11、 code segment assume cs:code,ds:data start: mov ax,data mov ds,ax lp0: mov dx,io8255z mov al,90h out dx,al; mov di,0 mov si,0 lp1:mov al,00h mov dx,io8255c out dx,al mov dx,io8255a in al,dx and al,3fh cmp al,3fh jz l
12、p1 call DELAY mov ah,0feh mov cx,4 lp2:mov al,ah mov dx,io8255c out dx,al mov dx,io8255a in al,dx and al,3fh cmp al,3fh jnz aa; rol ah,1 loop lp2 jmp lp1 aa: push ax mov dx,io8255a in al,dx nop nop nop
13、 nop nop and al,3fh cmp al,3fh jnz aa pop ax l4: mov cx,6 lp4:shr al,1 jnc l3 inc si loop lp4 l3: mov cx,4 mov al,ah lp3:shr al,1 jnc lp5 inc di loop lp3 lp5:mov bx,di mov al,6 mul bl add ax,si disp: mov bx,offset key
14、 xlat mov dh,0 mov dl,al mov ah,2 int 21h jmp lp0 exit: mov ah,4ch int 21h DELAY PROC NEAR PUSH CX MOV CX,20h L1:loop L1 pop cx ret DELAY ENDP code ends end start BCA: mov al,ah mov dx,io8255c out dx,al;
15、输出行值 mov dx,io8255a in al,dx;读入列值 and al,00111111b;保留低4位有效值 cmp al,00111111b;判断A0行是否有键按下 mov bl,al;有键按下,确定该键的值 rol ah;本行无键按下则继续查找下一行,循环左移(使下一行输出0) loop BCA jmp ABC realy: mov dx,io8255c in al,dx nop nop nop and al,0fh cmp al,0fh jnz realy mov cx,4 mov al,bl lp1:
16、shr al,1 jnc lp2 inc di loop lp1 lp2: mov cx,6 mov al,ah lp20: shr al,1 jnc lp3 inc si loop lp20 lp3: mov bx,di mov al,6 mul bl add ax,si disp: mov bx,offset key xlat mov dh,0 mov dl,al mov ah,2 int 21h jmp lp0 exit: mov ah,4ch int 21h delay proc n
17、ear push cx mov cx,20h l1: loop l1 pop cx ret delay endp code ends end start data segment io8255a equ 288h io8255b equ 289h io8255c equ 28ah io8255z equ 28bh key db 37h,38h,39h,41h,54h,52h db 34h,35h,36h,42h,53h,4dh db 31h,32h,
18、33h,43h,48h,4ch db 30h,46h,45h,44h,58h,4eh led1 db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh led2 db 77h,7ch,39h,5eh,79h,71h data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax lp0: mov dx,io8255z mov al,90h out dx,al;c shu
19、 chu ,a shu ru lp1: mov di,0 mov si,0 mov al,00h mov dx,io8255c out dx,al mov dx,io8255a in al,dx and al,3fh cmp al,3fh jz lp1 call DELAY mov ah,0feh mov cx,4 lp2:mov al,ah mov dx,io8255c out dx,al mov dx,io8255a
20、 in al,dx and al,3fh cmp al,3fh jnz realy;you jian an xia rol ah,1 loop lp2 jmp lp1 realy: push ax mov dx,io8255a in al,dx nop nop nop nop nop and al,3fh cmp al,3fh jnz realy pop ax l4: mov cx,6 lp4:shr al,1 jnc l3 inc si loop lp4
21、l3: mov cx,4 mov al,ah lp3:shr al,1 jnc lp5 inc di loop lp3 lp5:mov bx,di mov al,6 mul bl add ax,si disp: mov bx,offset key xlat cmp ax,39h jl ll cmp ax,40h jg lll ll: sub ax,30h mov bx,offset led1 xlat mov dx,io8255b ou
22、t dx,ax jmp lp1 lll: sub ax,41h mov bx,offset led2 xlat mov dx,io8255b out dx,ax jmp lp1 exit: mov ah,4ch int 21h delay proc near push cx mov cx,20h l1: loop l1 pop cx ret delay endp code ends end start
23、 实验三 3.1 timer_ctl equ 283h timer0 equ 280h io8255z equ 28bh io8255c equ 28ah code segment assume cs:code start: mov dx,io8255z mov al,80h out dx,al mov al,00010000b mov dx,timer_ctl out dx,al mov dx,timer0
24、 mov al,9 out dx,al display: mov al,00000000b mov dx,timer_ctl out dx,al mov dx,timer0 in al,dx mov bl,al mov al,9 sub al,bl mov dx,io8255c out dx,al mov ah,06h mov dl,0ffh int 21h jz display mov ah,4c
25、h int 21h code ends end start 3.2 timer_ctl equ 283h timer0 equ 280h timer1 equ 281h mode03 equ 36h mode12 equ 76h code segment assume cs:code start: mov dx,timer_ctl mov al,mode03 out dx,al mov dx,timer0 mov ax,500 ou
26、t dx,al mov al,ah out dx,al mov dx,timer_ctl mov al,mode12 out dx,al mov dx,timer1 mov ax,500 out dx,al mov al,ah out dx,al mov ah,4ch int 21h code ends end start 3.3 timer0 equ 280h timer1 equ 281h timerctl equ 283h io8255a equ
27、 288h io8255z equ 28bh code segment assume cs:code start: mov dx,io8255z mov al,90h out dx,al ll1: mov al,0 out dx,al call delay mov al,1 out dx,al call delay jmp ll1 delay proc near push dx mov dx,timerctl mov al,36h ou
28、t dx,al mov dx,timer0 mov ax,1000 out dx,al mov al,ah out dx,al mov dx,timerctl mov al,70h out dx,al mov dx,timer1 mov ax,500 out dx,al mov al,ah out dx,al ll2: mov ah,06 mov dl,0ffh int 21h jne exit mov dx,
29、io8255a in al,dx and al,01 jz ll2 pop dx ret exit: mov ah,4ch int 21h delay endp code ends end start 3.4 data segment io8255a equ 288h io8255z equ 28bh timer0 equ 280h timerctl equ 283h table dw 524,588,660,784,880,988,1
30、048 ;高音的 ;table dw 262,294,330,347,392,440,524 ;低音的 msg db Press 1,2,3,4,5,6,7,8,ESC:,0dh,0ah,$ data ends code segment assume cs:code, ds:data start: mov ax,data mov ds,ax mov dx,offset msg mov ah,9 int 21h sing: mov ah,7 int 21h cmp al,
31、1bh je finish cmp al,1 jl sing cmp al,8 jg sing sub al,32h shl al,1 mov bl,al mov bh,0 mov ax,4240H mov dx,0FH div word ptr[table+bx] mov bx,ax mov dx,timerctl mov al,00110110B out dx,al mov dx,timer0 mo
32、v ax,bx out dx,al mov al,ah out dx,al mov dx,io8255z mov al,10000000B out dx,al mov dx,io8255a mov al,03h out dx,al call delay mov al,0h out dx,al jmp sing finish: mov ax,4c00h int 21h delay proc near push cx pus
33、h ax mov ax,15 x1: mov cx,0ffffh x2: dec cx jnz x2 dec ax jnz x1 pop ax pop cx ret delay endp code ends end start 3.5 data segment io8255a equ 288h io8255z equ 28bh timer0 equ 280h timerctl equ 283h ;table dw 524,588,660,698,784,880,998,10
34、48 table dw 262,294,330,347,392,440,494,524 ;music_dataxxx db 1,1,5,5,6,6,5,4,4,3,3,2,2,1,5,5,4,4,3,3,2,5,5,4,4,3,3,2,1,1,5,5,6,6,5,4,4,3,3,,2,2,1 music_datalzlh db 1,2,3,1,1,2,3,1,3,4,5,3,4,5,5,6,5,4,3,1,5,6,5,4,3,1,2,5,1,2,5,1 mus_t1 db 50,50,50,100,50,50,50,100,50,50,25,50,50,25,15,15,15,15
35、,50,25,15,15,15,15,50,25,50,75,50,50,70,50 ;mus_t db 50,50,50,50,50,50,50,100,50,50,50,50,50,50,50,100,50,50,50,50,50,50,50,100,50,50,50,50,50,50,50,100,50,50,50,50,50,50,50,100,50,50,50,50,50,50,50,100 msg db xiao xing xing:,0dh,0ah,$ data ends code segment assume cs:code,ds:data star
36、t: mov ax,data mov ds,ax mov dx,offset msg mov ah,9 int 21h ;tishi mov bx,0 push bx sing: pop bx ; mov si,offset music_dataxxx mov si,offset music_datalzlh add si,bx push bx mov al,byte ptr[si] ; que pu zhi
37、 ;cmp al,1 ;jl sing ;cmp al,8 ;jg sing ;sub al,31h shl al,1 mov bl,al mov bh,0 mov ax,4240h mov dx,0fh div word ptr[table+bx] mov bx,ax mov dx,timerctl mov al,00110110B out dx,al mov dx,timer0 mov ax,bx out dx,al
38、 mov al,ah out dx,al mov dx,io8255z mov al,10000000B out dx,al mov dx,io8255a mov al,03h out dx,al lea si,mus_t1 ;lea si,mus_t mov bx,[si] call MUS_D ;out dx,al call delay mov al,0h out dx,al ;guan yang sheng
39、 qi pop bx cmp bx,42 je hehe add bx,1 push bx jmp sing hehe: mov bx,0 push bx jmp sing finish: mov ax,4c00h int 21h MUS_D proc Leng: mov cx,2081 delay1: Loop delay1 dec bx jnz Leng
40、 ret MUS_D endp delay proc near push cx push ax mov ax,15 x1:mov cx,0ffffh x2:dec cx jnz x2 dec ax jnz x1 pop ax pop cx ret delay endp code ends end start 实验四 int00 equ 28
41、8h int01 equ 289h io8255c equ 282h io8255z equ 283h N equ 7 code segment assume cs:code start: call I8255 cli mov bx,0 call WRITE0B call I8259 mov cl,0 sti l1: cmp cl,N jnz l1 mov ah,4ch int 21h INT_SERVICE PROC push dx
42、 ; mov dx,io8255c ;mov al,0FFH ;out dx,al inc bx mov al,bl mov ah,bh mov dx,io8255c out dx,ax NOP NOP NOP mov al,20h out 20h,al NOP pop dx iret NT_SERVICE ENDP WRITE0B PROC mov ax,code mov ds,ax mov d
43、x,offset INT_SERVICE mov ax,250bh int 21h ret WRITE0B ENDP I8255 PROC mov al,80h mov dx,io8255z out dx,al ret I8255 ENDP I8259 PROC mov al,00010011b mov dx,int00 out dx,al mov al,8 mov dx,int01 out dx,al mov al,00000001b
44、out dx,al mov al,0 out dx,al in al,21h and al,0f7h out 21h,al ret I8259 ENDP code ends end start 实验5 锯齿波: io0832a equ 290h code segment assume cs:code start: mov cl,0 mov dx,io0832a ll1: mov al,cl out dx,al add cl,1 push dx
45、 mov ah,06h ;判断是否有键按下 mov dl,0ffh int 21h pop dx jz ll1 mov ah,4ch int 21h code ends end start 正弦波: data segment io0832a equ 290h sin db 80h,96h,0aeh,0c5h,0d8h,0e9h,0f5h,0fdh db 0ffh,0fdh,0f5h,0e9h,0d8h,0c5h,0aeh,96h db 80h,66h,4eh,38h,25h,1
46、5h,09h,04h db 00h,04h,09h,15h,25h,38h,4eh,66h data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax l1: mov si,offset sin mov bh,32 ll1: mov al,[si] mov dx,io0832a out dx,al mov ah,06h ;判断是否有键按下 mov dl,0ff
47、h int 21h jne exit mov cl,1 delay: loop delay inc si dec bh jnz ll1 jmp l1 exit: mov ah,4ch int 21h code ends end start 直流电机转速控制: data segment Io0832a equ 290h io8255c equ 28ah io8255z equ 28bh data ends code segment assume cs:code,d
48、s:data start: mov ax,data mov ds,ax mov al,85h ;8255初始化 mov dx,io8255z out dx,al lp1: mov dx,io8255c ;开关值赋给cx作为循环次数 in al,dx mov ah,0 mov cx,ax lp2: mov al,0ffh mov dx,io8032a out dx,al mov ah,06h ;判断
49、是否有键按下 mov dl,0ffh int 21h jne exit loop lp2 lp3: mov cx,32 lp4: mov al,80h mov dx,io8032a out dx,al mov ah,06h ;判断是否有键按下 mov dl,0ffh int 21h jne exit loop lp4 jmp lp1 exit: mov ah,4ch int 21h code ends end star
50、t 实验六 模数转换 io0809a equ 298h code segment assume cs:code start:mov dx,io0809a out dx,al mov cx,0ffh delay:loop delay in al,dx mov bl,al mov cl,4 shr al,cl call disp mov al,bl and al,0fh call d
51、isp mov ah,02 mov dl,20h int 21h mov dl,20h int 21h push dx mov ah,06h mov dl,0ffh int 21h pop dx je start mov ah,4ch int 21h disp proc near mov dl,al cmp dl,9 jle ddd add dl,7 ddd:add dl,30h mov
52、 ah,02 int 21h ret disp endp code ends end start 温度传感器数据采集 io0809a equ 298h code segment assume cs:code start:mov dx,io0809a out dx,al mov cx,0ffh delay:loop delay in al,dx mov bl,al mov cl,4 shr al,cl call disp m
53、ov al,bl and al,0fh call disp mov ah,02h mov dl,20h int 21h mov dl,20h int 21h mov dl,20h int 21h mov dl,20h int 21h push dx mov ah,06h mov dl,0ffh int 21h pop dx je start mo
54、v ah,4ch int 21h disp proc near mov dl,al cmp dl,9 jne ddd add dl,7 ddd:add dl,30h mov ah,02h int 21h ret disp endp code ends end start 压力传感器数据采集实验 io0809a equ 298h code segment assume cs:code start:m
55、ov dx,io0809a out dx,al mov cx,0ffh delay:loop delay in al,dx mov bl,al mov cl,4 shr al,cl call disp mov al,bl and al,0fh call disp mov ah,02h mov dl,20h int 21h mov dl,20h int 21h push d
56、x mov ah,06h mov al,0ffh int 21h pop dx je start mov ah,4ch int 21h disp proc near mov dl,al cmp dl,9 jne ddd add dl,7 ddd:add dl,30h mov ah,02 int 21h ret disp endp code e
57、nds end start 综合: io0809a equ 298h io0832a equ 290h code segment assume cs:code start: mov dx,io0809a out dx,al mov cx,0ffh delay: loop delay in al,dx mov dx,io0832a out dx,al push dx ;判断是否有键按下 mov ah,06h mov dl,0ffh int 21h pop dx je start ;没键按下转start mov ah,4ch int 21h code ends end start
- 温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。