c程序时钟代码谁有

如题所述

#include <reg52.h>
#define uint unsigned int
sbit P3_0=P3^0;
sbit K1=P3^2;
sbit K2=P3^3;
sbit K3=P3^4;
sbit K4=P3^5;
uint count,min,hour,i,j=0;
uint code tab1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uint code tab2[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
uint code tab3[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,
0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0x00,0xff,0x00,0xff,
0xfe,0xfb,0xef,0xbf,0xfd,0xf7,0xdf,0x7f,0x7e,0x3c,0x18,0x00,0x81,
0xc3,0xe7,0xff,0xe7,0xdb,0xbd,0x7e,0xff,0x7e,0xbd,0xdb,0xe7,0xff,
0x00,0xff,0x00,0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x80,
0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0x00,0xff,0x00,0xff,0xfe,0xfc,
0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,
0xff,0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0xff,0x00,0xff,0x00,0xff};

void adjust(void)
{
if(!K3) //分调整
{
for(i=0;i<20000;i++);min++;
if(min==60)min=0;
}
if(!K4) //时调整
{
for(i=0;i<20000;i++);hour++;
if(hour==24)hour=0;
}
}

void display(void)
{
P0=tab1[min%10];P2=0xf7;for(i=0;i<5;i++);P2=0xff;//分个位显示
P0=tab1[min/10];P2=0xfb;for(i=0;i<5;i++);P2=0xff;//分十位显示
P0=tab2[hour%10];P2=0xfd;for(i=0;i<5;i++);P2=0xff;//时个位显示
P0=tab1[hour/10];P2=0xfe;for(i=0;i<5;i++);P2=0xff;//时十位显示
}

void ring(void)
{
if(hour/10==0&&(hour%10>=8&&hour%10<=9))P3_0=0;//早上7:00到晚上7:00自动整点报时,其中13、14点不报时
if(hour/10==1&&(hour%10>=0&&hour%10<=2))P3_0=0;
if(hour/10==1&&(hour%10>=5&&hour%10<=9))P3_0=0;
}

void update(void)
{
if(count==1200)
{
count=0;min++;
if(min==60)
{
min=0;hour++;
if(hour==24)hour=0;
ring();
}
}
}

void main(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
EA=1;
ET0=1;
while(1)
{
if(count==120)P3_0=1;//报时六秒后自动关闭蜂鸣器
adjust();
display();
}
}

void timer0_rupt(void) interrupt 1 // 定时器0中断
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count%10==0)
{
P1=tab3[j];
j++;
if(j>99)j=0;
}
update();
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-15

#include<graphics.h>      // 就是需要引用这个图形库

#include<conio.h>

#include<time.h>

#include<math.h>

#include<windows.h>

#define pi 3.141592653

double temp1,temp2,temp3;

char show[3];


void change(char *a,int d)//将数值d转换为对应的字符串并存放于a中,例如将50转换为“50%”

{

a[0]=d/10+48;

a[1]=d%10+48;

a[2]='\0';

}


void showtime(int hour,int minute,int second)  //将时间以数字的形式显示

{

setcolor(0);

setfillstyle(0,2);

bar(200,520,400,580);  //画矩形并以黑色填充,以清除上次显示的时间,显示新的时间

setcolor(0x00A800);

change(show,hour);

outtextxy(220,530,show);

change(show,minute);

outtextxy(280,530,show);

change(show,second);

outtextxy(340,530,show);

outtextxy(260,530,":");

outtextxy(320,530,":");

}

void clock(int hour,int minute,int second)   //将表盘及数字时间显示

{

temp1=6*second*pi/180;  //temp1存放秒针位置与12点钟的夹角

temp2=6*minute+2*(second/20); //temp2存放分针位置与12点钟的夹角

temp2=temp2*pi/180;

temp3=30*hour+3*(minute/6);  //temp3存放时针位置与12点钟的夹角

temp3=temp3*pi/180;

setcolor(0x0000A8);  //设置当前颜色为红色,以备画指针

line(300-20*sin(temp1),300+20*cos(temp1),300+160*sin(temp1),300-160*cos(temp1)); //画秒针

line(300,300,300+130*sin(temp2),300-130*cos(temp2)); //画分针

line(300,300,300+80*sin(temp3),300-80*cos(temp3)); //画时针

second==0?Beep(1000,200):0;  //整分钟报时

temp1-=6*pi/180;

temp2-=2*pi/180;

temp3-=3*pi/180;  //temp1,temp2,temp3各回到之前的数值,即秒针,分针,时针均退到上个状态

setcolor(0);  //当前要色设定为黑色,以把上次时间秒针,分针,时针留下的痕迹覆盖掉

line(300-20*sin(temp1),300+20*cos(temp1),300+160*sin(temp1),300-160*cos(temp1)); //覆盖秒针

second%20==0?line(300,300,300+130*sin(temp2),300-130*cos(temp2)):0; //覆盖分针

minute%6==0?line(300,300,300+80*sin(temp3),300-80*cos(temp3)):0; //覆盖时针

setfillstyle(0x0000A8,2); //红色为填充色

fillellipse(300,300,8,8);

showtime(hour,minute,second);  //调用showtime函数,将时间以数字的形式显示

}

void main()

{

int i;

char *digital[13]={"12","1","2","3","4","5","6","7","8","9","10","11","袁 氏 钟 表"};

initgraph(800,600);   //初始化

setcolor(0x00A800);  //设定当前颜色为绿色

setlinestyle(PS_SOLID,NULL,5); //画线宽度为5

circle(300,300,200);  //以(300,300)为圆心,200为半径画圆

time_t t,t_front;  

tm *tp;

for(i=0;i<12;i++)

{

line(300+185*sin(30*i*pi/180),300-185*cos(30*i*pi/180),300+190*sin(30*i*pi/180),300-190*cos(30*i*pi/180));

outtextxy(294+170*sin(30*i*pi/180),294-170*cos(30*i*pi/180),digital[i]);

}  //画1,2,3,...12等12个刻度

setlinestyle(PS_SOLID,NULL,2);

for(i=0;i<60;i++) //画12个大刻度之间的小刻度

line(300+185*sin(6*i*pi/180),300-185*cos(6*i*pi/180),300+190*sin(6*i*pi/180),300-190*cos(6*i*pi/180));

setfont(25,16,"宋体");  //设置字体格式为高25像素,宽16像素,宋体

outtextxy(215,50,digital[12]);

for(;;)

{

t=time(NULL);  //获取机器当前时间

if(t!=t_front)

{

tp=localtime(&t);

clock(tp->tm_hour,tp->tm_min,tp->tm_sec);  //调用clock函数,将表盘及数字时间显示

}

t_front=t;

}

}


相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网