原创 基于微机的汇编时钟设计

2009-12-5 19:27 2816 11 11 分类: 通信

其实现在很多学校和科研单位还是经常使用汇编语言来实现程序设计的。汇编语言在高校还是有一点市场的。微型计算机原理的汇编语言时钟设计也是很重要的。下面是汇编语言时钟设计程序,用的是8237微机。大家可参考一下。
Data segment
Table dw 28h,70,8,78,28,28h,78,28,102,36,28h,110,28,134,36,28h,134,8,142,28,28h
        Dw 110,0,134,8,28h,78,0,102,8,00h,102,8,110,28                ;0每个段码占70个字节
        dw 00h,70,8,78,28,28h,78,28,102,36,28h,110,28,134,36,00h,134,8,142,28,00h
        Dw 110,0,134,8,00h,78,0,102,8,00h,102,8,110,28                ;1
        dw 28h,70,8,78,28,28h,78,28,102,36,00h,110,28,134,36,28h,134,8,142,28,28h
        Dw 110,0,134,8,00h,78,0,102,8,28h,102,8,110,28                ;2
        dw 28h,70,8,78,28,28h,78,28,102,36,28h,110,28,134,36,28h,134,8,142,28,00h
        Dw 110,0,134,8,00h,78,0,102,8,28h,102,8,110,28                ;3
        dw 00h,70,8,78,28,28h,78,28,102,36,28h,110,28,134,36,00h,134,8,142,28,00h
        Dw 110,0,134,8,28h,78,0,102,8,28h,102,8,110,28                ;4
        dw 28h,70,8,78,28,00h,78,28,102,36,28h,110,28,134,36,28h,134,8,142,28,00h
        Dw 110,0,134,8,28h,78,0,102,8,28h,102,8,110,28                ;5
        dw 28h,70,8,78,28,00h,78,28,102,36,28h,110,28,134,36,28h,134,8,142,28,28h
        Dw 110,0,134,8,28h,78,0,102,8,28h,102,8,110,28                ;6
        dw 28h,70,8,78,28,28h,78,28,102,36,28h,110,28,134,36,00h,134,8,142,28,00h
        Dw 110,0,134,8,00h,78,0,102,8,00h,102,8,110,28                ;7
        dw 28h,70,8,78,28,28h,78,28,102,36,28h,110,28,134,36,28h,134,8,142,28,28h
        Dw 110,0,134,8,28h,78,0,102,8,28h,102,8,110,28                ;8
        dw 28h,70,8,78,28,28h,78,28,102,36,28h,110,28,134,36,28h,134,8,142,28,00h
        Dw 110,0,134,8,28h,78,0,102,8,28h,102,8,110,28                ;9


Pin     dw 28h,88,5,96,13,28h,118,5,126,13                        ;点28H亮,00H暗
        dw 28h,88,105,96,113,28h,118,105,126,113                ;第二列
Hl        dw ?         ;列中间值
Vl        dw ?        ;列
hms db 8 dup(?)        ;时十、时个、分十、分个、秒十、秒个
Mode dw ?                 ;存原来的工作模式,供结束时恢复用
Count db ?                ;段码序号
S        DB ?                ;存秒值,判别是否改变
STR                DB ' 2006.6.30',0DH,0AH,'$'
Data ends


Code segment
Time proc far
Assume cs:code,ds:data
Startush ds
        Xor ax,ax
        Push ax                        ;为返回DOS


        Push bx
        Push cx
        Push dx
        Push si
        Push di                        ;保护现场
        Mov ax,data
        Mov ds,ax                ;数据段
        Mov ah,0fh
        Int 10h                        ;取当前显示模式
        Mov mode,ax                ;并且储存,以被结束时恢复
        Mov ax,0013h
        Int 10h                        ;设置新的工作模式13H,320*200,256色VGA
Hms0:Lea di,hms                ;取分位存时分秒的首地址
Mov ah,2ch
Int 21h                        ;取系统时间,时:分:秒--CH:CLH
CMP DH,S
JE HMS0                        ;秒没改变,再取,不显示
MOV S,DH                ;秒发生改变了
Mov al,ch
Xor ah,ah
mov ch,0ah
Div ch
Mov [di],al                ;存时十位
Inc di
Mov [di],ah                ;存时个位
Inc di
Mov al,cl
Xor ah,ah
mov ch,0ah
Div ch
Mov [di],al                ;存分十位
Inc di
Mov [di],ah                ;存分个位
Inc di
Mov al,dh
Xor ah,ah
mov ch,0ah
Div ch
Mov [di],al                ;存秒十位
Inc di
Mov [di],ah         ;存秒个位
Mov  bx,20                ;初始位置,BX中记录列位置
Lea di,hms                ;取时分秒首地址
Mov al,[di]                ;时十位值*70找到相应段码位置
mov ch,70
Mul ch
        Lea si,table
        Add si,ax                ;生成相应数值的段码位置
        Call disp                 ;显示时十位
Inc di
Mov al,[di]                ;时个位值*70找到相应段码位置
mov ch,70
Mul ch
        Lea si,table
        Add si,ax                ;生成相应数值的段码位置
        call disp                        ;显示时个位
        lea si,pin                        ;取点位
        call disp1                        ;显示第一对点
        Inc di
        Mov al,[di]                        ;分十位值*70找到相应段码位置
        mov ch,70
        Mul ch
        Lea si,table
        Add si,ax                         ;生成相应数值的段码位置
        call disp                        ;显示分十位
        Inc di
        Mov al,[di]                        ;分个位值*70找到相应段码位置
        mov ch,70
        Mul ch
        Lea si,table
        Add si,ax                         ;生成相应数值的段码位置
        call disp                        ;显示分个位
;        lea si,pin                         ;取点位
;        call disp1                        ;显示第二对点
        ADD BX,20                        ;调整列值
        Inc di
        Mov al,[di]                        ;秒十位值*70找到相应段码位置
        mov ch,70
        Mul ch
        Lea si,table
        Add si,ax                         ;生成相应数值的段码位置
        call disp                        ;显示秒十位
        Inc di
        Mov al,[di]                        ;秒个位值*70找到相应段码位置
        mov ch,70
        Mul ch
        Lea si,table
        Add si,ax                         ;生成相应数值的段码位置
        call disp                        ;显示秒个位
        Mov ah,1                        ;读键盘缓冲区
        Int 16h
        Jz loop1                        ;没按键,跳
        Cmp al,1bh                        ;有键按下,看是否ESC(结束键)
        Je loop0                        ;结束
Loop1:        Jmp hms0                ;循环下去
Loop0:        Mov ax,mode                ;恢复原显示模式
        And ax,0ffh
        Int 10h
        LEA DX,STR
        MOV AH,9
        INT 21H
        Pop di                                ;恢复现场
        Pop si
        Pop dx
        Pop cx
        Pop bx
        Ret
Time endp


Disp proc near                        ;显示数字子程序
        Mov count,7                        ;7段
L2:        Mov ax,[si]                        ;取相应数字的A-G段色码
        Add si,2
        Mov dx,[si]                        ;取相应数字的A-G段左上角行号
        add si,2
        Mov cx,[si]                        ;取相应数字的A-G段左上角列号
    add cx,bx
        Mov vl,cx                        ;显示时的实际列号
        Add si,2
L1:        mov cx,vl
        Mov ah,0ch
L0:        Int 10h                                ;显示
        Mov hl,bx
        Add bx,[si+2]
        xchg hl,bx                        ;计算右下角列值
        Inc cx
        Cmp cx,hl                        ;和右下角列值比较
        Jne l0
        Inc dx
        Cmp dx,[si]                        ;和右下角行值比较
        Jne l1
        Add si,4
        Dec count                        ;下一段
        Jnz l2
    Add bx,40                        ;产生下一个位置
        Ret
Disp endp


Disp1 proc near                        ;显示点子程序
Push di                                ;保存DI
        Mov count,4                        ;4段
L21:Mov ax,[si]                        ;取相应点的4段色码
Lea di,hms
Mov ah,5[di]                ;取秒个位
And ah,1                        ;BCD码的最低位来判别奇偶
Jnz not0
Xor al,al                        ;偶数秒,使点暗,奇数秒点亮
Not0:        Add si,2
        Mov dx,[si]                        ;取左上角行
        add si,2
        Mov cx,[si]                        ;取左上角列
    add cx,bx                        ;产生显示列位
        Mov vl,cx                        ;存列
        Add si,2
L11:        mov cx,vl
        Mov ah,0ch
L01:        Int 10h                        ;显示
        Mov hl,bx
        Add bx,[si+2]
        xchg hl,bx                        ;计算右下角列值,存HL单元
        Inc cx
        Cmp cx,hl                        ;比较右下角列值
        Jne l01
        Inc dx
        Cmp dx,[si]                        ; 比较右下角行值
        Jne l11
        Add si,4
        Dec count
        Jnz l21
    Add bx,20
Pop di
        Ret
Disp1 endp
Code ends
        End start

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
11
关闭 站长推荐上一条 /3 下一条