3个回答
展开全部
我这里有个刚刚写好的,不过是用c写的你看看行不?还有闹钟.
/*2009年3月1号数字时钟*/
#include<reg51.h>
sbit P0_7=P0^7;
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
sbit P1_4=P1^4;
sbit P1_5=P1^5;
sbit P1_6=P1^6;
sbit P1_7=P1^7;
sbit P2_7=P2^7;
unsigned char p=9,q=5,m=9,n=5,h=3,w=2,s2=0,s3=0,s4=0;//时钟初值
unsigned char m1=0,n1=0,h1=0,w1=0,q1=0,p1=0; //闹钟初值
unsigned char j=0,j1=0,j2=0,s=0,s1=0,k=10;
unsigned char temp=0,temp1=0,temp2=1;
unsigned char show[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0xbf,0xff};//数码显示0~9
void display();
void display1();
void display2();
void key();
unsigned char i=0;
void delay(unsigned int k)//延时子程序
{
unsigned int i,j;
for(j=0;j<k;j++)
for(i=0;i<10;i++);
}
void main() //main主函数
{
TMOD=0X01;
TH0=0Xff;
TL0=0Xff;
EA=1;ET0=1;
ET1=0;TR1=1;
TR0=1;P0_7=0;
while(1)
{
while(temp==0)
{
display2();key();
}
while(temp==1)
{
display1();key();
}
while(temp2==0)
{
display();key();
}
}
}
void time()interrupt 1 using 1//中断子程序
{
j++;
if(j==10)
{
j=0;j1++;
if(j1==5)
{k=11;j2++;j1=0;
if(j2==2)
{
j2=0,k=10;
p++;
if(p==10)
{
p=0;
q++;
if(q==6)
{
q=0;
m++;
if(m==10)
{
m=0;
n++;
if(n==6)
{
n=0;
h++;
if((w<=2)&&(h==10))
{
h=0;
w++;
}
}
}
}
}
}
}}
if((w==2)&&(h==4))
{
h=0,w=0;
}
if((w==w1)&&(h==h1)&&(m==m1)&&(n==n1)&&(p==p1)&&(q==q1))
{
P0_7=1;
}
}
void time1()interrupt 3 using 3//秒表
{
s1++;
if(s1==10)
{
s1=0;s2++;
if(s2==10)
{
s2=0;s3++;
if(s3==10)
{
s4++;s3=0;
}
}
if(s4==10)
{
s1=0;s2=0;s3=0;s4=0;
}
}
}
void display1() //闹钟显示程序
{
P3=0x01;
P2=show[p1];
delay(1);
P3=0x02;
P2=show[q1];
delay(1);
P3=0x04;
P2=show[k];
delay(1);
P3=0x08;
P2=show[m1];
delay(1);
P3=0x10;
P2=show[n1];
delay(1);
P3=0x20;
P2=show[k];
delay(1);
P3=0x40;
P2=show[h1];
delay(1);
P3=0x80;
P2=show[w1];
delay(1);
}
void display2() //时钟显示程序
{
P3=0x01;
P2=show[p];
delay(1);
P3=0x02;
P2=show[q];
delay(1);
P3=0x04;
P2=show[k];
delay(1);
P3=0x08;
P2=show[m];
delay(1);
P3=0x10;
P2=show[n];
delay(1);
P3=0x20;
P2=show[k];
delay(1);
P3=0x40;
P2=show[h];
delay(1);
P3=0x80;
P2=show[w];
delay(1);
}
void display() //秒表显示程序
{
P3=0x01;
P2=show[s1];
delay(1);
P3=0x02;
P2=show[s2];
delay(1);
P3=0x04;
P2=show[s3];
delay(1);
P3=0x08;
P2=show[s4];
delay(1);
}
void key() //按键
{
if(P1_0==0)
{
delay(5000);temp=1;
}
if((P1_0==0)&&(temp=1))
{
delay(5000);temp=0;
}
if((P1_1==0)&&(temp==0))
{
delay(10000);
m++;
if(m==10)
{
m=0;n++;
if(n==6)
{
n=0;
h++;
if((w<=2)&&(h==10))
{
h=0;
w++;
}
}
}
}
if((w==2)&&(h==4))
{
h=0,w=0;
}
if((P1_2==0)&&(temp==0))
{
delay(10000);
h++;
if((w<=2)&&(h==10))
{
h=0;
w++;
if((w==2)&&(h==4))
{
h=0,w=0;
}
}
}
if((P1_1==0)&&(temp==1))
{
delay(10000);
m1++;
if(m1==10)
{
m1=0;n1++;
if(n1==6)
{
n1=0;
h1++;
if((w1<=2)&&(h1==10))
{
h1=0;
w1++;
}
}
}
}
if((w1==2)&&(h1==4))
{
h1=0,w1=0;
}
if((P1_2==0)&&(temp==1))
{
delay(10000);
h1++;
if((w1<=2)&&(h1==10))
{
h1=0;
w1++;
if((w1==2)&&(h1==4))
{
h1=0,w1=0;
}
}
}
if((P1_3==0)&&(temp1==1))
{
delay(10000);
s1=0;s2=0;s3=0;s4=0;temp1=0;
}
if((P1_3==0)&&(temp1==0))
{
delay(10000);
ET1=1;temp1=1;
}
if(P1_4==0)
{
ET1=0;
temp1=1;
}
if((P1_5==0)&&(temp==0))
{
delay(200);
p=0;q=0;m=0;n=0;h=0;w=0;
}
if((P1_5==0)&&(temp==1))
{
delay(200);
m1=0;n1=0;h1=0;w1=0;
}
if(P1_6==0)
{
delay(200);
P0_7=0;
}
if((P1_7==0)&&(temp2==1))
{
delay(200);
temp2=0;temp=2;
}
if((P1_7==0)&&(temp2==0))
{
delay(200);
temp2=1;
temp=0;
}
}
/*2009年3月1号数字时钟*/
#include<reg51.h>
sbit P0_7=P0^7;
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
sbit P1_4=P1^4;
sbit P1_5=P1^5;
sbit P1_6=P1^6;
sbit P1_7=P1^7;
sbit P2_7=P2^7;
unsigned char p=9,q=5,m=9,n=5,h=3,w=2,s2=0,s3=0,s4=0;//时钟初值
unsigned char m1=0,n1=0,h1=0,w1=0,q1=0,p1=0; //闹钟初值
unsigned char j=0,j1=0,j2=0,s=0,s1=0,k=10;
unsigned char temp=0,temp1=0,temp2=1;
unsigned char show[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0xbf,0xff};//数码显示0~9
void display();
void display1();
void display2();
void key();
unsigned char i=0;
void delay(unsigned int k)//延时子程序
{
unsigned int i,j;
for(j=0;j<k;j++)
for(i=0;i<10;i++);
}
void main() //main主函数
{
TMOD=0X01;
TH0=0Xff;
TL0=0Xff;
EA=1;ET0=1;
ET1=0;TR1=1;
TR0=1;P0_7=0;
while(1)
{
while(temp==0)
{
display2();key();
}
while(temp==1)
{
display1();key();
}
while(temp2==0)
{
display();key();
}
}
}
void time()interrupt 1 using 1//中断子程序
{
j++;
if(j==10)
{
j=0;j1++;
if(j1==5)
{k=11;j2++;j1=0;
if(j2==2)
{
j2=0,k=10;
p++;
if(p==10)
{
p=0;
q++;
if(q==6)
{
q=0;
m++;
if(m==10)
{
m=0;
n++;
if(n==6)
{
n=0;
h++;
if((w<=2)&&(h==10))
{
h=0;
w++;
}
}
}
}
}
}
}}
if((w==2)&&(h==4))
{
h=0,w=0;
}
if((w==w1)&&(h==h1)&&(m==m1)&&(n==n1)&&(p==p1)&&(q==q1))
{
P0_7=1;
}
}
void time1()interrupt 3 using 3//秒表
{
s1++;
if(s1==10)
{
s1=0;s2++;
if(s2==10)
{
s2=0;s3++;
if(s3==10)
{
s4++;s3=0;
}
}
if(s4==10)
{
s1=0;s2=0;s3=0;s4=0;
}
}
}
void display1() //闹钟显示程序
{
P3=0x01;
P2=show[p1];
delay(1);
P3=0x02;
P2=show[q1];
delay(1);
P3=0x04;
P2=show[k];
delay(1);
P3=0x08;
P2=show[m1];
delay(1);
P3=0x10;
P2=show[n1];
delay(1);
P3=0x20;
P2=show[k];
delay(1);
P3=0x40;
P2=show[h1];
delay(1);
P3=0x80;
P2=show[w1];
delay(1);
}
void display2() //时钟显示程序
{
P3=0x01;
P2=show[p];
delay(1);
P3=0x02;
P2=show[q];
delay(1);
P3=0x04;
P2=show[k];
delay(1);
P3=0x08;
P2=show[m];
delay(1);
P3=0x10;
P2=show[n];
delay(1);
P3=0x20;
P2=show[k];
delay(1);
P3=0x40;
P2=show[h];
delay(1);
P3=0x80;
P2=show[w];
delay(1);
}
void display() //秒表显示程序
{
P3=0x01;
P2=show[s1];
delay(1);
P3=0x02;
P2=show[s2];
delay(1);
P3=0x04;
P2=show[s3];
delay(1);
P3=0x08;
P2=show[s4];
delay(1);
}
void key() //按键
{
if(P1_0==0)
{
delay(5000);temp=1;
}
if((P1_0==0)&&(temp=1))
{
delay(5000);temp=0;
}
if((P1_1==0)&&(temp==0))
{
delay(10000);
m++;
if(m==10)
{
m=0;n++;
if(n==6)
{
n=0;
h++;
if((w<=2)&&(h==10))
{
h=0;
w++;
}
}
}
}
if((w==2)&&(h==4))
{
h=0,w=0;
}
if((P1_2==0)&&(temp==0))
{
delay(10000);
h++;
if((w<=2)&&(h==10))
{
h=0;
w++;
if((w==2)&&(h==4))
{
h=0,w=0;
}
}
}
if((P1_1==0)&&(temp==1))
{
delay(10000);
m1++;
if(m1==10)
{
m1=0;n1++;
if(n1==6)
{
n1=0;
h1++;
if((w1<=2)&&(h1==10))
{
h1=0;
w1++;
}
}
}
}
if((w1==2)&&(h1==4))
{
h1=0,w1=0;
}
if((P1_2==0)&&(temp==1))
{
delay(10000);
h1++;
if((w1<=2)&&(h1==10))
{
h1=0;
w1++;
if((w1==2)&&(h1==4))
{
h1=0,w1=0;
}
}
}
if((P1_3==0)&&(temp1==1))
{
delay(10000);
s1=0;s2=0;s3=0;s4=0;temp1=0;
}
if((P1_3==0)&&(temp1==0))
{
delay(10000);
ET1=1;temp1=1;
}
if(P1_4==0)
{
ET1=0;
temp1=1;
}
if((P1_5==0)&&(temp==0))
{
delay(200);
p=0;q=0;m=0;n=0;h=0;w=0;
}
if((P1_5==0)&&(temp==1))
{
delay(200);
m1=0;n1=0;h1=0;w1=0;
}
if(P1_6==0)
{
delay(200);
P0_7=0;
}
if((P1_7==0)&&(temp2==1))
{
delay(200);
temp2=0;temp=2;
}
if((P1_7==0)&&(temp2==0))
{
delay(200);
temp2=1;
temp=0;
}
}
展开全部
#include <windows.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
class SystemTime
{
private:
int year,month,day,hour,minute,second;
public:
const int T;
SystemTime(int t);
~SystemTime();
void GetSystemTime();
void move();
void show();
};
void main()
{
SystemTime t(1); //参数为更新时间的间隔,可以随意,1s、2s、3s...
t.GetSystemTime(); //程序开始运行时获得系统时间
while(1) //设置无限循环模拟系统时间!
{
t.show(); //显示时间
t.move(); //更新时间
Sleep(t.T * 1000); //暂停t.T s
system("cls");
}
}
SystemTime::SystemTime(int t):T(t){}
SystemTime::~SystemTime(){}
void SystemTime::GetSystemTime()
{
time_t ltime;
time(<ime);
char *str= ctime(<ime);
string stryear(str+20,str+24);
string strmonth(str+4,str+7);
if (strmonth == "Jan")strmonth="1";
if (strmonth == "Feb")strmonth="2";
if (strmonth == "Mar")strmonth="3";
if (strmonth == "Apr")strmonth="4";
if (strmonth == "May")strmonth="5";
if (strmonth == "Jun")strmonth="6";
if (strmonth == "Jul")strmonth="7";
if (strmonth == "Aug")strmonth="8";
if (strmonth == "Sep")strmonth="9";
if (strmonth == "Oct")strmonth="10";
if (strmonth == "Nov")strmonth="11";
if (strmonth == "Dec")strmonth="12";
string strday(str+8,str+10);
string strhour(str+11,str+13);
string strminute(str+14,str+16);
string strsecond(str+17,str+19);
year = atoi(stryear.c_str());
month = atoi(strmonth.c_str());
day = atoi(strday.c_str());
hour = atoi(strhour.c_str());
minute = atoi(strminute.c_str());
second = atoi(strsecond.c_str());
}
void SystemTime::move()
{
second += T ; //T s更新一次
if (second>59) { second =0; minute +=1; }
if (minute>59) { minute =0; hour +=1; }
if (hour>23) { hour =0; }
//年月的的更新这里就暂略了...
}
void SystemTime::show()
{
cout<<year<<"."<<month<<"."<<day<<" ";
if (hour<10)
{
cout<<0;
}
cout<<hour<<":"; //时
if (minute<10)
{
cout<<0;
}
cout<<minute<<":"; //分
if (second<10)
{
cout<<0;
}
cout<<second<<endl; //秒
}
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
class SystemTime
{
private:
int year,month,day,hour,minute,second;
public:
const int T;
SystemTime(int t);
~SystemTime();
void GetSystemTime();
void move();
void show();
};
void main()
{
SystemTime t(1); //参数为更新时间的间隔,可以随意,1s、2s、3s...
t.GetSystemTime(); //程序开始运行时获得系统时间
while(1) //设置无限循环模拟系统时间!
{
t.show(); //显示时间
t.move(); //更新时间
Sleep(t.T * 1000); //暂停t.T s
system("cls");
}
}
SystemTime::SystemTime(int t):T(t){}
SystemTime::~SystemTime(){}
void SystemTime::GetSystemTime()
{
time_t ltime;
time(<ime);
char *str= ctime(<ime);
string stryear(str+20,str+24);
string strmonth(str+4,str+7);
if (strmonth == "Jan")strmonth="1";
if (strmonth == "Feb")strmonth="2";
if (strmonth == "Mar")strmonth="3";
if (strmonth == "Apr")strmonth="4";
if (strmonth == "May")strmonth="5";
if (strmonth == "Jun")strmonth="6";
if (strmonth == "Jul")strmonth="7";
if (strmonth == "Aug")strmonth="8";
if (strmonth == "Sep")strmonth="9";
if (strmonth == "Oct")strmonth="10";
if (strmonth == "Nov")strmonth="11";
if (strmonth == "Dec")strmonth="12";
string strday(str+8,str+10);
string strhour(str+11,str+13);
string strminute(str+14,str+16);
string strsecond(str+17,str+19);
year = atoi(stryear.c_str());
month = atoi(strmonth.c_str());
day = atoi(strday.c_str());
hour = atoi(strhour.c_str());
minute = atoi(strminute.c_str());
second = atoi(strsecond.c_str());
}
void SystemTime::move()
{
second += T ; //T s更新一次
if (second>59) { second =0; minute +=1; }
if (minute>59) { minute =0; hour +=1; }
if (hour>23) { hour =0; }
//年月的的更新这里就暂略了...
}
void SystemTime::show()
{
cout<<year<<"."<<month<<"."<<day<<" ";
if (hour<10)
{
cout<<0;
}
cout<<hour<<":"; //时
if (minute<10)
{
cout<<0;
}
cout<<minute<<":"; //分
if (second<10)
{
cout<<0;
}
cout<<second<<endl; //秒
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这么些分就能够求到这么多东西?呵呵
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询