时钟程序设计

来源:百度知道 编辑:UC知道 时间:2024/06/27 18:15:34
时钟程序设计
设计内容:用汇编语言编写一个时钟程序,在微机屏幕上显示当前时间的时,分,秒。在程序启动后,可键入当前时间,回车键按下后,开始计时,微机屏幕上显示当前时间****年**月**日**时**分**秒。
设计要求:编程,画出程序流程图,程序调试,
设计过程:

2. 2查资料了解有关PC机系统时间的BIOS调用和DOS功能调用的使用方法
3. 编写程序
4. 程序调试
5. 写设计报告
设计报告内容要求:
1.设计题目及设计要求
2. 设计原理说明
3.流程图,源程序
4.实验结果说明

#include<graphics.h>
#include<math.h>
#include<dos.h>
#define PI 3.1415926

//屏幕中心的坐标(640X480模式下)
#define mid_x 320
#define mid_y 240

int main()
{ int graphdriver=DETECT,graphmode;
int end_x,end_y;
struct time curtime;
float th_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);