简单时钟c语言
Ⅰ 谁能告诉我51单片机简单的led数码管时钟程序 24小时制的(c语言版的)
#include "reg52.h"
#define uint unsigned int
#define uchar unsigned char
uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar shi,fen,miao;
uchar time;
void delay(uint x)
{
uint y;
for(;x>0;x--)
{
for(y=0;y<124;y++);
}
}
void display(uchar shi,uchar fen,uchar miao)
{
P2=0; //位码
P0=(tab[shi/10]); //段码
delay(2);
P2=1;
P0=(tab[shi%10]);
delay(2);
P2=2; //位码
P0=0x40; //段码
delay(2);
P2=3; //位码
P0=(tab[fen/10]); //段码
delay(2);
P2=4;
P0=(tab[fen%10]);
delay(2);
P2=5; //位码
P0=0x40; //段码
delay(2);
P2=6; //位码
P0=(tab[miao/10]); //段码
delay(2);
P2=7;
P0=(tab[miao%10]);
delay(2);
}
void main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(time==20)
{
time=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
shi=0;
}
}
}
display(shi,fen,miao);
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
time++;
}
/*还有什么不明白继续追加*/
Ⅱ 怎么用C语言编程数字时钟
1、以下例程实现时钟的实时显示基本要求: 1) 自行设计界面,模拟表盘式时钟。要求界面美观,清晰。2)数字同步显示时间信息。
2、例程:
#include<graphics.h>
#include<math.h>
#include<dos.h>
#definePI3.1415926
//屏幕中心的坐标(640X480模式下)
#definemid_x320
#definemid_y240
intmain()
{intgraphdriver=DETECT,graphmode;
intend_x,end_y;
structtimecurtime;
floatth_hour,th_min,th_sec;
initgraph(&graphdriver,&graphmode,"C:\TC2");//初始化VGA屏幕模式
setbkcolor(BLACK);//使用黑色的背景色
while(!kbhit(0))//若有键盘输入,则跳出,即是结束程序
{setcolor(GREEN);//把画笔设为绿色
circle(mid_x,mid_y,180);//钟的外圆
circle(mid_x,mid_y,150);//钟的内圆
circle(mid_x,mid_y,1);//画出钟的圆心
gettime(&curtime);//取得系统当前时间
th_sec=(float)curtime.ti_sec*0.1047197551;//把秒针的角度化为弧度,为以后绘制时方便,下同
th_min=(float)curtime.ti_min*0.1047197551+th_sec/60.0;//分针的弧度
th_hour=(float)curtime.ti_hour*0.5235987755+th_min/12.0;//时度的弧度,注意整时是12等分的,所时乘的是3.14/180*5
//计算出时针的尾的坐标(时针长70)
end_x=mid_x+70*sin(th_hour);
end_y=mid_y-70*cos(th_hour);
setcolor(RED);
line(mid_x,mid_y,end_x,end_y);//用红色线画出时针
//计算出分针坐标(分针长110)
end_x=mid_x+110*sin(th_min);
end_y=mid_y-110*cos(th_min);
setcolor(RED);
line(mid_x,mid_y,end_x,end_y);//用红色画出分针
end_x=mid_x+140*sin(th_sec);
end_y=mid_y-140*cos(th_sec);
setcolor(RED);
line(mid_x,mid_y,end_x,end_y);//同上,画出秒针,长为140
//画出钟盘上的刻度,刻度长20
line(140,240,160,240);//9点对应的大刻度
line(320,60,320,80);//12点对应的大刻度
line(500,240,480,240);//3点的刻度
line(320,420,320,400);//6点的刻度
line(410,395.7,400,378.4);//5点
line(475.7,330,458.4,320);//4点
line(475.7,150,458.4,160);//2点
line(410,84.3,400,101.6);//1点
line(230,84.3,240,101.6);//11点
line(164.3,150,181.6,160);//10点
line(164.3,330,181.6,320);//8点
line(230,395.7,240,378.4);//7点
sleep(BLUE);//这里应该是打错,停止一秒,应为sleep(1000)
cleardevice();//清除屏幕上的显示
}
closegraph();//关闭VGA屏幕,即返回文本方式
return0;
}
Ⅲ c语言简单数学时钟(结构体,指针),求大佬帮助
至今为止,在中国历史上有留下记载的四代计时器分别为:日晷、沙漏、机械钟、石英钟。在中国市场上石英钟最热销。
时钟一直以来都是国人钟爱的商品之一。新中国成立以来,国家投入大量资金发展钟表工业,使这一产业得以快速发展,此后,中国的改革开放以及经济全球化发展给中国钟表业带来了繁荣。经过几十年的发展,中国钟表业经历了进料组装-外观件制造-产品开发-创立品牌的发展过程,目前已形成配套齐全的钟表制造工业,除高端机芯外的所有零配件均可加工生产。
现状
从区域格局来看,全国已形成以广州、深圳为龙头的珠三角地区、福建、浙江、江苏、山东、天津等6大钟表主产区;从产量来看,我国已成为世界钟表生产大国,钟表产量稳居世界第一。监测数据显示,2011年,我国钟和表的产量分别达到1.59亿只和1.3亿只。
我国钟表行业发展虽然取得长足的进步,但国内钟表企业及其品牌在国际市场上的信誉度和影响力还微不足道,产量占比虽然已经达到80%以上,但是产值占比不到30%,依然没有话语权和定价权。统计数据显示,2010年从金融危机阴影中走出来的中国钟表行业实现了全面的恢复和增长,全年规模以上企业工业总产值同比增长17.12%,销售收入同比增长23.00%,均达到2008年以来的最高增速,同时利润总额也大幅增长了55.63%。此外,我国钟表出口形势也得到好转,全年共实现出口额30.49亿美元,同比增长24.27%。
Ⅳ 用C语言做数字时钟每走一秒响一次,求大神告诉源代码
“响一次”需要牵涉到图形编程中的音乐播放问题,需要自己下载图形编程相关库文件,具体实现请自己在TODO里添加播放音乐的代码
数字时钟的实现很简单,运用time.h相关函数即可
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
time_toldt=-1;
structtm*p;
boolPrintdate()
{
time_tt=time(NULL);
if(t!=oldt)
{
oldt=t;
p=localtime(&t);
system("cls");
printf("%d/%d/%d周",1900+p->tm_year,1+p->tm_mon,p->tm_mday,p->tm_hour,p->tm_min,p->tm_sec);
switch(p->tm_wday)
{
case1:printf("一");break;
case2:printf("二");break;
case3:printf("三");break;
case4:printf("四");break;
case5:printf("五");break;
case6:printf("六");break;
case7:printf("日");break;
}
printf("%d:%02d:%02d",p->tm_hour,p->tm_min,p->tm_sec);
return1;
}
return0;
}
main()
{
while(1)
if(Printdate())
{
/*************TODO*************/
/**Forexample:printf("a");**/
}
return0;
}
Ⅳ C语言时钟设计
#include<graphics.h> /* 引入graphic.h */ #include<math.h> /* 引入math.h */ #include<dos.h> /* 引入dos.h */ #define pi 3.1415926 /*定义pi=3.14159*/ #define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300; #define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240; #define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y) /*定义……*/ void init() /*初始化程序*/ {int i,l,x1,x2,y1,y2; /*定义……*/ setbkcolor(1); /*设置颜色*/ circle(300,240,200); /*作园*/ circle(300,240,205); circle(300,240,5); for(i=0;i<60;i++) /*循环(算时间)*/ {if(i%5==0) l=15; else l=5; x1=200*cos(i*6*pi/180)+300; y1=200*sin(i*6*pi/180)+240; x2=(200-l)*cos(i*6*pi/180)+300; y2=(200-l)*sin(i*6*pi/180)+240; line(x1,y1,x2,y2); } } main() { int x,y; int gd=VGA,gm=2; unsigned char h,m,s; /*定义*/ struct time t[1]; initgraph(&gd,&gm,"d:\\tc"); init(); setwritemode(1); gettime(t); h=t[0].ti_hour; m=t[0].ti_min; s=t[0].ti_sec; /*定义时分秒*/ setcolor(7); /*设置颜色*/ d(150,h,30); setcolor(14); d(170,m,6); setcolor(4); d(190,s,6); while(!kbhit()) /*获取键盘相应*/ {while(t[0].ti_sec==s) gettime(t); /*C语言中得到时间的函数*/ sound(400); /*计算时间……*/ delay(70); sound(200); delay(30); nosound(); setcolor(4); d(190,s,6); s=t[0].ti_sec; d(190,s,6); if (t[0].ti_min!=m) { setcolor(14); d(170,m,6); m=t[0].ti_min; d(170,m,6); } if (t[0].ti_hour!=h) { setcolor(7); d(150,h,30); h=t[0].ti_hour; d(150,h,30); sound(1000); delay(240); nosound(); delay(140); sound(2000); delay(240); nosound(); } } getch(); /*设置空格后退出*/ closegraph(); }
Ⅵ 求,简单一点的C语言时钟程序谢谢谢谢。555555555555
TC版本的时钟程序:
#include<graphics.h>
#include<math.h>
#include<dos.h>
#define pi 3.1415926
#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2) 300;
#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2) 240;
#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y)
void init()
{int i,l,x1,x2,y1,y2;
setbkcolor(1);
circle(300,240,200);
circle(300,240,205);
circle(300,240,5);
for(i=0;i<60;i )
{if(i%5==0) l=15;
else l=5;
x1=200*cos(i*6*pi/180) 300;
y1=200*sin(i*6*pi/180) 240;
x2=(200-l)*cos(i*6*pi/180) 300;
y2=(200-l)*sin(i*6*pi/180) 240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y;
int gd=VGA,gm=2;
unsigned char h,m,s;
suct time t[1];
initgraph(&gd,&gm,"d:\\tc");
init();
setwritemode(1);
gettime(t);
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_sec;
setcolor(7);
d(150,h,30);
setcolor(14);
d(170,m,6);
setcolor(4);
d(190,s,6);
while(!kbhit())
{while(t[0].ti_sec==s)
gettime(t);
sound(400);
delay(70);
sound(200);
delay(30);
nosound();
setcolor(4);
d(190,s,6);
s=t[0].ti_sec;
d(190,s,6);
if (t[0].ti_min!=m)
{
setcolor(14);
d(170,m,6);
m=t[0].ti_min;
d(170,m,6);
}
if (t[0].ti_hour!=h)
{ setcolor(7);
d(150,h,30);
h=t[0].ti_hour;
d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
}
getch();
closegraph();
}
Ⅶ 时钟的C语言程序代码,要没错误,能运行的。最好重要的语句后面要有注释,急求~~高手求解~~~
给你一个指示吧 1.绘图函数 2.时间从主板上面取 程序如下(运行环境是在TC下面的)/***********简单的时钟程序,界面不是很美观,您可以根据自己的爱好加以修改,如给表盘加上刻度,将指针改为其它外形等*/
#include<graphics.h>
#include<math.h>
#include<dos.h>
#define PI 3.1415926
#define x0 320 /*定义钟表中心坐标*/
#define y0 240
void DrawClock(int x,int y,int color) /*画表盘*/
{ int r=150; /*表盘的半径*/
float th;
setcolor(color);
circle(x,y,r);
circle(x,y,2);
}
void DrawHand(int x,int y,float th,int l,int color)
{
int x1,y1;
x1=x+l*sin(th);
y1=y-l*cos(th);
setcolor(color);
line(x,y,x1,y1);
}
void main()
{int gdriver=DETECT,gmode;<br> struct time curtime;<br> float th_hour,th_min,th_sec;<br> initgraph(&gdriver,&gmode,"");<br><br> setbkcolor(0);<br><br> while(! kbhit())<br> {<br> DrawClock(x0,y0,14);<br> gettime(&curtime); /*得到当前系统时间*/<br><br> gotoxy(35,20); /*定位输出位置*/<br> if((float)curtime.ti_hour<=12) /*午前的处理*/<br> {printf("AM ");<br> if((float)curtime.ti_hour<10) printf("0"); /*十点之前在小时数前加零*/<br> printf("%.0f:",(float)curtime.ti_hour);<br> }
else /*午后的处理*/
{printf("PM ");<br> if((float)curtime.ti_hour-12<10) printf("0");<br> printf("%.0f:",(float)curtime.ti_hour-12);<br> }
if((float)curtime.ti_min<10) printf("0");
printf("%.0f:",(float)curtime.ti_min);
if((float)curtime.ti_sec<10) printf("0");
printf("%.0f",(float)curtime.ti_sec);
/*以下三行计算表针转动角度,以竖直向上为起点,顺时针为正*/
th_sec=(float)curtime.ti_sec*0.1047197551; /*2π/60=0.1047197551*/
th_min=(float)curtime.ti_min*0.1047197551+th_sec/60.0;
th_hour=(float)curtime.ti_hour*0.523598775+th_min/12.0; /* 2π/12=0.5235987755 */
DrawHand(x0,y0,th_hour,70,2); /*画时针*/
DrawHand(x0,y0,th_min,110,3); /*分针*/
DrawHand(x0,y0,th_sec,140,12); /*秒针*/
sleep(1); /*延时一秒后刷新*/
cleardevice();
}
closegraph();
}
Ⅷ c语言时钟代码
#include<graphics.h> /* 引入graphic.h */
#include<math.h> /* 引入math.h */
#include<dos.h> /* 引入dos.h */
#define pi 3.1415926 /*定义pi=3.14159*/
#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300;
#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240;
#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y) /*定义……*/
void init() /*初始化程序*/
{int i,l,x1,x2,y1,y2; /*定义……*/
setbkcolor(1); /*设置颜色*/
circle(300,240,200); /*作园*/
circle(300,240,205);
circle(300,240,5);
for(i=0;i<60;i++) /*循环(算时间)*/
{if(i%5==0) l=15;
else l=5;
x1=200*cos(i*6*pi/180)+300;
y1=200*sin(i*6*pi/180)+240;
x2=(200-l)*cos(i*6*pi/180)+300;
y2=(200-l)*sin(i*6*pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y;
int gd=VGA,gm=2;
unsigned char h,m,s; /*定义*/
struct time t[1];
initgraph(&gd,&gm,"d:\\tc");
init();
setwritemode(1);
gettime(t);
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_sec; /*定义时分秒*/
setcolor(7); /*设置颜色*/
d(150,h,30);
setcolor(14);
d(170,m,6);
setcolor(4);
d(190,s,6);
while(!kbhit()) /*获取键盘相应*/
{while(t[0].ti_sec==s)
gettime(t); /*C语言中得到时间的函数*/
sound(400); /*计算时间……*/
delay(70);
sound(200);
delay(30);
nosound();
setcolor(4);
d(190,s,6);
s=t[0].ti_sec;
d(190,s,6);
if (t[0].ti_min!=m)
{
setcolor(14);
d(170,m,6);
m=t[0].ti_min;
d(170,m,6);
}
if (t[0].ti_hour!=h)
{ setcolor(7);
d(150,h,30);
h=t[0].ti_hour;
d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
}
getch(); /*设置空格后退出*/
closegraph();
}
具体的。。就是套用用几个函数算时间。。
不要对这种很长的东西害怕,其实大部分都是在画这个钟~
加油哦~
Ⅸ 单片机C语言该怎么编写时钟程序
这个是简单的数码管时钟显示如果有需要,我写过比较完善的1602显示时钟.显示控制年月日等等.#include<reg51.h>
sbit Begin=P2^0;
sbit Hour=P2^1;
sbit Mus=P2^2;
sbit End=P2^3;
unsigned char code Tab[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};
unsigned char code num[]={ 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char Time[]={0,0,16,0,0,16,0,0};
unsigned char a;
unsigned int x,m,th;
void init()
{
TMOD=0x01;
TH0=(65535/50000)/256;
TL0=(65535/50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void delay(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
unsigned char keyboard()
{
if(Begin==0){
delay(5);
if(Begin==0)
return 1;
}
if(Hour==0){
delay(30);
if(Hour==0)
return 2;
}
if(Mus==0)
return 3;
if(End==0)
return 4;
}
void display()
{
unsigned char i; for(i=0;i<8;i++)
{
P3=num[i];
P0=Tab[Time[i]];
delay(5);
}
}
void main()
{
unsigned char Key;
init();
Key=keyboard();
if(Key==1)
{
while(1){
Key=keyboard();
display();
if(Key==2)
x+=3600;
if(Key==3)
x+=1;
if(Key==4)
return;
}
}}
void holes() interrupt 1 using 2
{
TH0=(65535/50000)/256;
TL0=(65535/50000)%256;
a++;
if(a>=20)
{
x++;
m=x;
th=m/3600; //设置小时
Time[0]=th/10;
Time[1]=th%10;
m=m%3600; Time[2]=16; th=m/60; //设置分钟
Time[3]=th/10;
Time[4]=th%10;
m=m%60; Time[5]=16; th=m; //设置秒
Time[6]=th/10;
Time[7]=th%10; a=0;
}
}
Ⅹ c语言怎么样编写一个时钟程序
c语言时钟程序代码如下:
#include<windows.h>
#include<math.h>
#define ID_TIMER 1//计时器ID
#define TWOPI (2*3.14159)
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow)
{
static TCHAR szAppName[]=TEXT("Clock");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=szAppName;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("This program requires Windows
T"),szAppName,MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szAppName,TEXT("Analog Clock"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
void Setsotropic(HDC hdc,int cxClient,int cyClient)
{
SetMapMode(hdc,MM_ISOTROPIC);
SetWindowExtEx(hdc,1000,1000,NULL);
SetViewportExtEx(hdc,cxClient/2,-cyClient/2,NULL);
SetViewportOrgEx(hdc,cxClient/2,cyClient/2,NULL);
}
void RotatePoint(POINT pt[],int iNum,int iAngle)
{
int i;
POINT ptTemp;
for(i=0;i<iNum;i++)
{
ptTemp.x=(int)(pt[i].x*cos(TWOPI*iAngle/360)+pt[i].y*sin(TWOPI*iAngle/360));
ptTemp.y=(int)(pt[i].y*cos(TWOPI*iAngle/360)+pt[i].x*sin(TWOPI*iAngle/360));
pt[i]=ptTemp;
}
}
void DrawClock(HDC hdc)
{
int iAngle;
POINT pt[3];
for(iAngle=0;iAngle<360;iAngle+=6)
{
pt[0].x=0;
pt[0].y=900;
RotatePoint(pt,1,iAngle);
pt[2].x=pt[2].y=iAngle%5?33:100;
pt[0].x-=pt[2].x/2;
pt[0].y-=pt[2].y/2;
pt[1].x=pt[0].x+pt[2].x;
pt[1].y=pt[0].y+pt[2].y;
SelectObject(hdc,GetStockObject(BLACK_BRUSH));
Ellipse(hdc,pt[0].x,pt[0].y,pt[1].x,pt[1].y );
}
}
void DrawHands(HDC hdc,SYSTEMTIME *pst,BOOL fChange)
{
static POINT pt[3][5]={0,-150,100,0,0,600,-100,0,0,-150, 0,-200,50,0,0,800,-50,0,0,-200, 0,0,0,0,0,0,0,0,0,800 };
int i,iAngle[3];
POINT ptTemp[3][5];
iAngle[0]=(pst->wHour*30)%360+pst->wMinute/2;
iAngle[1]=pst->wMinute*6;
iAngle[2]=pst->wSecond*6;
memcpy(ptTemp,pt,sizeof(pt));
for(i=fChange?0:2;i<3;i++)
{
RotatePoint(ptTemp[i],5,iAngle[i]);
Polyline(hdc,ptTemp[i],5);
}
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static int cxClient,cyClient;
static SYSTEMTIME stPrevious;
BOOL fChange;
HDC hdc;
PAINTSTRUCT ps;
SYSTEMTIME st;
switch(message)
{
case WM_CREATE:
SetTimer(hwnd,ID_TIMER,1000,NULL);
GetLocalTime(&st);
stPrevious=st;
return 0;
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
return 0;
case WM_TIMER:
GetLocalTime(&st);
fChange=st.wHour!=stPrevious.wHour||st.wMinute!=stPrevious.wMinute;
hdc=GetDC(hwnd);
Setsotropic(hdc,cxClient,cyClient);
SelectObject(hdc,GetStockObject(WHITE_PEN));
DrawHands(hdc,&stPrevious,fChange);
SelectObject(hdc,GetStockObject(BLACK_PEN));
DrawHands(hdc,&st,TRUE);
stPrevious=st;
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
Setsotropic(hdc,cxClient,cyClient);
DrawClock(hdc);
DrawHands(hdc,&stPrevious,TRUE);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
KillTimer(hwnd,ID_TIMER);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}