标题:谁给写一个中断定时50ms精确地程序
只看楼主
chen3bing
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:507
专家分:104
注 册:2008-11-12
结帖率:91.22%
已结贴  问题点数:10 回复次数:15 
谁给写一个中断定时50ms精确地程序
谁给写一个中断定时50ms精确地程序,谢谢!
搜索更多相关主题的帖子: 中断 定时 精确 
2019-01-06 15:19
chen3bing
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:507
专家分:104
注 册:2008-11-12
得分:0 
我不会用多媒体定时器,谁教教我
2019-01-06 15:55
chen3bing
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:507
专家分:104
注 册:2008-11-12
得分:0 
用API方式定时举个例子
2019-01-06 16:07
wds1
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:49
帖 子:393
专家分:2025
注 册:2016-3-10
得分:2 
'延时调用函数
Public Declare Function timeGetTime Lib "winmm.dll" () As Long

call sleep(50)'相当于延时50ms


Public Sub sleep(seconds As Integer)
Dim temp As Variant
temp = timeGetTime
  While timeGetTime - seconds < temp
  DoEvents
  Wend
End Sub
2019-01-06 16:54
wds1
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:49
帖 子:393
专家分:2025
注 册:2016-3-10
得分:2 
类模块程序
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

Public Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
    Form1.Print Now()
    DoEvents
End Sub

窗体程序
Public ID1
Dim bz1 As Boolean

Private Sub Form_Load()
    bz1 = False
   Command1.Caption = "定时开始"
End Sub

Private Sub Command1_Click()
    If bz1 = False Then
        '每50ms调用一次函数
        ID1 = SetTimer(0, 0, 50, AddressOf TimerProc)
        bz1 = True
        Command1.Caption = "定时结束"
    Else
        KillTimer 0, ID1
        bz1 = False
        Command1.Caption = "定时开始"
    End If
End Sub

2019-01-06 22:43
chen3bing
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:507
专家分:104
注 册:2008-11-12
得分:0 
回复 5楼 wds1
谢谢!类模块程序有错误
2019-01-07 08:40
chen3bing
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:507
专家分:104
注 册:2008-11-12
得分:0 

只有16次,貌似定时不准。
2019-01-07 09:00
wds1
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:49
帖 子:393
专家分:2025
注 册:2016-3-10
得分:2 
用这个吧
mmTimer.ctl
2019-01-07 11:23
chen3bing
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:507
专家分:104
注 册:2008-11-12
得分:0 
回复 8楼 wds1
谢谢,mmt出来了,可是我想放到窗体上,提示错误
2019-01-07 11:34
wds1
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:49
帖 子:393
专家分:2025
注 册:2016-3-10
得分:2 
毫秒.zip (45.2 KB)


Private Sub CmdStart_Click()
        mmTimer1.Init 50
        Timer1.Interval = 50
        Timer1.Enabled = True
End Sub

Private Sub CmdStop_Click()
        mmTimer1.Destroy
        Timer1.Enabled = False
End Sub


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Static cnt As Long
        cnt = cnt + 1
        Text1.Text = cnt
End Sub


Private Sub mmTimer1_Timer()
        Static cnt As Long
        frmMain.Print Now()
        cnt = cnt + 1
        Text1.Text = cnt
End Sub

Private Sub Timer1_Timer()
        Static cnt As Long
        cnt = cnt + 1
        Text2.Text = cnt
End Sub
2019-01-07 11:40



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-492535-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.131189 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved