时钟的编程
‘壹’ 单片机电子时钟编程
设计两个按键,一个选定时钟数字一个改变时钟数字,选择一个中断定时扫描按键,通过读入键值给DS1307初始化校时,再选择一个中断定时扫描DS1307可以读出时,分,秒的BCD码,将BCD码译码后点亮数码管,数码管的显示可以通过对比当前时间与上一次扫描读出时间确定时,分,秒哪位发生了改变,分别选通对应的数码管,刷新显示。
‘贰’ C++编程,设计一个时钟类:
#include<iostream>
usingnamespacestd;
//具有三个成员函数
classCmytime
{
public:
Cmytime(inth=0,intm=0,ints=0){}
voidShow()
{
cout<<h<<":"<<m<<":"<<s<<endl;
}
//1、对于非法赋值不给予执行,三个参数合法范围是:0<=h<=23,0<=m,s<=60。如何参数非法,本次Set函数不改变原有值。
//2、赋值成功,返回1,否则返回0。
intSet(inth,intm,ints)
{
if(0<=h&&h<=23&&0<=m&&s<=60)
{
this->h=h;
this->m=m;
this->s=s;
return1;
}
else
{
return0;
}
}
//实现在原时间的基础上加1秒的时间值。
voidAddOneSecond()
{
this->s+=1;
}
protected:
inth;
intm;
ints;
};
intmain()
{
//关注我头像哦.惊喜
Cmytimetime;
intjude=time.Set(23,25,38);
if(jude==1)
time.Show();
else
cout<<0<<endl;
time.AddOneSecond();
time.Show();
system("pause");
return0;
}
‘叁’ 西门子PLC时钟指令晚上19时到早晨06怎么样编程
如图所示,READ_RTC是时钟读取指令,读取完后,VB0为年,VB1为月,VB2为日,VB3为时,VB4为分,VB5为秒,VB7为星期。因此用VB3做比较指令,与19和6进行比较就可以了。
望采纳。。。。。。
‘肆’ 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);
}
‘伍’ 求助PLC时钟控制编程
看你是什么PLC,一般PLC都是有系统时钟功能的,下面是三菱的:
(1)时钟数据读出指令
时钟数据读出TRD (Time Read)的功能指令编号为FNC166,[D.]可取T、C和D,只有16位运算,占5个程序步。该指令用来读出内置的实时钟的数据,并存放在[D·]开始的7个字内,实时钟的时间数据存放在特殊辅助寄存器D8013~D8019内,D8018~D8013中分别存放年、月、日、时、分和秒,星期存放在D8019中。
(2)时钟数据写入指令
时钟数据写入指令TWR(Time Write)的功能指令编号为FNC167,[S·]可取T、C和D,只有16位运算,占5个程序步。该指令用来将时间设定值写入内置的实时钟,写入的数据预先放在[S·]开始的7个单元内,执行该指令时,内置的实时钟立即变更,改为使用新的时间。图4-93中的D10~D15分别存放年、月、日、时、分和秒,D16存放星期。
应用:
X3为ON时,D8018~D8013中存放的6个时钟数据分别读入D0~D5,D8019中的星期值读入D6。
X4为ON时,D10~D15中的预置值分别写入D8018~D8013,D16中的数值写入D8019。
‘陆’ c++编程定义一时钟类Clock
#include <iostream> using namespace std; //时间类 class Time{ private: int hour; int minute; int second; public: //设置时间 void set(int h,int m,int s){ hour = h; minute = m; second = s; } //时间走一秒,时分秒的变化情况 void next(){ if(second<59) second++; else if(minute<59){ second=0; minute++;} else if(hour<23){ minute=0; hour++;} else hour=0; } //得到时间 int get(){ return hour*10000+minute*100+second; } }; //时钟类 class Clock{ private: Time now; Time ring_time; public: //对表,设定初始时间 void adjust_now(int h,int m,int s){ now.set(h,m,s); cout<<"现在的时间是:"<<h<<"时"<<m<<"分"<<s<<"秒"<<endl; } //设定闹铃时间 void adjust_ring(int h,int m,int s){ ring_time.set(h,m,s); cout<<"闹铃时间是:"<<h<<"时"<<m<<"分"<<s<<"秒"<<endl; } //时间过一秒 void tick(){ long int old=time(0); while(time(0)==old) ; now.next(); } //显示当前时间 void showtime(){ cout<<now.get()<<endl; } //时钟开始走时,等到了闹铃时间,开始响 void run(){ do{ tick(); showtime(); if(now.get()>=ring_time.get()) cout<<'\a'; }while(1); } }; int main(){ Clock c; c.adjust_now(18,35,40); //起始时间 c.adjust_ring(18,35,45); //闹铃时间 c.run(); }
‘柒’ c++编程 制作一个时钟,可以显示小时 分 秒
#include<iostream>
#include<vector>
classCtime{
private:
std::vector<int>_val;
conststaticint_is60=60;
std::vector<int>&calc_clock(constint&v,constintopt=0){
intres=v+opt;
_val.push_back(res%_is60);
_val.push_back((res/_is60)%_is60);
_val.push_back((res-_val[1]*_is60-_val[0])/(_is60*_is60));
return_val;
}
public:
Ctime(constint&v,constintopt=0){
calc_clock(v,opt);
}
friendstd::ostream&operator<<(std::ostream&out,constCtime&clock){
out<<clock._val[2]<<":";
out<<clock._val[1]<<":";
out<<clock._val[0];
returnout;
}
};
intmain(){
Ctimet1(3661);
Ctimet2(3661,-8);
Ctimet3(3661,8);
//
std::cout<<t1<<std::endl;
std::cout<<t2<<std::endl;
std::cout<<t3<<std::endl;
}
‘捌’ c++编程 制作一个时钟,可以显示小时 分 秒
类自己写吧,很累,不想写了
boolsetTime1(inth,intm,ints)//倒计时
{
if((h<0)||(m<0||m>=60)||(s<0||s>=60))
{
printf("Timeseterror! ");
returnfalse;
}
while(h>0||m>0||s>0)
{
printf("%02d:%02d:%02d",h,m,s);
--s;
if(s<0)
{
s=59;
--m;
if(m<0)
{
m=59;
--h;
}
}
Sleep(200);
system("cls");
}
returntrue;
}
boolsetTime2(inth,intm,ints)//正计时
{
inthour=0,min=0,sec=0;
if((h<0)||(m<0||m>=60)||(s<0||s>=60))
{
printf("Timeseterror! ");
returnfalse;
}
while(h!=hour||m!=min||s!=sec)
{
printf("%02d:%02d:%02d",hour,min,sec);
++sec;
if(sec==60)
{
sec=0;
++min;
if(min==60)
{
min=0;
++hour;
}
}
Sleep(1000);
system("cls");
}
returntrue;
}
‘玖’ C++时钟编程
#include<iostream.h> #include<stdlib.h> class timer{ int seconds; public: timer() { seconds=0; } timer(char *t) { seconds=atoi(t); } timer(int t) { seconds=t; } timer(int min,int sec) { seconds=min*60+sec; } gettime() { return seconds; } }; main() { timer a,b(10),c("20"),d(1,10); cout<<"seconds1="<<a.gettime()<<endl; cout<<"seconds2="<<b.gettime()<<endl; cout<<"seconds3="<<c.gettime()<<endl; cout<<"seconds4="<<d.gettime()<<endl; return 0; }
满意请采纳
‘拾’ 易语言时钟怎么编程,求大神指教
1.首先从工具栏中拖入这个空间到窗口那