
一秒的速度太慢,我给你设置了001秒
Option Explicit
Dim MinSec As Integer
Dim Sec As Integer
Dim Minute As Integer
Dim Hour As Integer
Private Sub Command1_Click() '开始
Timer1Enabled = True
End Sub
Private Sub Command2_Click() '停止
Timer1Enabled = False
MsgBox "现在是" & Label2Caption
End Sub
Private Sub Command3_Click() '取消
Timer1Enabled = False
Hour = 0
Minute = 0
MinSec = 0
Sec = 0
Label2Caption = Format(Hour, "00") & "时" & Format(Minute, "00") & "分" & Format(Sec, "00") & "秒" & Format(MinSec, "00")
End Sub
Private Sub Form_Load()
Timer1Enabled = False
Timer1Interval = 10
End Sub
Private Sub Timer1_Timer()
MinSec = MinSec + 1
If MinSec = 100 Then
MinSec = 0
Sec = Sec + 1
If Sec = 60 Then
Sec = 0
Minute = Minute + 1
If Minute = 60 Then
Minute = 0
Hour = Hour + 1
Else
End If
Else
End If
Else
End If
Label2Caption = Format(Hour, "00") & "时" & Format(Minute, "00") & "分" & Format(Sec, "00") & "秒" & Format(MinSec, "00")
End Sub
共阳数码管中断程序:
#include<reg52h>
#define uint unsigned int
#define uchar unsigned char
uchar code table[]=
{
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x83,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
uint num,a;
uchar bai,shi,ge;
void init();
void delay(uint);
void display(ucharbai,ucharshi,ucharge);
uint fb();
uint fs();
uint fg();
void main()
{
init();
while(1)
{
display(fb(),fs(),fg());
}
}
void init()
{
num=0;
a=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void display(ucharbai,ucharshi,ucharge)
{
P1=0xfd;
P0=table[bai];
delay(1);
P1=0xfb;
P0=table[shi];
delay(1);
P1=0xf7;
P0=table[ge];
delay(1);
}
void timeoff() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65526-50000)%256;
a++;
if(a%20==0)
{
num++;
if(num==999)
{
num=0;
}
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
uint fb()
{
bai=num/100;
return bai;
}
uint fs()
{
shi=num%100/10;
return shi;
}
uint fg()
{
ge =num%100%10;
return ge;
}
扩展资料
2个可编程定时/计数器·5个中断源,2个优先级(52有6个)
一个全双工串行通信口
外部数据存储器寻址空间为64kB
外部程序存储器寻址空间为64kB
逻辑 *** 作位寻址功能·双列直插40PinDIP封装
单一+5V电源供电
CPU:由运算和控制逻辑组成,同时还包括中断系统和部分外部特殊功能寄存器;
RAM:用以存放可以读写的数据,如运算的中间结果、最终结果以及欲显示的数据;
ROM:用以存放程序、一些原始数据和表格;
I/O口:四个8位并行I/O口,既可用作输入,也可用作输出
T/C:两个定时/记数器,既可以工作在定时模式,也可以工作在记数模式;
五个中断源的中断控制系统;
一个全双工UART(通用异步接收发送器)的串行I/O口,用于实现单片机之间或单片机与微机之间的串行通信;
片内振荡器和时钟产生电路,石英晶体和微调电容需要外接。最佳振荡频率为6M—12M。
参考资料来源:百度百科-51单片机
这什么东西啊,也太乱了吧!用一个GetTickCount这个API函数;
GetTickCount函数
函数功能:GetTickCount返回(retrieve)从 *** 作系统启动到现在所经过(elapsed)的毫秒数,它的返回值是DWORD。
函数原型: DWORD GetTickCount(void);
C/C++头文件:winbaseh
windows程序设计中可以使用头文件windowsh
程序示例
//代替time函数来初始化随机数生成器
#include<stdioh>
#include<windowsh>
int main()
{
int i,k,r;
for(i=0;i<10;i++)
{
srand(GetTickCount());
printf("\n");
for(k=0;k<5;k++)
{
r=rand();
printf("%d ",r);
}
}
return 0;
}
注意事项
GetTickcount函数:它返回从 *** 作系统启动到当前所经过的毫秒数,常常用来判断某个方法执行的时间,其函数原型是DWORD GetTickCount(void),返回值以32位的双字类型DWORD存储,因此可以存储的最大值是2-1 ms约为4971天,因此若系统运行时间超过4971天时,这个数就会归0,MSDN中也明确的提到了:"Retrieves the number of milliseconds that have elapsed since the system was started, up to 497 days"。因此,如果是编写服务器端程序,此处一定要万分注意,避免引起意外的状况。
这个是从百度百科上贴过来的。
//Timer3初始化 下面是使用timer3做的500mA计时器,给你参考
void Timer3_Init(void)
{
//主时钟1s
INSCON|=(1<<BKS0);
TL3=(unsigned char)T3CLK_500MS;
TH3=(unsigned char)(T3CLK_500MS>>8);
TF3=0;
switch(T3CLK_DIV)
{
case CLK_DIV_8:
T3PS0=1;
T3PS1=0; //1/8预分频
break;
case CLK_DIV_64:
T3PS0=0;
T3PS1=1; //1/64预分频
break;
case CLK_DIV_256:
T3PS0=1;
T3PS1=1; //1/256预分频
break;
default:
T3PS0=0;
T3PS1=0; //无预分频
}
T3CLKS1=0;
T3CLKS0=0;
TR3=1;
}
//
/Function Name:void Timer3_ISP(void)
/Input:
/Output:
/Description:Timer3_ISP Interrupt
/Data:
//
extern void os_timer(void);
void Timer3_ISP(void) interrupt 11
{
uchar data temp_inscon;
temp_inscon=INSCON;
INSCON&=~(1<<BKS0);
os_timer(); //这个中断500mA进来一次
INSCON=temp_inscon;
}
using System;
using SystemCollections;
using SystemTimers;
using SystemRuntimeInteropServices;
using SystemCollectionsGeneric;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemLinq;
using SystemText;
using SystemWindowsForms;
namespace 计时器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("kernel32",EntryPoint="Beep")]
public extern static int Beep(int dwfreq,int dwduration);
private void numericUpDown3_ValueChanged(object sender, EventArgs e)
{
string hour, minute, second;
if (numericUpDown3Value == 60)
{
numericUpDown3Value = 0;
numericUpDown2Value = ConvertToInt32(numericUpDown2Value) + 1;
int our = ConvertToInt32(numericUpDown1Value);
int niuit = ConvertToInt32(numericUpDown2Value);
int secon = ConvertToInt32(numericUpDown3Value);
if (our < 10)
{
hour = "0" + ourToString();
}
else
{
hour = ourToString();
}
if (niuit < 10)
{
minute = "0" + niuitToString() + ":";
}
else
{
minute = niuitToString() + ":";
}
if (secon < 10)
{
second = "0" + seconToString() + ":";
}
else
{
second = seconToString() + ":";
}
}
else
{
int our = ConvertToInt32(numericUpDown1Value);
int niuit = ConvertToInt32(numericUpDown2Value);
int secon = ConvertToInt32(numericUpDown3Value);
if (our < 10)
{
hour = "0" + ourToString()+ ":" ;
}
else
{
hour = ourToString()+ ":" ;
}
if (niuit < 10)
{
minute = "0" + niuitToString() + ":";
}
else
{
minute = niuitToString() + ":";
}
if (secon < 10)
{
second = "0" + seconToString();
}
else
{
second = seconToString();
}
}
label2Text = hour + minute + second;
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
string hour, minute, second;
if (numericUpDown2Value == 60)
{
numericUpDown2Value = 0;
numericUpDown1Value = ConvertToInt32(numericUpDown1Value) + 1;
int our = ConvertToInt32(numericUpDown1Value);
int niuit = ConvertToInt32(numericUpDown2Value);
int secon = ConvertToInt32(numericUpDown3Value);
if (our < 10)
{
hour = "0" + ourToString() + ":" ;
}
else
{
hour = ourToString() + ":" ;
}
if (niuit < 10)
{
minute = "0" + niuitToString() + ":";
}
else
{
minute = niuitToString() + ":";
}
if (secon < 10)
{
second = "0" + seconToString();
}
else
{
second = seconToString();
}
}
else
{
int our = ConvertToInt32(numericUpDown1Value);
int niuit = ConvertToInt32(numericUpDown2Value);
int secon = ConvertToInt32(numericUpDown3Value);
if (our < 10)
{
hour = "0" + ourToString() + ":";
}
else
{
hour = ourToString() + ":";
}
if (niuit < 10)
{
minute = "0" + niuitToString() + ":";
}
else
{
minute = niuitToString() + ":";
}
if (secon < 10)
{
second = "0" + seconToString() ;
}
else
{
second = seconToString();
}
}
label2Text = hour + minute + second;
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
string hour, minute, second;
if (numericUpDown1Value == 24)
{
numericUpDown1Value = 0;
int our = ConvertToInt32(numericUpDown1Value);
int niuit = ConvertToInt32(numericUpDown2Value);
int secon = ConvertToInt32(numericUpDown3Value);
if (our < 10)
{
hour = "0" + ourToString();
}
else
{
hour = ourToString() ;
}
if (niuit < 10)
{
minute = "0" + niuitToString() + ":";
}
else
{
minute = niuitToString() + ":";
}
if (secon < 10)
{
second = "0" + seconToString() + ":";
}
else
{
second = seconToString() + ":";
}
}
else
{
int our = ConvertToInt32(numericUpDown1Value);
int niuit = ConvertToInt32(numericUpDown2Value);
int secon = ConvertToInt32(numericUpDown3Value);
if (our < 10)
{
hour = "0" + ourToString() + ":";
}
else
{
hour = ourToString() + ":";
}
if (niuit < 10)
{
minute = "0" + niuitToString() + ":";
}
else
{
minute = niuitToString() + ":";
}
if (secon < 10)
{
second = "0" + seconToString();
}
else
{
second = seconToString();
}
}
label2Text = hour + minute +second ;
}
private void button1_Click(object sender, EventArgs e)
{
timer1Interval = 1000;
timer1Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
label1Text = DateTimeNowToString();
int hours = DateTimeNowHour;
int munit = DateTimeNowMinute;
int second = DateTimeNowSecond;
long dat;
if ((int)numericUpDown1Value > hours)
{
dat = (long)((int)numericUpDown1Value - hours) 3600 + ((int)numericUpDown2Value - munit) 60 + ((int)numericUpDown3Value - second);
}
else
{
if ((int)numericUpDown2Value > munit)
{
dat = (long)((int)numericUpDown1Value - hours) 3600 + ((int)numericUpDown2Value - munit) 60 + ((int)numericUpDown3Value - second);
}
else
{
if ((int)numericUpDown3Value >= second)
{
dat = (long)((int)numericUpDown1Value - hours) 3600 + ((int)numericUpDown2Value - munit) 60 + ((int)numericUpDown3Value - second);
}
else
{
dat = (long)((int)numericUpDown1Value + 24 - hours) 3600 + ((int)numericUpDown2Value - munit) 60 + ((int)numericUpDown3Value - second);
}
}
}
if (dat > 0)
{
label3Text = "闹钟已经启动";
label4Text = "剩余" + datToString() + "秒";
}
if (dat == 0)
{
timer1Enabled = false;
Beep(200, 500);
label4Text = "时间已到";
}
}
private void button2_Click(object sender, EventArgs e)
{
timer1Enabled = false;
label3Text = "闹钟已经停止";
}
}
}
倒计时生成器JS脚本
说明: 用来生成倒计时JS代码的脚本
效果: 点这里在新窗口中看效果!
代码: 要完成此效果需要两个步骤
第一步:把如下代码加入到<head>区域中
<SCRIPT language=javascript>
<!--
function generate(form){
for(var q=0;q<12;q++){
if(documentmemoptions[documentmemselectedIndex]value==q){
var m2=q+1
}
var txt='<!-- 要完成此效果需要三个步骤:\r\n\r\n'
+' 1 将第一部分粘贴到HTML的HEAD区\r\n'
+' 2 将OnLoad事件加入BODY标签内\r\n'
+' 3 将最后一部分代码加入BODY区 -->\r\n\r\n'
+'<!-- 第一步: 将如下代码加入到HEAD区域中-->\r\n\r\n'
+'<HEAD>\r\n\r\n<SCRIPT LANGUAGE="JavaScript">\r\n\r\n'
+'<!-- Begin\r\n'
+'var Temp2;\n'
+'var timerID = null;\n'
+'var timerRunning = false;\n'
+'function arry() {\n'
+'thislength = 12;\n'
+'this[0] = 31;\n'
+'this[1] = 28;\n'
+'this[2] = 31;\n'
+'this[3] = 30;\n'
+'this[4] = 31;\n'
+'this[5] = 30;\n'
+'this[6] = 31;\n'
+'this[7] = 31;\n'
+'this[8] = 30;\n'
+'this[9] = 31;\n'
+'this[10] = 30;\n'
+'this[11] = 31;\n'
+'}\n'
+'var date = new arry();\n'
+'\n'
+'function stopclock() {\n'
+'if(timerRunning)\n'
+'clearTimeout(timerID);\n'
+'timerRunning = false;\n'
+'}\n'
+'\n'
+'function startclock() {\n'
+'stopclock();\n'
+'showtime();\n'
+'}\n'
+'\n'
+'function showtime() {\n'
+'now = new Date();\n'
+'var CurMonth = nowgetMonth();\n'
+'var CurDate = nowgetDate();\n'
+'var CurYear = nowgetFullYear();\n'
+'now = null;\n'
+'if ('+documentmedoptions[documentmedselectedIndex]value+'<CurDate) {\n'
+'CurDate -= date[CurMonth]; CurMonth++;\n'
+'}\n'
+'if ('+documentmemoptions[documentmemselectedIndex]value+' < CurMonth) {\n'
+'CurMonth -= 12; CurYear++;\n'
+'}\n'
+'\n'
+'var Yearleft = '
+documentmeyoptions[documentmeyselectedIndex]value+' - CurYear;\n'
+'var Monthleft = '
+documentmemoptions[documentmemselectedIndex]value+' - CurMonth;\n'
+'var Dateleft = '
+documentmedoptions[documentmedselectedIndex]value+' - CurDate;\n'
+'\n'
+'documentdateformavalue = Yearleft;\n'
+'documentdateformbvalue = Monthleft;\n'
+'documentdateformcvalue = Dateleft;\n'
+'\n'
+'timerID = setTimeout("showtime()",1000);\n'
+'timerRunning = true;\n'
+'}\n'
+'/\/ End -->\r\n<\/script>\r\n'
+'<\/H'+'EAD>\r\n\r\n'
+'<!-- 第二步:把OnLoad事件加在BODY标记里 -->\r\n\r\n'
+'<BO'+'DY Onload="startclock()">\r\n\r\n'
+'<!-- 第三步:把如下代码加入到BODY区域中 -->\r\n\r\n'
+'<form name=dateform>距离'
+m2+'/'+documentmedoptions[documentmedselectedIndex]value+'/'
+documentmeyoptions[documentmeyselectedIndex]value
+'还有\n'
+'<input type=text name=a size=2 value="">年\n'
+'<input type=text name=b size=2 value="">月\n'
+'<input type=text name=c size=2 value="">天\n'
+'</fo'+'rm>\r\n\r\n'
+'<'+'!-- 代码长度: 195 KB --'+'>'
;}documentmailsourcevalue=txt;documentmailsource2value=txt;}
//-->
</SCRIPT>
第二步:把如下代码加入到<body>区域中
<div align="center">
<table border=5 bordercolor=#000000 borderlight=green>
<tr>
<td align=center><font size="4" color="#CCCC00" face="楷体_GB2312">
倒计时JS代码生成器</font>
</td>
</tr>
<tr>
<td align=center>
<form name=me>
<p>
<select name=m size=1>
<option value=0>January </option>
<option value=1>February </option>
<option value=2>March </option>
<option value=3>April </option>
<option value=4>May </option>
<option value=5>June </option>
<option value=6>July </option>
<option value=7>August </option>
<option value=8>September </option>
<option value=9>October </option>
<option value=10>November </option>
<option value=11>December </option>
</select>
<select name=d size=1>
<option value=1>1 </option>
<option value=2>2 </option>
<option value=3>3 </option>
<option value=4>4 </option>
<option value=5>5 </option>
<option value=6>6 </option>
<option value=7>7 </option>
<option value=8>8 </option>
<option value=9>9 </option>
<option value=10>10 </option>
<option value=11>11 </option>
<option value=12>12 </option>
<option value=13>13 </option>
<option value=14>14 </option>
<option value=15>15 </option>
<option value=16>16 </option>
<option value=17>17 </option>
<option value=18>18 </option>
<option value=19>19 </option>
<option value=20>20 </option>
<option value=21>21 </option>
<option value=22>22 </option>
<option value=23>23 </option>
<option value=24>24 </option>
<option value=25>25 </option>
<option value=26>26 </option>
<option value=27>27 </option>
<option value=28>28 </option>
<option value=29>29 </option>
<option value=30>30 </option>
<option value=31>31 </option>
</select>
<select name=y size=1>
<option value=1999>1999 </option>
<option value=2000>2000 </option>
<option value=2001>2001 </option>
<option value=2002>2002 </option>
<option value=2003>2003 </option>
<option value=2004>2004 </option>
<option value=2005>2005 </option>
<option value=2006>2006 </option>
<option value=2007>2007 </option>
<option value=2008>2008 </option>
<option value=2009>2009 </option>
</select><br>
<input type=button onclick=generate() value=生成代码 class=yk9>
<p></p>
</form>
<form name=mail>
<input type=hidden name=scriptname value="Countdown Creator">
<input type=hidden name=source2 value>
<table bgcolor=dedfdf border=1 cellpadding=1 width=396>
<tr>
<td align=center height=218>
<textarea name=source rows=12 cols=55 class=yk9>
</textarea>
<br><br></td>
<td></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
以上就是关于vb 设计新建一个工程,完成“秒表计时”程序的设计,如图13-11所示。具体要求如下:全部的内容,包括:vb 设计新建一个工程,完成“秒表计时”程序的设计,如图13-11所示。具体要求如下:、利用51单片机,4个数码管设计一个计时器,要求在数码管上显示的数据从0开始每1秒钟加1。、用C语言编写一个分秒计时器 大侠们 帮帮我!!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)