正文

大学时代接口实验之小键盘接口程序2006-10-10 14:14:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/sonicling/19183.html

分享到:

需要和8255程序一同连接,注意初始化参数与引脚连接方式有关。 .286public _getcharextrn _i8255:near,_outpb:near,_inpa:neardseg segment para public 'DATA'INVALID equ 0ffhg_ch_tbl  db 'C','D','E','F','B','A','9','8'  db '4','5','6','7','3','2','1','0'  db 'W','X','Y','S','R','P','M','G'dseg endscseg segment para public 'CODE' assume cs:cseg,ds:dsegstart:_getchar proc   ;char getchar(){ call _testkey ; char al = testkey(); cmp al,0ffh  ; if(al == INVALID){ je gc_ret  ;   return INVALID;    ; }    ; else{ call _scankey  ;   al = scankey(); cmp al,INVALID ;   if(al == INVALID) return INVALID; je gc_ret mov bx,ax  ;   return g_ch_tbl[al]; mov al,g_ch_tbl[bx] ; } retgc_ret: mov ax,INVALID ret_getchar endp   ;} _testkey proc   ;char testkey() mov al,07h  ;{ xor al,0ffh call _outpb  ; outpb(0f8h); call _inpa  ; return inpa(); ret_testkey endp   ;} _scankey proc   ;int scankey(){ mov bx,0  ; int code = 0; mov dx,0  ; int index = 0; mov ax,1  ; int outcode = 1; xor ax,0ffffh mov cx,3  ; for(int i=0;i<3;i++)for_3:    ; { push ax call _scanline ;   code = scanline(~outcode); mov bx,ax pop ax cmp bl,0ffh  ;   if(code != INVALID){ je for_3_next push ax mov ax,bx call _transcode ;    index += transcode(code); add dx,ax pop ax call _waitup  ;    waitup(~outcode,code); mov ax,dx ret   ;    return index;    ;   }for_3_next:   ;   else{ add dx,8  ;    index += 8; rol ax,1  ;    outcode << 1; loop for_3  ;   } mov ax,INVALID ; } ret   ; return INVALID;_scankey endp   ;} _scanline proc   ;char scanline(char outcode){ call _outpb  ; outpb(outcode); call _inpa  ; return inpa(); ret_scanline endp   ;} _transcode proc   ;int transcode(char code){ push bx mov bx,1  ; char test = 1; xor bl,0ffh  mov cx,8  ; for(int i=0;i<8;i++)tc_lp:    ; { cmp al,bl  ;   if(code == ~test) je tc_ret  ;    return 8-i; rol bl,1  ;   test << 1; loop tc_lp  ; }tc_ret: mov ax,8 sub ax,cx pop bx ret_transcode endp   ;} _waitup proc   ;void waitup(char outcode,char code) pusha   ;{ mov dx,axwu_lp:    ;wu_lp: mov ax,dx call _scanline ; char test = scanline(outcode); cmp ax,bx  ; if(test == code) je wu_lp  ;   goto wu_lp; popa ret_waitup endp   ;} cseg ends end start

阅读(7184) | 评论(1)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册