汇编:定时器代码

.386
.model flat, stdcall
option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include ????
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include gdi32.inc
includelib gdi32.lib
IDD_DLG1   equ 1000
IDC_STC1 equ 1002
IDC_EDT1 equ 1001
IDC_IMG1 equ 1003
A equ 1
B equ 2
TIMER1 equ 1
TIMER2 equ 2
.data?
hInstance dd ?
dwCount dd ?
hWinMain dd ?
.const
aa db 'no',0
bb db 'yes',0
.code


_ProTime proc
pushad
invoke GetDlgItemInt,hWinMain,IDC_EDT1,NULL,FALSE
inc eax
invoke SetDlgItemInt,hWinMain,IDC_EDT1,eax,FALSE
popad
ret
_ProTime endp
_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam
mov eax,wMsg
.if eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
invoke KillTimer,hWnd,TIMER1
invoke KillTimer,hWnd,TIMER2
.elseif   eax==WM_INITDIALOG
push hWnd
pop hWinMain
invoke  SetTimer,hWnd,TIMER1,2000,NULL
invoke SetTimer,hWnd,TIMER2,1000,NULL
invoke SetTimer,NULL,NULL,1000,addr _ProTime

.elseif eax==WM_TIMER
mov eax,wParam
.if eax==1
invoke MessageBeep,-1
.elseif eax==2
inc dwCount
mov eax,dwCount
and eax,1
inc eax
invoke LoadIcon,hInstance,eax
invoke SendDlgItemMessage,hWnd,IDC_IMG1,STM_SETIMAGE,IMAGE_ICON,eax
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,IDD_DLG1,NULL,offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
end start
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
;name: ELECTRONIC CLOCK data segment mess1 db 'Press C or c to correct the time',0ah,0dh db 'Press R or r to SET the RING time',0ah,0dh db 'Press ESC button to exit',0ah,0dh,'$' tn db 'Please input the new time (hh:mm:ss):',0dh,0ah,'$' tM db 'Please input the RING time (hh:mm:SS):',0dh,0ah,'$' mess2 db 'Time is:',0ah,0dh,'$' t_buff db 40 ;在数据段开一段时间显示缓冲区 db ? db 40 dup (?) HOR1 DB 'S' MIN1 DB 'S' SEC1 DB 'S' hor db ? min db ? sec db ? fg db 0 data ends stack segment db 100 dup(?) stack ends code segment assume cs:code,ss:stack,ds:data ;确定各个逻辑段的类型 start: call clear ;调用清屏子程序 display: ;时间显示部分 mov ax,data mov ds,ax mov bx,offset t_buff ;送t_buff的偏移地址到BX mov ah,2ch ;调用DOS时间调用功能,功能号:2cH,小时,分钟,秒数分别保存在CH,CL,DH中 int 21h mov al,ch ;小时数设定 mov ah,0 call bctd ;调用进制转换子程序 CALL ASC ;---------------------------------------------------------- mov al,':' ;显示分隔符号 mov [bx],al inc bx ;------------------------------------------------------- mov ah,2ch int 21h mov al,cl ;分钟数设定 mov ah,0 call bctd CALL ASC ;------------------------------------------------------------------------- mov al,':' ;显示分隔符号 mov [bx],al inc bx ;------------------------------------------------------------------------- mov ah,2ch ;秒设定 int 21h mov al,dh mov ah,0 call bctd CALL ASC ;---------------------------------------------------------------------- mov al,'$' ;将字符串的结束位送至显示缓冲区的最后一位 mov [bx],al ;------------------------------------------------------------------------------ push bx ;置光标位置 ,AH=2,BH=0,DH跟DL分别为行号与列号,并入栈保护BX mov ah,2 mov bh,0 mov dh,3 mov dl,8 int 10h pop bx lea dx,t_buff ;送t_buff偏移地址到DX,并调用DOS显示功能,功能号为9 mov ah,9 int 21h push bx ;置光标位置 mov ah,2 mov bh,0 mov dh,0 mov dl,0 int 10h pop bx lea dx,mess1 mov ah,9 int 21h push bx ;置光标位置 mov ah,2 mov bh,0 mov dh,3 mov dl,0 int 10h pop bx lea dx,mess2 mov ah,9 int 21h ;------------------------------------------------- mov ah,2ch ;调用DOS时间调用功能,功能号:2cH,小时,分钟,秒数分别保存在CH,CL,DH中 int 21h CMP CH,HOR1 JNZ nxt ;判断闹钟是否到时,如果到时调用07H输出响声 CMP CL,MIN1 JNZ nxt CMP DH,SEC1 JNZ nxt MOV DL,07H MOV AH,02H INT 21H ;----------------------------- nxt: call delay1 mov ah,1 ;调用键盘I/O中断功能号1,获取键值到AL int 16h cmp al,'c' ;是c键,转到时间修改程序 je Cor cmp al,'C' ;是C键,转到时间修改程序 je Cor CMP AL,'R' JE RING CMP AL,'r' JE RING cmp al,1bh jz quit ;是ESC键,退出程序 JMP DISPLAY quit:mov ah,4ch ;程序终止功能号 int 21h ret RING: call INPUT2 JMP START Cor: call correct ;调用时间修改子程序 ;------------------------------- bctd proc near ;二进制转BCD码子程序 ;AX输入参数 ;AX输出参数,存放调整过的BCD码 mov dx,ax mov ax,0 mov cx,16 ;设循环次数 bctd1: clc ;清进位标志C rcl dx,1 ;通过进位的循环右移 adc al,al ;带进位加法 daa ;加法的十进制调整 xchg al,ah ;交换高、低八位 adc al,al daa xchg al,ah loop bctd1 ;循环次数保存在CX里 ret bctd endp ;------------------------------------------- clear proc near push ax ;入栈保护现场 push bx push cx push dx mov ax,0600h ;ah=06(滚动)al=00(全屏空白) mov bh,0fh ;设置背景颜色(2)和前景颜色(e) sub cx,cx mov dx,5f5fh int 10h pop dx ;出栈恢复现场 pop cx pop bx pop ax ret clear endp ;----------------------------------------- delay1 PROC ;精确延迟时间子程序 MOV DX,04ffh ;循环次数 up: XOR CX,CX a: NOP LOOP a DEC DX JNZ up RET delay1 ENDP ;---------------------------- correct proc ;时间修改子程序 call input ;调用键盘输入子程序输入数据 mov ch,hor mov cl,min mov dh,sec and dl,0h mov ah,2dh int 21h jmp start ret correct endp ;---------------------------------- input2 proc ;闹钟设置子程序 push ax ;入栈保护数据 push bx push cx push dx pushf mov dx,offset tm ;显示设置闹钟的格式提示 mov ah,09h int 21h mov dx,offset t_buff ;数据缓冲区的数据输入 mov ah,0ah int 21h and dx,0h lea bx,t_buff inc bx inc bx mov dh,[bx] sub dh,30h inc bx mov dl,[bx] sub dl,30h mov cl,10 mov al,dh mul cl add al,dl mov ch,al mov hor1,al inc bx inc bx mov dh,[bx] sub dh,30h inc bx mov dl,[bx] sub dl,30h mov cl,10 mov al,dh mul cl add al,dl mov cl,al mov min1,al inc bx inc bx mov dh,[bx] sub dh,30h inc bx mov dl,[bx] sub dl,30h mov cl,10 mov al,dh mul cl add al,dl mov dh,al mov sec1,al popf ;出栈恢复数据 pop dx pop cx pop bx pop ax ret input2 endp ;---------------------------------- input proc ;键盘输入子程序 push ax ;入栈保护数据 push bx push cx push dx pushf mov dx,offset tn ;显示修改时间的格式提示 mov ah,09h int 21h mov dx,offset t_buff ;数据缓冲区的数据输入 mov ah,0ah int 21h and dx,0h lea bx,t_buff inc bx inc bx mov dh,[bx] sub dh,30h inc bx mov dl,[bx] sub dl,30h mov cl,10 mov al,dh mul cl add al,dl mov ch,al mov hor,al inc bx inc bx mov dh,[bx] sub dh,30h inc bx mov dl,[bx] sub dl,30h mov cl,10 mov al,dh mul cl add al,dl mov cl,al mov min,al inc bx inc bx mov dh,[bx] sub dh,30h inc bx mov dl,[bx] sub dl,30h mov cl,10 mov al,dh mul cl add al,dl mov dh,al mov sec,al popf ;出栈恢复数据 pop dx pop cx pop bx pop ax ret input endp ;---------------------------- ASC PROC PUSH AX AND AL,0F0H ;选取AL高四位 MOV CL,4 ;设置右循环的次数 ROL AL,CL ;右循环 OR AL,30H ;加30H得到ACSII码 MOV [BX],AL ;将得到的结果送到T_BUFF缓冲区 INC BX ;BX自加1,指针指向下一个缓冲区的下一个地址 POP AX AND AL,0FH ;选取低四位 OR AL,30H MOV [BX],AL ;将转换后的低四位值送入缓冲区的第二个地址 INC BX RET ASC ENDP ;---------------------------------- code ends end start

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值