数字时钟完整版

合集下载

单片机课程设计数字时钟

单片机课程设计数字时钟

汇编程序SECOND EQU 30HMINITE EQU 31HHOUR EQU 32HHOURK BIT P0.0MINITEK BIT P0.1SECONDK BIT P0.2DISPBUF EQU 40HDISPBIT EQU 48HT2SCNTA EQU 49HT2SCNTB EQU 4AHTEMP EQU 4BHORG 00HLJMP STARTORG 0BHLJMP INT_T0START: MOV SECOND,#00HMOV MINITE,#00HMOV HOUR,#12MOV DISPBIT,#00HMOV T2SCNTA,#00HMOV T2SCNTB,#00HMOV TEMP,#0FEHLCALL DISPMOV TMOD,#01HMOV TH0,#(65536-2000) / 256MOV TL0,#(65536-2000) MOD 256SETB TR0SETB ET0SETB EAWT: JB SECONDK,NK1LCALL DELY10MSJB SECONDK,NK1MOV SECOND,#00HNS60: LCALL DISPJNB SECONDK,$NK1: JB MINITEK,NK2LCALL DELY10MSJB MINITEK,NK2INC MINITEMOV A,MINITECJNE A,#60,NM60 MOV MINITE,#00H NM60: LCALL DISP JNB MINITEK,$NK2: JB HOURK,NK3 LCALL DELY10MSJB HOURK,NK3INC HOURMOV A,HOURCJNE A,#24,NH24 MOV HOUR,#00HNH24: LCALL DISP JNB HOURK,$NK3: LJMP WT DELY10MS:MOV R6,#10D1: MOV R7,#248 DJNZ R7,$DJNZ R6,D1RETDISP:MOV A,#DISPBUF ADD A,#8DEC AMOV R1,AMOV A,HOURMOV B,#10DIV ABMOV @R1,ADEC R1MOV A,BMOV @R1,ADEC R1MOV B,#10DIV ABMOV @R1,ADEC R1MOV A,BMOV @R1,ADEC R1MOV A,#10MOV@R1,ADEC R1MOV A,SECONDMOV B,#10DIV ABMOV @R1,ADEC R1MOV A,BMOV @R1,ADEC R1RETINT_T0:MOV TH0,#(65536-2000) / 256MOV TL0,#(65536-2000) MOD 256MOV A,#DISPBUFADD A,DISPBITMOV R0,AMOV A,@R0MOV DPTR,#TABLEMOVC A,@A+DPTRMOV P1,AMOV A,DISPBITMOV DPTR,#TABMOVC A,@A+DPTRMOV P3,AINC DISPBITMOV A,DISPBITCJNE A,#08H,KNAMOV DISPBIT,#00HNEMOV T2SCNTB,#00HINC SECONDMOV A,SECONDCJNE A,#60,NEXTMOV SECOND,#00HINC MINITEMOV A,MINITECJNE A,#60,NEXTMOV MINITE,#00HINC HOURMOV A,HOURCJNE A,#24,NEXTMOV HOUR,#00HNEXT: LCALL DISPDONE: RETITABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,40HTAB: DB 0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,07FH ENDC 语言源程序#include <AT89X51.H>unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};unsigned char dispbitcode[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};unsigned char dispbuf[8]={0,0,16,0,0,16,0,0};unsigned char dispbitcnt;unsigned char second;unsigned char minite;unsigned char hour;unsigned int tcnt;unsigned char mstcnt;unsigned char i,j;void main(void){TMOD=0x02;TH0=0x06;TL0=0x06;TR0=1;ET0=1;EA=1;while(1){if(P0_0==0){for(i=5;i>0;i--)for(j=248;j>0;j--);if(P0_0==0){second++;if(second==60){second=0;}dispbuf[0]=second%10; dispbuf[1]=second/10; while(P0_0==0);}}if(P0_1==0){for(i=5;i>0;i--)for(j=248;j>0;j--);if(P0_1==0){minite++;if(minite==60){minite=0;}dispbuf[3]=minite%10; dispbuf[4]=minite/10; while(P0_1==0);}}if(P0_2==0){for(i=5;i>0;i--)for(j=248;j>0;j--);if(P0_2==0){hour++;if(hour==24){hour=0;}dispbuf[6]=hour%10; dispbuf[7]=hour/10; while(P0_2==0);}}}}void t0(void) interrupt 1 using 0 {mstcnt++;if(mstcnt==8){mstcnt=0;P1=dispcode[dispbuf[dispbitcnt]]; P3=dispbitcode[dispbitcnt]; dispbitcnt++;if(dispbitcnt==8){dispbitcnt=0;}}tcnt++;if(tcnt==4000){tcnt=0;second++;if(second==60){second=0;minite++;if(minite==60){minite=0;hour++;if(hour==24){hour=0;}}}dispbuf[0]=second%10; dispbuf[1]=second/10; dispbuf[3]=minite%10; dispbuf[4]=minite/10;dispbuf[6]=hour%10;dispbuf[7]=hour/10;原理图。

数字的时钟学习读取和设置时钟上的时间

数字的时钟学习读取和设置时钟上的时间

数字的时钟学习读取和设置时钟上的时间时钟是我们日常生活中必不可少的工具之一,而数字时钟更是被广泛应用于各种设备和场景中。

学习如何读取和设置数字时钟上的时间对我们来说是至关重要的。

本文将介绍如何准确地读取数字时钟上的时间,并提供一些常用的时间设置技巧和注意事项。

一、读取数字时钟上的时间要准确地读取数字时钟上的时间,我们首先需要了解时钟所表达的时间单位和表示方法。

通常,一个标准的数字时钟会显示小时和分钟这两个时间单位。

下面是一些常见的时钟时间表示方法:1. 24小时制:这种表示方法使用24小时来表示一天中的时间。

例如,上午9点会显示为09:00,下午3点则显示为15:00。

2. 12小时制:这种表示方法使用12小时来表示一天中的时间,同时还会显示上午(AM)和下午(PM)的标识。

例如,上午9点会显示为09:00 AM,下午3点则显示为03:00 PM。

根据时钟的显示模式,我们可以按照以下步骤来读取数字时钟上的时间:1. 查看小时数:首先,看一下时钟上显示的数字,找到表示小时的数字。

如果是24小时制,则直接读取数字即可;如果是12小时制,则同时注意显示的上午(AM)或下午(PM)标识。

2. 查看分钟数:接下来,查看时钟上显示的分钟数,通常以两位数的形式呈现。

例如,显示为09:15 或者15:30。

通过以上步骤,我们就能准确地读取数字时钟上的时间了。

二、设置数字时钟上的时间时钟的时间设置通常是只需要在特定的情况下进行,比如更换电池或变更时区等。

以下是一些常用的设置时钟时间的方法和技巧:1. 找到设置按钮:大多数数字时钟都有设置按钮,可以通过按下该按钮来进入时间设置模式。

有些时钟还配备了调整小时和分钟的额外按钮。

2. 进入设置模式:按下设置按钮,时钟显示屏上通常会出现闪烁的时间数字,表示已进入设置模式。

3. 调整小时数:根据具体的设置方式,通过按钮或旋转时间轮来调整小时数,直到显示的数字与想要设置的时间相符。

数字时钟知识讲解

数字时钟知识讲解

数字时钟知识讲解目录一、数字时钟概述 (2)1. 数字时钟定义与特点 (3)2. 数字时钟发展历史 (4)二、数字时钟基本原理 (5)1. 数字时钟计时原理 (6)1.1 时间计数方式 (7)1.2 计时准确度与频率 (8)2. 数字时钟电路构成 (9)2.1 振荡器电路 (10)2.2 分频器电路 (11)2.3 显示驱动电路 (12)三、数字时钟显示技术 (13)1. LED显示技术 (14)1.1 LED数码管显示原理 (15)1.2 LED时钟显示效果 (17)2. LCD显示技术 (18)2.1 LCD显示器原理 (19)2.2 LCD时钟显示效果 (20)四、数字时钟功能与应用领域介绍 (21)一、数字时钟概述数字时钟是一种现代化的时间显示设备,与传统的机械时钟相比,具有更高的准确性和精度。

数字时钟采用电子技术和数字化显示方式,能够精确地显示当前的小时、分钟、甚至秒数。

它们广泛应用于家庭、办公室、公共场所,甚至是个人手持设备中,已成为日常生活中不可或缺的一部分。

数字时钟的基本原理是依靠晶体振荡器来计时,通过电子线路驱动显示器显示时间。

与传统的机械时钟相比,数字时钟具有许多优势。

它们精度高,不受环境温度和机械振动的影响。

数字时钟易于阅读,特别是对于视力较弱的人群来说,数字显示比传统指针显示更为清晰易辨。

现代数字时钟还具备多种附加功能,如闹钟、定时器、日历等,为用户提供了极大的便利。

数字时钟的发展离不开电子技术的进步,随着科技的不断发展,数字时钟不仅在功能和应用领域得到了扩展,其设计和制造技术也不断提升。

数字时钟已不再是简单的计时工具,更是时尚和科技的代表。

它们在造型设计、显示色彩、界面控制等方面不断创新,为用户带来全新的视觉体验和使用感受。

数字时钟已经成为现代社会不可或缺的一部分,它们以其高精度、易用性和多功能性为人们提供了更加便捷和准确的时间服务。

1. 数字时钟定义与特点数字时钟是一种采用数字技术来显示时间的电子设备,与传统的模拟时钟相比,数字时钟具有许多优点和特点。

时钟完整版(带整点报时)

时钟完整版(带整点报时)

#include<Windows.h>#include<string.h>#include<mmsystem.h>#include<wingdi.h>#include"resource.h"#include<math.h>#include<commdlg.h>#pragma comment(lib,"WinLib.lib")#pragma comment(lib,"WINMM.LIB")//导入声音用void SetDlgMenuID(UINT nMainDlgID,UINT nCalendarDlgID,UINT nMenuID); void SetButtonID(UINT nCalendarID,UINT nExitID,UINT nBiaoPan1,UINT nBiaoPan2,UINT nBiaoPan3);INT_PTR ShowMainDlg();/**********************************************************API函数参考:GetLocalTime: 获得当前时间(公历:年、月、日、周)MoveToEx: 移动划线的起点LineTo: 绘制到某一点SetTextColor: 设置要绘制的文字颜色TextOut: 绘制文字SetBkMode: 设置背景显示模式wsprintf: 整数转换为字符串,宽字符,用Unicode码GetClientRect: 获取窗口大小GetDC: 获取内存设备SetTimer: 设置定时器FillRect: 填充矩形CreateSolidBrush: 创建刷子RGB: 设置RGB颜色CreateFont:创建一种有特殊性的字体结构体类型参考:SYSTEMTIME: 描述时间类型,包括年月日、时分秒、周**********************************************************/HINSTANCE g_hInst;//保存操作系统传递进来的"应用程序实例句柄"//Windows程序入口函数int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ){g_hInst = hInstance;SetDlgMenuID(IDD_DLG_CLOCK,IDD_DLG_CALENDAR,IDR_MENU);SetButtonID(ID_CALENDAR,ID_EXIT,ID_BIAO1,ID_BIAO2,ID_BIAO3);ShowMainDlg(IDD_DLG_CLOCK);}typedef struct _stDateTime{int nYear;int nMonth;int nDay;}stDateTime;//定义表格,存储年-2099年的农历信息:每年的大小月、闰月信息、春节所在的公历日期unsigned int LunarCalendarTable[199] ={0x04AE53,0x0A5748,0x5526BD,0x0D2650,0x0D9544,0x46AAB9,0x056A4D, 0x09AD42,0x24AEB6,0x04AE4A,/*1901-1910*/0x6A4DBE,0x0A4D52,0x0D2546,0x5D52BA,0x0B544E,0x0D6A43,0x296D37, 0x095B4B,0x749BC1,0x049754,/*1911-1920*/0x0A4B48,0x5B25BC,0x06A550,0x06D445,0x4ADAB8,0x02B64D,0x095742, 0x2497B7,0x04974A,0x664B3E,/*1921-1930*/0x0D4A51,0x0EA546,0x56D4BA,0x05AD4E,0x02B644,0x393738,0x092E4B, 0x7C96BF,0x0C9553,0x0D4A48,/*1931-1940*/0x6DA53B,0x0B554F,0x056A45,0x4AADB9,0x025D4D,0x092D42,0x2C95B6, 0x0A954A,0x7B4ABD,0x06CA51,/*1941-1950*/0x0B5546,0x555ABB,0x04DA4E,0x0A5B43,0x352BB8,0x052B4C,0x8A953F, 0x0E9552,0x06AA48,0x6AD53C,/*1951-1960*/0x0AB54F,0x04B645,0x4A5739,0x0A574D,0x052642,0x3E9335,0x0D9549, 0x75AABE,0x056A51,0x096D46,/*1961-1970*/0x54AEBB,0x04AD4F,0x0A4D43,0x4D26B7,0x0D254B,0x8D52BF,0x0B5452, 0x0B6A47,0x696D3C,0x095B50,/*1971-1980*/0x049B45,0x4A4BB9,0x0A4B4D,0xAB25C2,0x06A554,0x06D449,0x6ADA3D, 0x0AB651,0x093746,0x5497BB,/*1981-1990*/0x04974F,0x064B44,0x36A537,0x0EA54A,0x86B2BF,0x05AC53,0x0AB647, 0x5936BC,0x092E50,0x0C9645,/*1991-2000*/0x4D4AB8,0x0D4A4C,0x0DA541,0x25AAB6,0x056A49,0x7AADBD,0x025D52, 0x092D47,0x5C95BA,0x0A954E,/*2001-2010*/0x0B4A43,0x4B5537,0x0AD54A,0x955ABF,0x04BA53,0x0A5B48,0x652BBC, 0x052B50,0x0A9345,0x474AB9,/*2011-2020*/0x06AA4C,0x0AD541,0x24DAB6,0x04B64A,0x69573D,0x0A4E51,0x0D2646, 0x5E933A,0x0D534D,0x05AA43,/*2021-2030*/0x36B537,0x096D4B,0xB4AEBF,0x04AD53,0x0A4D48,0x6D25BC,0x0D254F, 0x0D5244,0x5DAA38,0x0B5A4C,/*2031-2040*/0x056D41,0x24ADB6,0x049B4A,0x7A4BBE,0x0A4B51,0x0AA546,0x5B52BA, 0x06D24E,0x0ADA42,0x355B37,/*2041-2050*/0x09374B,0x8497C1,0x049753,0x064B48,0x66A53C,0x0EA54F,0x06B244, 0x4AB638,0x0AAE4C,0x092E42,/*2051-2060*/0x3C9735,0x0C9649,0x7D4ABD,0x0D4A51,0x0DA545,0x55AABA,0x056A4E, 0x0A6D43,0x452EB7,0x052D4B,/*2061-2070*/0x8A95BF,0x0A9553,0x0B4A47,0x6B553B,0x0AD54F,0x055A45,0x4A5D38, 0x0A5B4C,0x052B42,0x3A93B6,/*2071-2080*/0x069349,0x7729BD,0x06AA51,0x0AD546,0x54DABA,0x04B64E,0x0A5743, 0x452738,0x0D264A,0x8E933E,/*2081-2090*/0x0D5252,0x0DAA47,0x66B53B,0x056D4F,0x04AE45,0x4A4EB9,0x0A4D4C, 0x0D1541,0x2D92B5 /*2091-2099*/};char* TianGanDizhi[60]={"甲子", "乙丑","丙寅","丁卯","戊辰","已巳","庚午","辛未","壬申","癸酉","甲戌","乙亥","丙子","丁丑","戊寅","已卯","庚辰","辛巳","壬午","癸未","甲申","乙酉","丙戌","丁亥","戊子","已丑","庚寅","辛卯","壬辰","癸巳","甲午","乙未","丙申","丁酉","戊戌","已亥","庚子","辛丑","壬寅","癸卯","甲辰","乙巳","丙午","丁未","戊申","已酉","庚戌","辛亥","壬子","癸丑","甲寅","乙卯","丙辰","丁巳","戊午","已未","庚申","辛酉","壬戌","癸亥"char *ChDayTable[] ={"*","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"};char *ChMonthTable[] = {"*","正","二","三","四","五","六","七","八","九","十","十一","腊"};//定义表格,存储每月日离元旦的天数(不考虑瑞年)unsigned int MonthAdd[12] ={0,31,59,90,120,151,181,212,243,273,304,334};//定义用户要显示的年、月、日unsigned int nCurrentYear=0; //button控制年unsigned int nCurrentMonth=0;//月unsigned int nCurrentDay=0; //日UINT LiteSongs = 0; //判断是否听歌UINT Total=0; //我自定义的变量,当月的总天数UINT PreTotal=0; //自定义的当月的前一月的总天数UINT BUTTON6=0;UINT BUTTON4=0;int k=0;int m=0;//TCHAR Hours[255];SYSTEMTIME BellTime;UINT Inthour=0;//判断某年是否为公历瑞年int IsLeapYear(WORD iYear) //学生需要修改此函数,已经修改{if(((iYear%4==0)&&!(iYear%100==0))||(iYear%400==0))return 1;elsereturn 0;}//公历日期转农历日期的函数void SunToLunar(const stDateTime* pSunDay,stDateTime* pLunarDay) {int i=0;int SunDiff=0;int SpringDiff=0;int nSpringYear=pSunDay->nYear;int nSpringMonth=1;int nSpringDay=0;//计算当前公历日离当年元旦的天数SunDiff = MonthAdd[pSunDay->nMonth-1] + pSunDay->nDay - 1;if(IsLeapYear(pSunDay->nYear) && (pSunDay->nMonth > 2) )//若是瑞年且大于月,天数再加SunDiff++;//计算春节所在公历日离元旦的天数:通过查表,计算当年的春节所在的公历日期,if(((LunarCalendarTable[pSunDay->nYear - 1901] & 0x60)>>5)==1)//若春节在公历月SpringDiff=(LunarCalendarTable[pSunDay->nYear-1901]&0x1F)-1;else//若春节在公历月SpringDiff=(LunarCalendarTable[pSunDay->nYear-1901]&0x1F)-1+31;//SunDiff和SpringDiff的差就是当前公历日离春节的天数if(SunDiff>=SpringDiff)//公历日在春节后{int x = SunDiff - SpringDiff;int bLunar = (LunarCalendarTable[nSpringYear - 1901] & 0xF00000)>>20;//闰月月份i=0;nSpringMonth=1;for(;;){int a = (LunarCalendarTable[pSunDay->nYear-1901] & (0x80000>>i));//计算大小月if(a==0)a=29;elsea=30;if(x<a)break;x =x - a;i++;nSpringMonth++;}nSpringDay =x+1;//如果有闰月if(nSpringMonth>bLunar && bLunar>0)nSpringMonth--;}else//公历日在春节前{int x = SpringDiff-SunDiff;int nShift=0;int bLunar = (LunarCalendarTable[nSpringYear - 1901] & 0xF00000)>>20;//闰月月份i=0;nSpringYear--;//需要上一年的农历信息nSpringMonth=12;//从最后一个月开始计算if (bLunar == 0)//如果没有润月nShift = 0x100;elsenShift = 0x80;for(;;){int a = (LunarCalendarTable[nSpringYear-1901] & (nShift<<i));//计算大小月if(a==0)a=29;elsea=30;if(x<a){x = a-x;break;}x =x - a;i++;nSpringMonth--;}nSpringDay =x+1;if(nSpringMonth<bLunar && bLunar>0)nSpringMonth++;}pLunarDay->nYear = nSpringYear;pLunarDay->nMonth= nSpringMonth;pLunarDay->nDay = nSpringDay;}//根据公历日期获得星期int GetDayOfWeek(const stDateTime* pSunDay){//根据泰勒公式//nWeek = [nYear1÷] - 2*nYear1 + nYear2 + [nYear2÷] + [26(nMonth+1)÷] + nDay - 1int nWeek=0;int nYear1=pSunDay->nYear/100;//年的前两位数字int nYear2=pSunDay->nYear%100;//年的后两位数字int nDay=pSunDay->nDay; //公立日int nMonth=pSunDay->nMonth;//公立月数,所求的月份如果是月或月,//则应视为上一年的月或月,//也就是公式中nMonth的取值范围是从到而不是从到if(nMonth==1 || nMonth==2){nMonth=12+nMonth;nYear1=(pSunDay->nYear-1)/100;//年的前两位数字nYear2=(pSunDay->nYear-1)%100;//年的后两位数字}nWeek = nYear1/4 - 2*nYear1 + nYear2 + nYear2/4 + (26*(nMonth+1))/10 + nDay - 1;if(nWeek < 0)nWeek = ((nWeek)%7+7);// 有问题吗?nWeek可能小于零,循环加elsenWeek = (nWeek)%7;return nWeek;}//根据公立年得到农历干支年char* GetGanZhi(int nYear){int i=(nYear-1984)%60;return TianGanDizhi[i];}//日历绘制函数,学生自己实现该函数void DrawCalendar(HDC hDC,int nWidth,int nHeight){//获得日历的背景色stDateTime SunDay,LunarDay; //存储当时年月日SYSTEMTIME DateTime; //系统时间RECT rc;HBRUSH hBrush;HFONT hFont;TCHAR RILI[255]; //日历的标题TCHAR GraTime[255]; //表格日期UINT xOrg=50; //x起始坐标UINT yOrg=50; //y起始坐标UINT xRight=nWidth-45; //X的右端不包括UINT yBottom = nHeight-30; //Y的底部UINT i=0,biaoGe=0; //日历表格用TCHAR *WeekDay[] = {"日","一","二","三","四","五","六"};TCHAR *ShuXiang[]= {"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"};UINT Week=0;//列数UINT Hang=0;//行数TCHAR Str[255];//农历和公历年月字符UINT week=0;UINT hangkuan=0,liekuan=0;UINT First=0;UINT xLeft=0;UINT yRigth=0;UINT ShengXiao=0;UINT BeiJing=0;HBITMAP hBkmap;//得到图片HDC hdc;//绘制日历的矩形背景(改变皮肤)hdc = CreateCompatibleDC(hDC);switch (nCurrentMonth%12){case 0:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/yiyue.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 1:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/eryue.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 2:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/sanyue.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE) ;break;case 3:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/siyue.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 4:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/wuyue.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 5:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/liuyue.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE) ;break;case 6:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/qi.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 7:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/ba.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 8:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/jiu.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 9:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/shi.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 10:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/shiyi.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 11:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/shier.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;}SelectObject(hdc,hBkmap);BitBlt(hDC,0,0,nWidth,nHeight,hdc,0,0,SRCCOPY);SetRect (&rc,xOrg+65,yOrg,xRight-65,yOrg+25);hBrush=CreateSolidBrush(RGB(230,0,150));FillRect(hDC,&rc,hBrush);SetRect (&rc,xOrg,yOrg,xOrg+65,yOrg+25);hBrush=CreateSolidBrush(RGB(0,255,255));FillRect(hDC,&rc,hBrush);SetRect (&rc,xRight-65,yOrg,xRight,yOrg+25);hBrush=CreateSolidBrush(RGB(0,255,255));FillRect(hDC,&rc,hBrush);//绘制星期背景色MoveToEx(hDC,xOrg,yOrg,NULL);LineTo(hDC,xRight,yOrg);MoveToEx(hDC,xOrg,yOrg,NULL);LineTo(hDC,xOrg,yBottom);MoveToEx(hDC,xRight,yOrg,NULL);LineTo(hDC,xRight,yBottom);MoveToEx(hDC,xOrg,yBottom,NULL);LineTo(hDC,xRight,yBottom);//星期标题框MoveToEx(hDC,xOrg,yOrg+25,NULL);LineTo(hDC,xRight,yOrg+25);//行biaoGe = yBottom-yOrg-25;//只是日历的高度biaoGe = biaoGe/6;//高度分为六块hangkuan=biaoGe;for(i=0;i<5;i++)//画五行{MoveToEx(hDC,xOrg,yOrg+25+biaoGe*(i+1),NULL);LineTo(hDC,xRight,yOrg+25+biaoGe*(i+1));}//列biaoGe = xRight-xOrg;//只是日历的宽度biaoGe = biaoGe/7;//要七列liekuan=biaoGe;for(i=0;i<6;i++)//画七列{MoveToEx(hDC,xOrg+biaoGe*(i+1),yOrg,NULL);LineTo(hDC,xOrg+biaoGe*(i+1),yBottom);}//绘制‘星期’标题框内的文字SetTextColor(hDC,RGB(255,0,0));TextOut(hDC,xOrg+20,yOrg+6,WeekDay[0],strlen(WeekDay[0]));//星期日的//绘制“属相”的文字SetTextColor(hDC,RGB(0,100,255));switch((nCurrentYear-4)%12)//jisuan{case 0:TextOut(hDC,xOrg-35,yOrg,ShuXiang[0],strlen(ShuXiang[0]));break;case 1:TextOut(hDC,xOrg-35,yOrg,ShuXiang[1],strlen(ShuXiang[1]));break;case 2:TextOut(hDC,xOrg-35,yOrg,ShuXiang[2],strlen(ShuXiang[2]));break;case 3:TextOut(hDC,xOrg-35,yOrg,ShuXiang[3],strlen(ShuXiang[3]));break;case 4:TextOut(hDC,xOrg-35,yOrg,ShuXiang[4],strlen(ShuXiang[4]));break;case 5:TextOut(hDC,xOrg-35,yOrg,ShuXiang[5],strlen(ShuXiang[5]));break;case 6:TextOut(hDC,xOrg-35,yOrg,ShuXiang[6],strlen(ShuXiang[6]));break;case 7:TextOut(hDC,xOrg-35,yOrg,ShuXiang[7],strlen(ShuXiang[7]));break;case 8:TextOut(hDC,xOrg-35,yOrg,ShuXiang[8],strlen(ShuXiang[8]));break;case 9:TextOut(hDC,xOrg-35,yOrg,ShuXiang[9],strlen(ShuXiang[9]));break;case 10:TextOut(hDC,xOrg-35,yOrg,ShuXiang[10],strlen(ShuXiang[10]));break;case 11:TextOut(hDC,xOrg-35,yOrg,ShuXiang[11],strlen(ShuXiang[11]));break;}SetTextColor(hDC,RGB(0,0,0));for(i=1;i<6;i++)//星期一到六{TextOut(hDC,xOrg+20+biaoGe*i,yOrg+6,WeekDay[i],strlen(WeekDay[i ]));}SetTextColor(hDC,RGB(255,0,0));TextOut(hDC,xOrg+20+biaoGe*6,yOrg+6,WeekDay[6],strlen(WeekDay[6 ]));//以下代码是公历显示if(nCurrentYear==0)//如果当前日期还没有被设定{GetLocalTime(&DateTime);nCurrentYear = DateTime.wYear;nCurrentMonth= DateTime.wMonth;nCurrentDay =DateTime.wDay;}SunDay.nYear = nCurrentYear;SunDay.nMonth = nCurrentMonth;SunDay.nDay = nCurrentDay;SunToLunar(&SunDay,&LunarDay);//得到农历TextOut(hDC,80,28,ChMonthTable[LunarDay.nMonth],strlen(ChMonthTable[LunarDay.nMonth]));//农历显示TextOut(hDC,110,28,"月",strlen("月"));SunDay.nDay = 1;wsprintf(GraTime,"%.4d年%.2d月%.2d日",nCurrentYear,nCurrentMonth,nCurrentDay);//现在时间TextOut(hDC,50,10,GraTime,strlen(GraTime));//标题的时间//十二生肖图片hdc = CreateCompatibleDC(hDC);switch((nCurrentYear-4)%12){case 0:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/0.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 1:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/1.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 2:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/2.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 3:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/3.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 4:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/4.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 5:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/5.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 6:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/6.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 7:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/7.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 8:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/8.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 9:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/9.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 10:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/10.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 11:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/11.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;}SelectObject(hdc,hBkmap);BitBlt(hDC,7,20,150,150,hdc,0,0,SRCCOPY);//该月的总天数if(SunDay.nMonth==12){//PreTotal=30;Total=31;elseTotal=MonthAdd[SunDay.nMonth]-MonthAdd[SunDay.nMonth-1];if(IsLeapYear(SunDay.nYear)&&SunDay.nMonth==2){Total++;}//前一月的总天数if(SunDay.nMonth==1)PreTotal=31;else if(SunDay.nMonth==3){PreTotal=28;if(IsLeapYear(SunDay.nYear))PreTotal++;}else if(SunDay.nMonth==12)PreTotal=30;elsePreTotal=MonthAdd[SunDay.nMonth-1]-MonthAdd[SunDay.nMonth-2];First=GetDayOfWeek(&SunDay); //该月的第一天是星期几for(i=1;i<=Total;i++){SunDay.nYear = nCurrentYear;SunDay.nMonth = nCurrentMonth;SunDay.nDay=i; //从一号开始week=GetDayOfWeek(&SunDay);//得到该月第i号是星期几 SunToLunar(&SunDay,&LunarDay);//得到农历Week=week%7; //从第Week列开始Hang=((First+i-1)-(First+i-1)%7)/7; //从第Hang行开始xLeft=xOrg+15+(Week)*liekuan;yRigth=yOrg+40+(Hang)*hangkuan;if(DateTime.wYear==SunDay.nYear&&DateTime.wMonth==SunDay.nMonth &&DateTime.wDay==i)//显示今天{SetRect (&rc,xOrg+(Week)*liekuan,yOrg+25+(Hang)*hangkuan,xOrg+(Week)*liekuan+liekuan,yOrg+25+(Hang)*hangkuan+hangkuan) ;hBrush=CreateSolidBrush(RGB(0,255,255));FillRect(hDC,&rc,hBrush);}if(nCurrentYear==SunDay.nYear&&nCurrentMonth==SunDay.nMonth&&nC urrentDay==i)//动态显示每一天{SetRect (&rc,xOrg+(Week)*liekuan,yOrg+25+(Hang)*hangkuan,xOrg+(Week)*liekuan+liekuan,yOrg+25+(Hang)*hangkuan+hangkuan) ;hBrush=CreateSolidBrush(RGB(255,255,0));FillRect(hDC,&rc,hBrush);}SetTextColor(hDC,RGB(0,0,255));//节日颜色if(SunDay.nMonth==1&&SunDay.nDay==1){TextOut(hDC,xLeft,yRigth,"元旦",strlen("元旦"));//显示公历}else if(SunDay.nMonth==2&&SunDay.nDay==14){TextOut(hDC,xLeft,yRigth,"情人节",strlen("情人节"));}else if(SunDay.nMonth==5&&SunDay.nDay==1){TextOut(hDC,xLeft,yRigth,"劳动节",strlen("劳动节"));else if(SunDay.nMonth==5&&SunDay.nDay==4){TextOut(hDC,xLeft,yRigth,"青年节",strlen("青年节"));}else if(SunDay.nMonth==9&&SunDay.nDay==10){TextOut(hDC,xLeft,yRigth,"教师节",strlen("教师节"));}else if(SunDay.nMonth==10&&SunDay.nDay==1){TextOut(hDC,xLeft,yRigth,"国庆节",strlen("国庆节"));}else if(SunDay.nMonth==11&&SunDay.nDay==11){TextOut(hDC,xLeft,yRigth,"光棍节",strlen("光棍节"));}else if(SunDay.nMonth==11&&SunDay.nDay==24){TextOut(hDC,xLeft,yRigth,"感恩节",strlen("感恩节"));}else if(SunDay.nMonth==12&&SunDay.nDay==25){TextOut(hDC,xLeft,yRigth,"圣诞节",strlen("圣诞节"));}else{wsprintf(Str,"%i",i);SetTextColor(hDC,RGB(0,0,255));TextOut(hDC,xLeft,yRigth,Str,strlen(Str));//显示公历}//显示农历SetTextColor(hDC,RGB(0,0,255));//节日颜色if(LunarDay.nMonth==1&&LunarDay.nDay==1){TextOut(hDC,xLeft,yRigth+15,"春节",strlen("春节"));//农历显示else if(LunarDay.nMonth==1&&LunarDay.nDay==15){TextOut(hDC,xLeft,yRigth+15,"元宵节",strlen("元宵节"));//农历显示}else if(LunarDay.nMonth==5&&LunarDay.nDay==5){TextOut(hDC,xLeft,yRigth+15,"端午节",strlen("端午节"));//农历显示}else if(LunarDay.nMonth==9&&LunarDay.nDay==15){TextOut(hDC,xLeft,yRigth+15,"中秋节",strlen("中秋节"));//农历显示}else if(LunarDay.nMonth==9&&LunarDay.nDay==9){TextOut(hDC,xLeft,yRigth+15,"重阳节",strlen("重阳节"));//农历显示}else{SetTextColor(hDC,RGB(255,255,0));if(LunarDay.nDay==1)//月初改为月名{TextOut(hDC,xLeft,yRigth+15,ChMonthTable[LunarDay.nMonth],strlen(ChMonthTable[LunarDay.nMonth]));TextOut(hDC,xLeft+20,yRigth+15,"月",strlen("月"));}elseTextOut(hDC,xLeft,yRigth+15,ChDayTable[LunarDay.nDay],strlen(ChDayTable[LunarDay.nDay]));//农历显示}}//forhFont=CreateFont(44,20,0,100,FW_NORMAL,TRUE,0,0,ANSI_CHARSET,OU T_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_MODERN, "华文新魏"); //字体输出格式SelectObject(hDC,hFont);SetTextColor(hDC,RGB(50,50,255));wsprintf(RILI,"My>>万年历>> ");TextOut(hDC,200,10,RILI,10);}//事件函数:点击日历界面上各个按钮后被调用,学员自己实现该函数//注意:该函数调用完后,系统自动调用DrawCalendar函数// 因此,可以理解为,该函数和DrawCalendar函数是联动的void CalendarButtonEvent(UINT nID,HWND hDlg) //学生需要修改此函数{TCHAR Hours[255];int temp1;switch (nID){case IDC_BTN_YEARUP://点击了"年↑"按钮nCurrentYear++;break;case IDC_BTN_YEARDOWN:nCurrentYear--;break;case IDC_BTN_MONTHUP:{nCurrentMonth++;if(nCurrentMonth>12){nCurrentYear+=1;nCurrentMonth=1;}}break;case IDC_BTN_MONTHDOWN:{if(nCurrentMonth==1){nCurrentYear--;nCurrentMonth=12;}elsenCurrentMonth--;}break;case IDC_BTN_TODAY://GetDlgItemText(hDlg,IDC_BELL,Hours,sizeof(Hours));//nCurrentYear = atoi(Hours);nCurrentYear=0;break;case IDC_BUTTON_Day1://动态显示显示每一天{nCurrentDay++;if(nCurrentDay>Total){nCurrentDay=1;nCurrentMonth++;if(nCurrentMonth>12){nCurrentYear+=1;nCurrentMonth=1;}}}break;case IDC_BUTTON_Day2://动态显示显示每一天{nCurrentDay--;if(nCurrentDay<=0)nCurrentDay=PreTotal;nCurrentMonth--;if(nCurrentMonth==0){nCurrentYear--;nCurrentMonth=12;}}}break;case IDC_PLAYSONG:k++;{switch ( k%3){case 0:mciSendString("stop ../image/sound/b.mp3","",0,NULL); mciSendString("play ../image/sound/a.mp3","",0,NULL);break;case 1:mciSendString("stop ../image/sound/a.mp3","",0,NULL); mciSendString("play ../image/sound/y.mp3","",0,NULL);break;case 2:mciSendString("stop ../image/sound/y.mp3","",0,NULL); mciSendString("play ../image/sound/b.mp3","",0,NULL);break;}}break;case IDC_BUTTON6:m++;{switch ( m%3){case 0:mciSendString("pause ../image/sound/a.mp3","",0,NULL);break;case 1:mciSendString("pause ../image/sound/y.mp3","",0,NULL);break;case 2:mciSendString("pause ../image/sound/b.mp3","",0,NULL);break;}}break;case IDC_BUTTON_BELL:GetDlgItemText(hDlg,IDC_EDIT_YEAR,Hours,sizeof(Hours));temp1 = atoi(Hours);nCurrentYear = temp1;nCurrentMonth = 1;break;}}//该函数每.5秒被调用一次,时钟界面上的文字绘制,学生自己实现该函数void DrawClockText(HDC hDC){ //TCHAR year[255];//获得本地年月日时间stDateTime DateTime;stDateTime DateTime1,DateTime2; //得到公历农历日期 TCHAR HTime[255]; //存储时分秒TCHAR YTime[255]; //存储年TCHAR MTime[255]; //存储月TCHAR DTime[255];TCHAR TGAN[255]; //获得天干地支SYSTEMTIME LocTime; //定义当地时间RECT rec;HBRUSH hBrush;HFONT hfon;GetClientRect(hDC,&rec) ; //得到背影区域SetRect (&rec,33,52,94,65) ; //设置这块区域hBrush = CreateSolidBrush( RGB(0,0,222)); //建立画刷颜色FillRect(hDC,&rec,hBrush);SetBkMode(hDC,TRANSPARENT); //设置背景涂画,以备下次调用//获取星期和时间(时分秒)SetTextColor(hDC,RGB(111,208,252)); //字体颜色GetLocalTime(&LocTime);wsprintf(HTime,"%.2d:%.2d:%.2d",LocTime.wHour,LocTime.wMinute,L ocTime.wSecond);SetTextColor(hDC,RGB(235,255,0));SetBkMode(hDC,3);TextOut(hDC,35,50,HTime,8) ;//获得星期GetLocalTime(&LocTime);if(LocTime.wHour==Inthour)mciSendString("play ../image/sound/12.mp3","",0,NULL);//整点报时if(LocTime.wSecond==0&&LocTime.wMinute==0){switch(LocTime.wHour){case 6:mciSendString("play ../image/sound/06.mp3","",0,NULL);break;case 7:mciSendString("play ../image/sound/07.mp3","",0,NULL);break;case 8:mciSendString("play ../image/sound/08.mp3","",0,NULL);break;case 9:mciSendString("play ../image/sound/09.mp3","",0,NULL);break;case 10:mciSendString("play ../image/sound/10.mp3","",0,NULL);break;case 11:mciSendString("play ../image/sound/11.mp3","",0,NULL);break;case 12:mciSendString("play ../image/sound/12.mp3","",0,NULL);break;case 13:mciSendString("play ../image/sound/13.mp3","",0,NULL);break;case 14:mciSendString("play ../image/sound/14.mp3","",0,NULL);break;case 15:mciSendString("play ../image/sound/15.mp3","",0,NULL);break;case 16:mciSendString("play ../image/sound/16.mp3","",0,NULL);break;}}DateTime.nYear = LocTime.wYear ;DateTime.nMonth = LocTime.wMonth ;DateTime.nDay = LocTime.wDay ;SetTextColor(hDC,RGB(255,255,0));//字体颜色switch(GetDayOfWeek(&DateTime)){case 1:TextOut(hDC,41,69,"星期一",6) ;break;case 2:TextOut(hDC,41,69,"星期二",6) ;break;case 3:TextOut(hDC,41,69,"星期三",6) ;break;case 4:TextOut(hDC,41,69,"星期四",6) ;break;case 5:TextOut(hDC,41,69,"星期五",6) ;break;case 6:TextOut(hDC,41,69,"星期六",6) ;break;case 7:TextOut(hDC,41,69,"星期日",6) ;break;default:break;}//得到天干GetLocalTime(&LocTime);wsprintf(TGAN,GetGanZhi(LocTime.wYear));SetTextColor(hDC,RGB(250,100,100)); //字体颜色TextOut(hDC,48,89,TGAN,4);//获得农历的年月日GetLocalTime(&LocTime);DateTime1.nYear = LocTime.wYear ;DateTime1.nMonth = LocTime.wMonth ;DateTime1.nDay = LocTime.wDay ;SetTextColor(hDC,RGB(255,255,0));SunToLunar(&DateTime1,&DateTime2);//调用农历函数TextOut(hDC,70,35,ChDayTable[DateTime2.nDay],4);if(DateTime2.nMonth<11){TextOut(hDC,31,35,ChMonthTable[DateTime2.nMonth],2);TextOut(hDC,52,35,"月",2);}else{TextOut(hDC,31,35,ChMonthTable[DateTime2.nMonth],4);TextOut(hDC,52,35,"月",2);}//获得年GetLocalTime(&LocTime);hfon=CreateFont(13,0,380,67,FW_NORMAL,FALSE,0,0,ANSI_CHARSET,OU T_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS, ("Arial")); //字体输出格式SelectObject(hDC,hfon);wsprintf(YTime,"%.4d",LocTime.wYear);SetTextColor(hDC,RGB(255,255,0)); //字体颜色TextOut(hDC,25,25,YTime,4);//得到月hfon=CreateFont(13,0,3400,67,FW_NORMAL,FALSE,0,0,ANSI_CHARSET,O UT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS, ("Arial")); //字体输出格式SelectObject(hDC,hfon);wsprintf(MTime,"%.2d",LocTime.wMonth);SetTextColor(hDC,RGB(255,255,0)); //字体颜色TextOut(hDC,68,8,MTime,2);//得到日。

电子时钟完整版 有实物图

电子时钟完整版 有实物图
3
3.6 校时电路……………………………………………………………….14 3.6.1 电路结构及工作原理……………………………………………14 3.6.2 电路仿真…………………………………………………………14 3.6.3 元器件的选择及参数确定………………………………………15
3.7 整点报时电路………………………………………………………….16 4 电路总体仿真………………………………………………………………16 5 电路安装、调试与测试……………………………………………………18
7
图 3.2 由仿真图可知,该电路可以得到 5V 的直流电源,因此可以做为整个系统的电源。
3.1.3 元件的选择
电网供给交流电压(220v 50HZ)经变压器降压后,得到符合电路需要的 交流电压,然后由整流桥经整流后变换成方向不变、大小随时间变化的脉动电流, 然后有滤波电容滤去其中的杂波,并且可以抵消线路的电感效应防止产生自激震 荡,但是这样的直流电压还会随电网和负载的变化而变化,因此在该电路中又使 用了稳压芯片(7805)可以得到比较理想的直流电压,输出端的滤波电容的作用 是用以滤除输出端的高频信号,改善电路的暂态效应。
这里我用 555 定时器构成一个多谐振荡器其产生的频率为 100Hz,然后 经过整形、分频获得 1Hz 的秒脉冲。电路原理图如图 3.3
8
图 3.3 3.2.2 电路仿真结果如下图 3.4
图 3.4 由仿真图可知,产生的波形符合我们的标准,周期大约为 1 秒,大致可以做为秒 脉冲信号。
3.2.3 元件的选择
电子技术综合训练
设计报告
题目:
多功能电子钟的设计
姓名: 学号: 班级: 同组成员: 指导教师: 日期:
杜鹏 10020106 控制工程基地一班 宋峰 杨新华 2012 年 12 月 31 日星期一

数电实验 数字钟

数电实验  数字钟

数字钟简介:这是一个以EPM7128SLC84-15为软件载体,数码管作显示器件,蜂鸣器作提示器件,拥有4个按键的电子钟。

它能够正常计时,支持12小时和24小时两种计时方式,同时允许用户手动调时和设置整点报时。

在正常计时状态下,用户可以选择12或24小时的计时方式,也可以设置或取消整点报时的功能(蜂鸣器作整点报时的提示设备)。

同时,数码管会有相应的显示来指示当前电子钟的设置。

当用户通过按键进入校时状态时,闪烁的一位数便是当前调节的数;用户可以通过按键选择要调的位,并对选择位的数字进行修改。

(具体按键的功能说明请查阅软件编写部分三、2 )该电子钟的软件部分用VHDL编写,编译环境采用的是MAX+plus II.主要分为分频、按键防抖动、模式控制、计时校时、显示输出五个模块。

(具体设计见软件编写部分四)由于时间有限、作者才疏,纰漏在所难免,敬请老师指正。

关键字:显示模块的刷新率:=显示模块的输入时钟频率/数码管的个数;防抖动模块的基准频率:按键操作会产生上升沿,只有当两个上升沿发生在不同的基准周期时才被看作是两次按键;正常计时的基准频率:1Hz时钟状态:即mode,分为正常计时(mode=0)和校时(mode=1)两个状态;12/24 hour:即tm,tm=1为12小时制;tm=0为24小时制;选择位:在校时操作时,用户操作的当前位,可以是时分秒的低位或高位,从硬件显示上看,就是在校时状态下,闪烁的那一位。

硬件支持部分软件设计部分一、设计要求设计并制作一台能显示时、分、秒的数字钟。

1、可手动校时,能分别进行时、分的校正;2、12小时(含上下午显示)、24小时计时制可手动选择;3、选做:整点报时。

4、选做:闹铃功能,当计时计到预定时间时,蜂鸣器发出闹铃信号,闹铃时间为1秒,可提前终止闹铃。

5、选做:自拟其它功能。

二、程序编写方案比较与选择方案一:将所有功能设计好,程序结构制定完备后,将代码写入一个或几个文件里。

数字时钟

数字时钟

数字时钟设计方案1.前言数字时钟是由计数器、时钟信号源、数码管等组成的,具有整点报时功能。

数字时钟是一种计时装置,它具有时、分、秒计时功能和显示计时功能。

数字时钟精度高、稳定性好,不需经常校对,便于携带。

再定时控制和时间程序控制等方面得到了广泛的应用2、设计方案该方案通过计数器和数码管来设计的,该方案的原理是:首先时钟脉冲源给“1/10秒”计时器一个频率为0.1Hz的连续时钟脉冲,“秒”计时器通过串联进位方式与“分”位、“时”位进行连接,计时器芯片采用74LS160,用数码管来进行显示。

首先时钟脉冲源给“1/10秒”一个脉冲信号,当“1/10秒”计时器的数位10时就给秒计数器产生一个进位,将这个进位输出作为“秒”计时器的脉冲输入端CP,当“秒”计时器的数为60时产生进位,作为“分”计数器的信号输入端CP,“分”计数器也是一样,“时”计数器产生进位后,利用与非门对其进行清零。

3、单元模块设计3.1“1/10秒”位设计该部分是采用10进制计数器,对“1/10秒”进行计数,通过数码管来进行显示,并用进位输出给“秒”计时器一个计数脉冲。

选取74LS160D芯片、与非门74LS00D、时钟脉冲源和数码管等。

将74LS160D芯片的输出端QA、QB、QC、QD从左到右依次和数码管的管脚相连接。

时钟脉冲源一端接地,另一端和74LS160D的信号输入端CP进行连接,给74LS00D的引脚控制端一个高电平,让74LS00D 输入端的两端分别接输出端QB、QD,将输出端与74LS160D的清零端连接,在计数到9时实现请零,74LS160D的输出端和“秒”计时器的CP端进行连接,将其作为秒”计时器计数脉冲信号。

3.2“秒”位设计该部分是采用60进制计数器,对“秒”进行计数,通过数码管来进行显示,并用进位输出给“分”计时器一个计数脉冲,同时接收“1/10秒“计时器计数脉冲选取2片74LS160D芯片U3、U4和两个数码管U1、U2和与非门74LS00D,让芯片U3的输出端QA、QB、QC、QD 和数码管U2的管脚依次进行连接,芯片U4和数码管U1连接方式与U3、U2连接方式相同。

AT89C2051做的数字电子时钟

AT89C2051做的数字电子时钟

AT89C2051做的数字钟采用AT89C2051的6位电子钟原理如下图所示,只要硬件连接无误,保证成功。

另外图中的SET按纽用于校准时间。

按住2秒以上进入校准时间状态及换档和退出,快速点触用于调节时间数值。

三极管采用9015即可。

数码管最好采用红色的共阳型LED数码管,亮度高些,因为是扫描的显示方式,所以各个数码管的abcdefg各脚采用了总线并联,改动510欧姆的电阻可以改变显示亮度。

电子钟原理图电子钟源程序;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; AT89C2051时钟程序;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 定时器T0、T1溢出周期为50MS,T0为秒计数用,T1为调整时闪烁用,; P3.7为调整按钮,P1口为字符输出口,采用共阳显示管。

; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 中断入口程序;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ORG 0000H ;程序执行开始地址LJMP START ;跳到标号START执行ORG 0003H ;外中断0中断程序入口RETI ;外中断0中断返回ORG 000BH ;定时器T0中断程序入口LJMP INTT0 ;跳至INTTO执行ORG 0013H ;外中断1中断程序入口RETI ;外中断1中断返回ORG 001BH ;定时器T1中断程序入口LJMP INTT1 ;跳至INTT1执行ORG 0023H ;串行中断程序入口地址RETI ;串行中断程序返回; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 主程序;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;START: MOV R0,#70H ;清70H-7AH共11个内存单元MOV R7,#0BH ;CLEARDISP: MOV @R0,#00H ;INC R0 ;DJNZ R7,CLEARDISP ;MOV 20H,#00H ;清20H(标志用)MOV 7AH,#0AH ;放入"熄灭符"数据MOV TMOD,#11H ;设T0、T1为16位定时器MOV TL0,#0B0H ;50MS定时初值(T0计时用)MOV TH0,#3CH ;50MS定时初值MOV TL1,#0B0H ;50MS定时初值(T1闪烁定时用)MOV TH1,#3CH ;50MS定时初值SETB EA ;总中断开放SETB ET0 ;允许T0中断SETB TR0 ;开启T0定时器MOV R4,#14H ;1秒定时用初值(50MS×20)START1: LCALL DISPLAY ;调用显示子程序JNB P3.7,SETMM1 ;P3.7口为0时转时间调整程序SJMP START1 ;P3.7口为1时跳回START1SETMM1: LJMP SETMM ;转到时间调整程序SETMM ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1秒计时程序;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;T0中断服务程序INTT0: PUSH ACC ;累加器入栈保护PUSH PSW ;状态字入栈保护CLR ET0 ;关T0中断允许CLR TR0 ;关闭定时器T0MOV A,#0B7H ;中断响应时间同步修正ADD A,TL0 ;低8位初值修正MOV TL0,A ;重装初值(低8位修正值)MOV A,#3CH ;高8位初值修正ADDC A,TH0 ;MOV TH0,A ;重装初值(高8位修正值)SETB TR0 ;开启定时器T0DJNZ R4, OUTT0 ;20次中断未到中断退出ADDSS: MOV R4,#14H ;20次中断到(1秒)重赋初值MOV R0,#71H ;指向秒计时单元(71H-72H)ACALL ADD1 ;调用加1程序(加1秒操作)MOV A,R3 ;秒数据放入A(R3为2位十进制数组合)CLR C ;清进位标志CJNE A,#60H,ADDMM ;ADDMM: JC OUTT0 ;小于60秒时中断退出ACALL CLR0 ;大于或等于60秒时对秒计时单元清0MOV R0,#77H ;指向分计时单元(76H-77H)ACALL ADD1 ;分计时单元加1分钟MOV A,R3 ;分数据放入ACLR C ;清进位标志CJNE A,#60H,ADDHH ;ADDHH: JC OUTT0 ;小于60分时中断退出ACALL CLR0 ;大于或等于60分时分计时单元清0MOV R0,#79H ;指向小时计时单元(78H-79H)ACALL ADD1 ;小时计时单元加1小时MOV A,R3 ;时数据放入ACLR C ;清进位标志CJNE A,#24H,HOUR ;HOUR: JC OUTT0 ;小于24小时中断退出ACALL CLR0 ;大于或等于24小时小时计时单元清0OUTT0: MOV 72H,76H ;中断退出时将分、时计时单元数据移MOV 73H,77H ;入对应显示单元MOV 74H,78H ;MOV 75H,79H ;POP PSW ;恢复状态字(出栈)POP ACC ;恢复累加器SETB ET0 ;开放T0中断RETI ;中断返回;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 闪动调时程序;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;T1中断服务程序,用作时间调整时调整单元闪烁指示INTT1: PUSH ACC ;中断现场保护PUSH PSW ;MOV TL1, #0B0H ;装定时器T1定时初值MOV TH1, #3CH ;DJNZ R2,INTT1OUT ;0.3秒未到退出中断(50MS中断6次)MOV R2,#06H ;重装0.3秒定时用初值CPL 02H ;0.3秒定时到对闪烁标志取反JB 02H,FLASH1 ;02H位为1时显示单元"熄灭"MOV 72H,76H ;02H位为0时正常显示MOV 73H,77H ;MOV 74H,78H ;MOV 75H,79H ;INTT1OUT: POP PSW ;恢复现场POP ACC ;RETI ;中断退出FLASH1: JB 01H,FLASH2 ;01H位为1时,转小时熄灭控制MOV 72H,7AH ;01H位为0时,"熄灭符"数据放入分MOV 73H,7AH ;显示单元(72H-73H),将不显示分数据MOV 74H,78H ;MOV 75H,79H ;AJMP INTT1OUT ;转中断退出FLASH2: MOV 72H,76H ;01H位为1时,"熄灭符"数据放入小时MOV 73H,77H ;显示单元(74H-75H),小时数据将不显示MOV 74H,7AH ;MOV 75H,7AH ;AJMP INTT1OUT ;转中断退出; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 加1子序;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ADD1: MOV A,@R0 ;取当前计时单元数据到A DEC R0 ;指向前一地址SWAP A ;A中数据高四位与低四位交换ORL A,@R0 ;前一地址中数据放入A中低四位ADD A,#01H ;A加1操作DA A ;十进制调整MOV R3,A ;移入R3寄存器ANL A,#0FH ;高四位变0MOV @R0,A ;放回前一地址单元MOV A,R3 ;取回R3中暂存数据INC R0 ;指向当前地址单元SWAP A ;A中数据高四位与低四位交换ANL A,#0FH ;高四位变0MOV @R0,A ;数据放入当削地址单元中RET ;子程序返回; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 清零程序;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;对计时单元复零用CLR0: CLR A ;清累加器MOV @R0,A ;清当前地址单元DEC R0 ;指向前一地址MOV @R0,A ;前一地址单元清0RET ;子程序返回; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 时钟调整程序;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;当调时按键按下时进入此程序SETMM: cLR ET0 ;关定时器T0中断CLR TR0 ;关闭定时器T0LCALL DL1S ;调用1秒延时程序JB P3.7,CLOSEDIS ;键按下时间小于1秒,关闭显示(省电)MOV R2,#06H ;进入调时状态,赋闪烁定时初值SETB ET1 ;允许T1中断SETB TR1 ;开启定时器T1SET2: JNB P3.7,SET1 ;P3.7口为0(键未释放),等待SETB 00H ;键释放,分调整闪烁标志置1SET4: JB P3.7,SET3 ;等待键按下LCALL DL05S ;有键按下,延时0.5秒JNB P3.7,SETHH ;按下时间大于0.5秒转调小时状态MOV R0,#77H ;按下时间小于0.5秒加1分钟操作LCALL ADD1 ;调用加1子程序MOV A,R3 ;取调整单元数据CLR C ;清进位标志CJNE A,#60H,HHH ;调整单元数据与60比较HHH: JC SET4 ;调整单元数据小于60转SET4循环LCALL CLR0 ;调整单元数据大于或等于60时清0CLR C ;清进位标志AJMP SET4 ;跳转到SET4循环CLOSEDIS: SETB ET0 ;省电(LED不显示)状态。

基于单片机C语言电子时钟完整版(闹钟,整点报时)

基于单片机C语言电子时钟完整版(闹钟,整点报时)

《单片机技术》课程设计说明书数字电子钟系、部:电气与信息工程学院学生姓名:指导教师:职称专业:班级:完成时间:2013-06-07摘要电子钟在生活中应用非常广泛,而一种简单方便的数字电子钟则更能受到人们的欢迎。

所以设计一个简易数字电子钟很有必要。

本电子钟采用ATMEL公司的AT89S52单片机为核心,使用12MHz 晶振与单片机AT89S52 相连接,通过软件编程的方法实现以24小时为一个周期,同时8位7段LED数码管(两个四位一体数码管)显示小时、分钟和秒的要求,并在计时过程中具有定时功能,当时间到达提前定好的时间进行蜂鸣报时。

该电子钟设有四个按键KEY1、KEY2、KEY3、KEY4和KEU5键,进行相应的操作就可实现校时、定时、复位功能。

具有时间显示、整点报时、校正等功能。

走时准确、显示直观、运行稳定等优点。

具有极高的推广应用价值。

关键词电子钟;AT89S52;硬件设计;软件设计ABSTRACTClock is widely used in life, and a simple digital clock is more welcomed by people. So to design a simple digital electronic clock is necessary.The system use a single chip AT89S52 of ATMEL’s as its core to control The crystal oscillator clock,using of E-12MHZ is connected with the microcontroller AT89S52, through the software programming method to achieve a 24-hour cycle, and eight 7-segment LED digital tube (two four in one digital tube) displays hours, minutes and seconds requirements, and in the time course of a timing function, when the time arrived ahead of scheduled time to buzz a good timekeeping. The clock has four buttons KEY1, KEY2, KEY3,KEY4 and KEY5 key, and make the appropriate action can be achieved when the school, timing, reset. With a time display, alarm clock settings, timer function, corrective action. Accurate travel time, display and intuitive, precision, stability, and so on. With a high application value.Key words Electronic clock;;AT89S52;Hardware Design;Software Design目录1设计课题任务、功能要求说明及方案介绍 (1)1.1设计课题任务 (1)1.2功能要求说明 (1)1.3设计总体方案介绍及原理说明 (1)2设计课题硬件系统的设计 (2)2.1设计课题硬件系统各模块功能简要介绍 (2)2.2设计课题电路原理图、PCB图、元器件布局图 (2)2.3设计课题元器件清单 (5)3设计课题软件系统的设计 (6)3.1设计课题使用单片机资源的情况 (6)3.2设计课题软件系统各模块功能简要介绍 (6)3.3设计课题软件系统程序流程框图 (6)3.4设计课题软件系统程序清单 (10)4设计结论、仿真结果、误差分析、教学建议 (21)4.1设计课题的设计结论及使用说明 (21)4.2设计课题的仿真结果 (21)4.3设计课题的误差分析 (22)4.4设计体会 (22)4.5教学建议 (22)结束语 (23)参考文献 (24)致谢 (25)附录 (26)1 设计课题任务、功能要求说明及方案介绍1.1 设计课题任务设计一个具有特定功能的电子钟。

VHDL数字时钟

VHDL数字时钟

一、功能要求:1、能够分别显示时、分、秒,以24小时循环设计;2、能够对小时、分钟进行调时;3、能够设置闹钟,使其能够在指定时间响;二、设计原理:该数字时钟有三个状态,分别是正常显示状态、调时状态和闹钟设置状态,每当来到一个z的上升沿时,状态改变一次;正常显示状态:对输入的频率clk1进行分频,产生一个与秒的频率相等的频率信号clk,用clk来控制秒的走时,秒的个位每到10往秒的十位进位,秒的十位每到6就往分的个位进位,分的个位十位进位和秒一样,时的个位每到10就往时的十位进位,时的十位每到2就为0;当时间为23:59:59时,全部清零,重新开始计时;调时状态:当处于调时状态时,可对时间进行调整,先选择对哪位进行调整,可分别对分和时的个位和十位进行调整,每当来到一个md2的上升沿时可选中其中一位,每来到一个md3的上升沿时对其进行加“1”操作并设置一个开关allow1,当allow1接通一次时可把设置的时间赋给正常显示的时间,否则不影响正常显示的时间;闹钟设置状态:当处于闹钟设置状态时,同样通过md2选择要调整的位,并通过md3对其进行加“1”操作,并设置一个闹钟开关allow2,接通时闹钟开启;数字显示:对6个显示器用一个频率进行循环扫描,利用人眼停留的效果使其达到同时显示的效果;三、变量说明:端口说明:clk1:输入频率md1:负责对时钟状态的切换,每接通一次,状态就切换一次md2:在调时状态和闹钟设置状态时,负责选定对那个位进行操作(时的个位和十位,分的个位和十位)md3:负责对所选中的位进行加“1”操作,每接通一次,就加“1”allow1:负责是否确定对时钟的设置,设置好时钟后,若allow1接通一次,时钟就被修改;若allow1没有接通,则所调整的时间对原来的时钟没有影响allow2:负责是否确定开启闹钟,当allow2处于接通状态时,时钟到了设置的时间闹钟会响,断开allow2闹钟关闭speak:负责闹钟的发声dout,sellout:负责板子上显示管的显示数字内部变量说明:sel:选择哪个位置显示数counter:对输入频率进行分频,得出秒的频率clkcounter1:对输入频率进行分频,得出闹钟发声的频率z:选择时钟的状态,“00”为正常显示状态,“01”为调整状态,“10”为闹钟设置状态k:选择要对哪位进行操作,“00”为分的个位,“01”为分的十位,“10”为时的个位,“11”为时的十位hou1,hou2,min1,min2,sec1,sec2:分别代表正常显示状态下的时的十位,个位;分的十位,个位;秒的十位,个位;hou1n,hou2n,min1n,min2n,:分别代表处于调时状态时的时和分的十位和个位;seth1,seth2,setm1,setm2:分别代表处于闹钟设置状态的时和分的十位和个位;h1,h2,m1,m2,s1,s2:分别代表最终显示在板子上的时、分、秒的十位和个位;四、源代码:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity zhong isport(clk1:in std_logic;md1:in std_logic;-----xuan ze zhuang taimd2:in std_logic;------xuan ze she zhi na ge wei zhimd3:in std_logic;------jia yiallow1:in std_logic;allow2:in std_logic;speak:out std_logic;-----nao zhongdout:out std_logic_vector(6 downto 0);-------shu chuselout:out std_logic_vector(5 downto 0));-----xuan ze xian shi end zhong;architecture one of zhong issignal sel:std_logic_vector(2 downto 0);signal hou1:std_logic_vector(3 downto 0);signal hou2:std_logic_vector(3 downto 0);signal min1:std_logic_vector(3 downto 0);signal min2:std_logic_vector(3 downto 0);signal hou1n:std_logic_vector(3 downto 0);signal hou2n:std_logic_vector(3 downto 0);signal min1n:std_logic_vector(3 downto 0);signal min2n:std_logic_vector(3 downto 0);signal seth1:std_logic_vector(3 downto 0);signal seth2:std_logic_vector(3 downto 0);signal setm1:std_logic_vector(3 downto 0);signal setm2:std_logic_vector(3 downto 0);signal sec1:std_logic_vector(3 downto 0);signal sec2:std_logic_vector(3 downto 0);signal h1:std_logic_vector(3 downto 0);signal h2:std_logic_vector(3 downto 0);signal m1:std_logic_vector(3 downto 0);signal m2:std_logic_vector(3 downto 0);signal s1:std_logic_vector(3 downto 0);signal s2:std_logic_vector(3 downto 0);signal counter:std_logic_vector(8 downto 0);-----------secondsignal countern1:std_logic_vector(7 downto 0);----------speakersignal clk:std_logic;----------secondsignal clkn1:std_logic;-----speakersignal k:std_logic_vector(1 downto 0);---------xuan ze xian shisignal z:std_logic_vector(1 downto 0);------00 zheng chang ;01 tiao zheng;10 nao ling;-------------------------------------------------beginfen:process(clk1)beginif(clk1'event and clk1='1')thenif(counter="110000000")thencounter<="000000000";clk<=not clk;elsecounter<=counter+'1';end if;if(countern1="10000000")thencountern1<="00000000";elseclkn1<=not clkn1;end if;end if;end process fen;-------------------------------------------kong:process(md2)beginif( md2'event and md2='1')thenif(k="11")thenk<="00";elsek<=k+1;end if;end if;end process kong;process(md1)beginif(md1'event and md1='1')thenif(z="10")thenz<="00";elsez<=z+1;end if;end if;end process;----------------------------------------------choice:process(clk1)beginif clk1'event and clk1='1' thenif sel="101" thensel<="000";elsesel<=sel+1;end if;end if;end process choice;-------------------------------------------zheng chang xian shi-----------------------------------------------hour1hou_1:process(clk,hou2,min1,min2,sec1,sec2)beginif clk'event and clk='1' thenif (hou1="0010" and hou2="0011" and min1="0101" and min2="1001" and sec1="0101" andsec2="1001") thenhou1<="0000";elsif (hou2="1001"and min1="0101" and min2="1001" and sec1="0101" and sec2="1001") thenhou1<=hou1+1;end if;end if;if(allow1='1' and z="01")thenhou1<=hou1n;end if;end process hou_1;-----------------------------------------------hour2hou_2:process(clk,min1,min2,sec1,sec2,hou1)beginif clk'event and clk='1' thenif (hou1="0010" and hou2="0011"and min1="0101" and min2="1001" and sec1="0101" andsec2="1001") thenhou2<="0000";elsif hou2="1001"and(min1="0101" and min2="1001" and sec1="0101" and sec2="1001") thenhou2<="0000";elsif (min1="0101" and min2="1001" and sec1="0101" and sec2="1001")thenhou2<=hou2+1;end if;end if;if(allow1='1' and z="01")thenhou2<=hou2n;end if;end process hou_2;-----------------------------------------------min1min_1:process(clk,min2,sec1,sec2)beginif clk'event and clk='1' thenif (min1="0101" and min2="1001" and sec1="0101" and sec2="1001") then min1<="0000";elsif (min2="1001"and sec1="0101" and sec2="1001") thenmin1<=min1+1;end if;end if;if(allow1='1' and z="01")thenmin1<=min1n;end if;end process min_1;----------------------------------------------min2min_2:process(clk,sec1,sec2)beginif clk'event and clk='1' thenif (min2="1001" and sec1="0101" and sec2="1001")thenmin2<="0000";elsif (sec1="0101" and sec2="1001")thenmin2<=min2+1;end if;end if;if(allow1='1' and z="01")thenmin2<=min2n;end if;end process min_2;---------------------------------------------second1sec_1:process(clk)beginif clk'event and clk='1' thenif (sec1="0101" and sec2="1001")thensec1<="0000";elsif sec2="1001"thensec1<=sec1+1;end if;end if;if(allow1='1' and z="01")thensec1<="0000";end if;end process sec_1;--------------------------------------------second2sec_2:process(clk)beginif clk'event and clk='1' thenif sec2="1001" thensec2<="0000";else sec2<=sec2+1;end if;end if;if(allow1='1' and z="01")thensec2<="0000";end if;end process sec_2;-----------------------------------------------------------------------------------shi jian tiao zheng process(md3)-----------hour1beginif(z="01")thenif(k="11")thenif(md3'event and md3='1')thenif(hou1n="0010")thenhou1n<="0000";elsehou1n<=hou1n+1;end if;end if;end if;end if;end process;process(md3)-----------hour2beginif(z="01")thenif(k="10")thenif(md3'event and md3='1')thenif(hou2n="1001")or(hou1n="0010" and hou2n="0011")then hou2n<="0000";elsehou2n<=hou2n+1;end if;end if;end if;end if;end process;process(md3)-----------min1beginif(z="01")thenif(k="01")thenif(md3'event and md3='1')thenif(min1n="0110")thenmin1n<="0000";elsemin1n<=min1n+1;end if;end if;end if;end if;end process;process(md3)------------min2beginif(z="01")thenif(k="00")thenif(md3'event and md3='1')thenif(min2n="1001")thenmin2n<="0000";elsemin2n<=min2n+1;end if;end if;end if;end if;end process;--------------------------------------------------------------------------------------she zhi nao zhong sethour1:process(md3)beginif(z="10")thenif(k="11")thenif(md3'event and md3='1')thenif(seth1="0010")thenseth1<="0000";elseseth1<=seth1+1;end if;end if;end if;end if;end process sethour1;-------------------------------------------sethour2:process(md3)beginif(z="10")thenif(k="10")thenif(md3'event and md3='1')thenif(seth2="1001")or(seth2="0010" and seth2="0100")then seth2<="0000";elseseth2<=seth2+1;end if;end if;end if;end if;end process sethour2;-------------------------------------------setmin1:process(md3)beginif(z="10")thenif(k="01")thenif(md3'event and md3='1')thenif(setm1="0110")thensetm1<="0000";elsesetm1<=setm1+1;end if;end if;end if;end if;end process setmin1;----------------------------------------------setmin2:process(md3)beginif(z="10")thenif(k="00")thenif(md3'event and md3='1')thenif(setm2="1001")thensetm2<="0000";elsesetm2<=setm2+1;end if;end if;end if;end if;end process setmin2;----------------------------------------------------------------------------------------nao zhongspeaker:process(clk1,hou1,hou2,min1,min2)beginif clk1'event and clk1='1'thenif(allow2='1')thenif seth1=hou1 and seth2=hou2 and setm1=min1 and setm2=min2 thenspeak<=clkn1;elsespeak<='0';end if;end if;end if;end process speaker;--------------------------------------------------------------------------------------disp:process(sel,md1,hou1,hou2,min1,min2,sec1,sec2,seth1,seth2,setm1,setm2) beginif sel="000" thenselout<="111110";case h1 iswhen "0000"=>dout<="1000000";--0when "0001"=>dout<="1111001";--1when "0010"=>dout<="0100100";--2when others =>dout<="1000000";--0end case;elsif sel="001" thenselout<="111101";case h2 iswhen "0000"=>dout<="1000000";--0when "0001"=>dout<="1111001";--1when "0010"=>dout<="0100100";--2when "0011"=>dout<="0110000";--3when "0100"=>dout<="0011001";--4when "0101"=>dout<="0010010";--5when "0110"=>dout<="0000010";--6when "0111"=>dout<="1111000";--7when "1000"=>dout<="0000000";--8when "1001"=>dout<="0010000";--9when others=>dout<="1000000";end case;elsif sel="010" thenselout<="111011";case m1 iswhen "0000"=>dout<="1000000";--0 when "0001"=>dout<="1111001";--1 when "0010"=>dout<="0100100";--2 when "0011"=>dout<="0110000";--3 when "0100"=>dout<="0011001";--4 when "0101"=>dout<="0010010";--5 when others=>dout<="1000000";--0 end case;elsif sel="011" thenselout<="110111";case m2 iswhen "0000"=>dout<="1000000";--0 when "0001"=>dout<="1111001";--1 when "0010"=>dout<="0100100";--2 when "0011"=>dout<="0110000";--3 when "0100"=>dout<="0011001";--4 when "0101"=>dout<="0010010";--5 when "0110"=>dout<="0000010";--6 when "0111"=>dout<="1111000";--7 when "1000"=>dout<="0000000";--8 when "1001"=>dout<="0010000";--9 when others=>dout<="1000000";--0 end case;elsif sel="100" thenselout<="101111";case s1 iswhen "0000"=>dout<="1000000";--0 when "0001"=>dout<="1111001";--1 when "0010"=>dout<="0100100";--2 when "0011"=>dout<="0110000";--3 when "0100"=>dout<="0011001";--4 when "0101"=>dout<="0010010";--5 when others=>dout<="1000000";--0 end case;elsif sel="101" thenselout<="011111";case s2 iswhen "0000"=>dout<="1000000";--0 when "0001"=>dout<="1111001";--1 when "0010"=>dout<="0100100";--2 when "0011"=>dout<="0110000";--3 when "0100"=>dout<="0011001";--4 when "0101"=>dout<="0010010";--5when "0110"=>dout<="0000010";--6when "0111"=>dout<="1111000";--7when "1000"=>dout<="0000000";--8when "1001"=>dout<="0010000";--9when others=>dout<="1000000";--0end case;end if;if z="00" then---------------zheng chang xian shih1<=hou1;h2<=hou2;m1<=min1;m2<=min2;s1<=sec1;s2<=sec2;elsif z="01"thenh1<=hou1n;h2<=hou2n;m1<=min1n;m2<=min2n;s1<="0000";s2<="0000";elsif z="10" then ----------------nao zhong xian shi h1<=seth1;h2<=seth2;m1<=setm1;m2<=setm2;s1<="0000";s2<="0000";end if;end process disp;------------------------------------------end one;11。

简单的数字时钟(verilog设计)

简单的数字时钟(verilog设计)

3、计时
if (second0<4'b1001) second0<=second0+4'b1; else second0<=4'b0; if (second1<4'b0101) second1<=second1+4'b1; else second1<=4'b0; if (minute0<4'b1001) minute0<=minute0+4'b1; else minute0<=4'b0; if (minute1<4'b0101) minute1<=minute1+4'b1; else minute1<=4'b0; if (hour1<2'b10) if (hour0<4'b1001) hour0<=hour0+4'b1; else hour0<=4'b0; hour1<=hour1+2'b1; if (hour1==2'b10) if (hour0<4'b0011) hour0<=hour0+4'b1; else hour0<=4'b0; hour1<=2'b0;
谢谢!
2、确认
if (miao==1) nz1<=1;
3、闹铃
if (nz1==1) begin lednz[1]<=1; if((hour_1==hour1)&&(hour_0==hour0)&&(minute_1==minute1)&&(m inute_0==minute0)) lednz[0]<=lednz[0]+1; end

(完整word版)数字钟verilog(word文档良心出品)

(完整word版)数字钟verilog(word文档良心出品)

目录1 设计任务及要求 (1)2 总体设计分析 (1)3 各模块设计 (2)3.1 数字钟主体部分 (2)3.1.1小时计数器 (2)3.1.2 分、秒计数器 (3)3.2 分频部分 (4)3.3 秒表模块 (5)3.4 闹钟模块 (5)3.5 时间设置模块 (7)3.6 报时模块 (7)3.7 控制显示模块 (8)3.8 顶层模块 (11)4 总结 (11)4.1 本次作业遇到的问题 (11)4.2 建议和总结 (12)附件 (13)1 设计任务及要求本次大作业的要求为设计一个多功能数字钟,其具体要求如下:1.有基础的实时数字钟显示功能,即时、分、秒的正常显示模式,并且在此基础上增加上,下午显示。

2.手动校准。

按动方式键,将电路置于校时状态,则计时电路可用手动方式校准,每按一下校时键,时计数器加1;按动方式键,将电路置于校分状态,以同样方式手动校分。

3.整点报时,仿中央人民广播电台整点报时信号,从59分50秒起每隔2秒发出一次低音“嘟”信号(信号鸣叫持续时间1S,间隙时间1S)连续5次,到达整点(00分00秒时),发一次高音“哒”信号(信号持续时间1S)。

4.闹时功能,按动方式键,使电路工作于预置状态,此时显示器与时钟脱开,而与预置计数器相连,利用前面手动校时,校分方式进行预置,预置后回到正常模式。

当计时计至预置的时间时,扬声器发出闹铃信号,时间为半分钟,闹铃信号可以用开关“止闹”,按下此开关后,闹铃声立刻中止,正常情况下应将此开关释放,否则无闹时作用。

5.秒表功能。

按start键开始计秒,按stop键停止计秒并保持显示数不变,直到复位信号加入。

2 总体设计分析设计的总体部分按照要求可以分为基本的数字时钟显示、手动校准、整点报时、闹钟功能和秒表功能5大部分。

其总体设计框图如下:图1 总体设计框图其中整点报时跟闹钟部分要求不同频率的声响,所以需要加入分频器模块将输入的1kHZ的分频产生500HZ及1HZ的方波信号,其中1HZ的信号对应1S 的周期,可以用作时钟秒的显示及秒表部分。

时钟表示法数字表示法

时钟表示法数字表示法

时钟表示法数字表示法
时钟的数字表示法是一种常见的时间表示方法,它使用数字来描述小时和分钟。

小时使用1到12的数字来表示,而分钟则使用0到59的数字来表示。

例如,上午9点30分可以表示为"9:30"。

此外,还有刻度表示法,即使用钟表上的刻度线来表示时间。

钟表被分为12个小时刻度,每个小时刻度之间有5分钟的刻度线。

时针、分针和秒针指向不同的刻度线,以显示当前的小时和分钟。

例如,时针指向12点,分针指向6点的刻度线时,表示时间为"6:00"。

此外,还有其他的时间表示方法,如直接法和逆读法。

直接法就是直接使用数字来表示时间,例如"6:10"可以表示为"six ten"。

逆读法则是从60分钟中减去未过完的小时数,并读出剩余的分钟数,例如"4:30"可以表示为"half past four"。

需要注意的是,不同地区和语言可能存在时间表示法的差异。

因此,在使用时间表示法时,最好根据具体语境和习惯来选择合适的方法。

数字时钟701T(28G) - 设置说明说明书

数字时钟701T(28G) - 设置说明说明书

correction, back lit LCD display and trade button inputINTRODUCTIONThe digital time clock has been designed particularly for the access control market. It incorporates all the features required from a time clock including:• 12V AC or DC operation.• Dry Contact 3A rated relay output (CO, NO & NC).• Six fully programmable ON/OFF times. The times can be set for a single day of the week, weekends, week days or all days. To disable an ON/OFF time simply set the ON time the same as the OFF time.• On board battery backup that will maintain the correct time and all time bands during mains failures.• Automatic British summer time correction (BST/GMT). If this feature is not required it can be disabled, by moving JP2 into position A.• Manual override button to toggle the relay on and off in stan-dby mode (NOTE: The manual override is attached to time band 1 and so will switch off at the off time of time band 1 (Unless another time band is also set to on). For all other time bands the relay will stay in the state it is left until the next on then off time period).• Trade button input: when the time clock is used in trade mode, the relay will only energise when the trade button is pressed and then, only during an active time band. The time clock can be switched into trade mode by moving JP1 into position A. When JP1 is in position B the relay will energise for the full duration of an active time band.• Trade activated relay time can be adjusted from 1 second up to 99 seconds during programming.• All information is displayed on an easy to read 2 lines 16 cha-racters back lit LCD display.• The time clock is mounted within an ABS white wall moun-table plastic box.In standby mode the time clock display will show the current day of the week, the time and date. It will also show if the time is British summer time (BST) or Greenwich Mean Time (GMT). Fi-nally the display will indicate if the relay is ON or OFF. When this is flashing it indicates the time clock is in trade mode and so the relay will only energise when the trade button is pressed (The ON/OFF flashing, only indicates if a time band is on or off). If theON/OFF is fixed, this indicates the state of the relay.Fig. 1Fig. 3PROGRAMMINGProgramming is carried out by meansof the four push buttons. The modebutton advances through the modesbeginning with mode 1 which allowsthe editing of the time and date,mode 2 – 7 allows the editing of thetime bands and mode 8 allows theediting of the relay time in trade mode(Note: mode 8 only appears in trademode). The up/down buttons allowthe underlined information to be edi-ted (pressing these buttons once willchange the value by one, holding thebutton down will auto increment thevalue until the button is released) andthe select button allows the underlinecursor to rotate round to the next itemon the display. If the time clock is ina-dvertently left in programming modeit will automatically revert to standbymode after a preset time.TECHNICAL SPECIFICATIONSupply Voltage:12Vdc or 12VacStandby Current (Relay off): 47mAStandby Current (Relay on): 67mABattery backup:Min. 3 daysRelay contacts (Dry contact): 3A@24Vdc3A @ 120VacOn/Off times available: SixON/OFF period 1 will switch off at the off time for that period regardless of manual override.ON/OFF period 2-6 won’t switch off at the off time for that period if override is pressed. Time Accuracy:less than + or – 2 seconds drift per dayTrade mode relay time:From 1 second to 99 secondsDimensions:110 x 70 x 30mmJumpers:JP1 (A = Trade mode, B = Time clock mode)JP2 (A = BST/GMT Correction disabled, B = Automatic BST/GMT correction)CUSTOMER SUPPORTAll Countries:VIDEX ELECTRONICS S.P.A.******************************* Tel: +39 0734-631669Fax: +39 0734-632475UK Customers:VIDEX SECURITY L TDTech Line: 0191 224 3174Fax: 0191 224 1559The product is CE marked demonstrating its conformity and is for distribu-tion within all member states of the EU with no restrictions. This productfollows the provisions of the European Directives 2004/108/ECC (EMC);2006/95/ECC (LVD) and 93/68/ECC (CE marking).。

时钟完整版(带整点报时)

时钟完整版(带整点报时)

#include<Windows.h>#include<string.h>#include<mmsystem.h>#include<wingdi.h>#include"resource.h"#include<math.h>#include<commdlg.h>#pragma comment(lib,"WinLib.lib")#pragma comment(lib,"WINMM.LIB")//导入声音用void SetDlgMenuID(UINT nMainDlgID,UINT nCalendarDlgID,UINT nMenuID); void SetButtonID(UINT nCalendarID,UINT nExitID,UINT nBiaoPan1,UINT nBiaoPan2,UINT nBiaoPan3);INT_PTR ShowMainDlg();/**********************************************************API函数参考:GetLocalTime: 获得当前时间(公历:年、月、日、周)MoveToEx: 移动划线的起点LineTo: 绘制到某一点SetTextColor: 设置要绘制的文字颜色TextOut: 绘制文字SetBkMode: 设置背景显示模式wsprintf: 整数转换为字符串,宽字符,用Unicode码GetClientRect: 获取窗口大小GetDC: 获取内存设备SetTimer: 设置定时器FillRect: 填充矩形CreateSolidBrush: 创建刷子RGB: 设置RGB颜色CreateFont:创建一种有特殊性的字体结构体类型参考:SYSTEMTIME: 描述时间类型,包括年月日、时分秒、周**********************************************************/HINSTANCE g_hInst;//保存操作系统传递进来的"应用程序实例句柄"//Windows程序入口函数int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ){g_hInst = hInstance;SetDlgMenuID(IDD_DLG_CLOCK,IDD_DLG_CALENDAR,IDR_MENU);SetButtonID(ID_CALENDAR,ID_EXIT,ID_BIAO1,ID_BIAO2,ID_BIAO3);ShowMainDlg(IDD_DLG_CLOCK);}typedef struct _stDateTime{int nYear;int nMonth;int nDay;}stDateTime;//定义表格,存储年-2099年的农历信息:每年的大小月、闰月信息、春节所在的公历日期unsigned int LunarCalendarTable[199] ={0x04AE53,0x0A5748,0x5526BD,0x0D2650,0x0D9544,0x46AAB9,0x056A4D, 0x09AD42,0x24AEB6,0x04AE4A,/*1901-1910*/0x6A4DBE,0x0A4D52,0x0D2546,0x5D52BA,0x0B544E,0x0D6A43,0x296D37, 0x095B4B,0x749BC1,0x049754,/*1911-1920*/0x0A4B48,0x5B25BC,0x06A550,0x06D445,0x4ADAB8,0x02B64D,0x095742, 0x2497B7,0x04974A,0x664B3E,/*1921-1930*/0x0D4A51,0x0EA546,0x56D4BA,0x05AD4E,0x02B644,0x393738,0x092E4B, 0x7C96BF,0x0C9553,0x0D4A48,/*1931-1940*/0x6DA53B,0x0B554F,0x056A45,0x4AADB9,0x025D4D,0x092D42,0x2C95B6, 0x0A954A,0x7B4ABD,0x06CA51,/*1941-1950*/0x0B5546,0x555ABB,0x04DA4E,0x0A5B43,0x352BB8,0x052B4C,0x8A953F, 0x0E9552,0x06AA48,0x6AD53C,/*1951-1960*/0x0AB54F,0x04B645,0x4A5739,0x0A574D,0x052642,0x3E9335,0x0D9549, 0x75AABE,0x056A51,0x096D46,/*1961-1970*/0x54AEBB,0x04AD4F,0x0A4D43,0x4D26B7,0x0D254B,0x8D52BF,0x0B5452, 0x0B6A47,0x696D3C,0x095B50,/*1971-1980*/0x049B45,0x4A4BB9,0x0A4B4D,0xAB25C2,0x06A554,0x06D449,0x6ADA3D, 0x0AB651,0x093746,0x5497BB,/*1981-1990*/0x04974F,0x064B44,0x36A537,0x0EA54A,0x86B2BF,0x05AC53,0x0AB647, 0x5936BC,0x092E50,0x0C9645,/*1991-2000*/0x4D4AB8,0x0D4A4C,0x0DA541,0x25AAB6,0x056A49,0x7AADBD,0x025D52, 0x092D47,0x5C95BA,0x0A954E,/*2001-2010*/0x0B4A43,0x4B5537,0x0AD54A,0x955ABF,0x04BA53,0x0A5B48,0x652BBC, 0x052B50,0x0A9345,0x474AB9,/*2011-2020*/0x06AA4C,0x0AD541,0x24DAB6,0x04B64A,0x69573D,0x0A4E51,0x0D2646, 0x5E933A,0x0D534D,0x05AA43,/*2021-2030*/0x36B537,0x096D4B,0xB4AEBF,0x04AD53,0x0A4D48,0x6D25BC,0x0D254F, 0x0D5244,0x5DAA38,0x0B5A4C,/*2031-2040*/0x056D41,0x24ADB6,0x049B4A,0x7A4BBE,0x0A4B51,0x0AA546,0x5B52BA, 0x06D24E,0x0ADA42,0x355B37,/*2041-2050*/0x09374B,0x8497C1,0x049753,0x064B48,0x66A53C,0x0EA54F,0x06B244, 0x4AB638,0x0AAE4C,0x092E42,/*2051-2060*/0x3C9735,0x0C9649,0x7D4ABD,0x0D4A51,0x0DA545,0x55AABA,0x056A4E, 0x0A6D43,0x452EB7,0x052D4B,/*2061-2070*/0x8A95BF,0x0A9553,0x0B4A47,0x6B553B,0x0AD54F,0x055A45,0x4A5D38, 0x0A5B4C,0x052B42,0x3A93B6,/*2071-2080*/0x069349,0x7729BD,0x06AA51,0x0AD546,0x54DABA,0x04B64E,0x0A5743, 0x452738,0x0D264A,0x8E933E,/*2081-2090*/0x0D5252,0x0DAA47,0x66B53B,0x056D4F,0x04AE45,0x4A4EB9,0x0A4D4C, 0x0D1541,0x2D92B5 /*2091-2099*/};char* TianGanDizhi[60]={"甲子", "乙丑","丙寅","丁卯","戊辰","已巳","庚午","辛未","壬申","癸酉","甲戌","乙亥","丙子","丁丑","戊寅","已卯","庚辰","辛巳","壬午","癸未","甲申","乙酉","丙戌","丁亥","戊子","已丑","庚寅","辛卯","壬辰","癸巳","甲午","乙未","丙申","丁酉","戊戌","已亥","庚子","辛丑","壬寅","癸卯","甲辰","乙巳","丙午","丁未","戊申","已酉","庚戌","辛亥","壬子","癸丑","甲寅","乙卯","丙辰","丁巳","戊午","已未","庚申","辛酉","壬戌","癸亥"char *ChDayTable[] ={"*","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"};char *ChMonthTable[] = {"*","正","二","三","四","五","六","七","八","九","十","十一","腊"};//定义表格,存储每月日离元旦的天数(不考虑瑞年)unsigned int MonthAdd[12] ={0,31,59,90,120,151,181,212,243,273,304,334};//定义用户要显示的年、月、日unsigned int nCurrentYear=0; //button控制年unsigned int nCurrentMonth=0;//月unsigned int nCurrentDay=0; //日UINT LiteSongs = 0; //判断是否听歌UINT Total=0; //我自定义的变量,当月的总天数UINT PreTotal=0; //自定义的当月的前一月的总天数UINT BUTTON6=0;UINT BUTTON4=0;int k=0;int m=0;//TCHAR Hours[255];SYSTEMTIME BellTime;UINT Inthour=0;//判断某年是否为公历瑞年int IsLeapYear(WORD iYear) //学生需要修改此函数,已经修改{if(((iYear%4==0)&&!(iYear%100==0))||(iYear%400==0))return 1;elsereturn 0;}//公历日期转农历日期的函数void SunToLunar(const stDateTime* pSunDay,stDateTime* pLunarDay) {int i=0;int SunDiff=0;int SpringDiff=0;int nSpringYear=pSunDay->nYear;int nSpringMonth=1;int nSpringDay=0;//计算当前公历日离当年元旦的天数SunDiff = MonthAdd[pSunDay->nMonth-1] + pSunDay->nDay - 1;if(IsLeapYear(pSunDay->nYear) && (pSunDay->nMonth > 2) )//若是瑞年且大于月,天数再加SunDiff++;//计算春节所在公历日离元旦的天数:通过查表,计算当年的春节所在的公历日期,if(((LunarCalendarTable[pSunDay->nYear - 1901] & 0x60)>>5)==1)//若春节在公历月SpringDiff=(LunarCalendarTable[pSunDay->nYear-1901]&0x1F)-1;else//若春节在公历月SpringDiff=(LunarCalendarTable[pSunDay->nYear-1901]&0x1F)-1+31;//SunDiff和SpringDiff的差就是当前公历日离春节的天数if(SunDiff>=SpringDiff)//公历日在春节后{int x = SunDiff - SpringDiff;int bLunar = (LunarCalendarTable[nSpringYear - 1901] & 0xF00000)>>20;//闰月月份i=0;nSpringMonth=1;for(;;){int a = (LunarCalendarTable[pSunDay->nYear-1901] & (0x80000>>i));//计算大小月if(a==0)a=29;elsea=30;if(x<a)break;x =x - a;i++;nSpringMonth++;}nSpringDay =x+1;//如果有闰月if(nSpringMonth>bLunar && bLunar>0)nSpringMonth--;}else//公历日在春节前{int x = SpringDiff-SunDiff;int nShift=0;int bLunar = (LunarCalendarTable[nSpringYear - 1901] & 0xF00000)>>20;//闰月月份i=0;nSpringYear--;//需要上一年的农历信息nSpringMonth=12;//从最后一个月开始计算if (bLunar == 0)//如果没有润月nShift = 0x100;elsenShift = 0x80;for(;;){int a = (LunarCalendarTable[nSpringYear-1901] & (nShift<<i));//计算大小月if(a==0)a=29;elsea=30;if(x<a){x = a-x;break;}x =x - a;i++;nSpringMonth--;}nSpringDay =x+1;if(nSpringMonth<bLunar && bLunar>0)nSpringMonth++;}pLunarDay->nYear = nSpringYear;pLunarDay->nMonth= nSpringMonth;pLunarDay->nDay = nSpringDay;}//根据公历日期获得星期int GetDayOfWeek(const stDateTime* pSunDay){//根据泰勒公式//nWeek = [nYear1÷] - 2*nYear1 + nYear2 + [nYear2÷] + [26(nMonth+1)÷] + nDay - 1int nWeek=0;int nYear1=pSunDay->nYear/100;//年的前两位数字int nYear2=pSunDay->nYear%100;//年的后两位数字int nDay=pSunDay->nDay; //公立日int nMonth=pSunDay->nMonth;//公立月数,所求的月份如果是月或月,//则应视为上一年的月或月,//也就是公式中nMonth的取值范围是从到而不是从到if(nMonth==1 || nMonth==2){nMonth=12+nMonth;nYear1=(pSunDay->nYear-1)/100;//年的前两位数字nYear2=(pSunDay->nYear-1)%100;//年的后两位数字}nWeek = nYear1/4 - 2*nYear1 + nYear2 + nYear2/4 + (26*(nMonth+1))/10 + nDay - 1;if(nWeek < 0)nWeek = ((nWeek)%7+7);// 有问题吗?nWeek可能小于零,循环加elsenWeek = (nWeek)%7;return nWeek;}//根据公立年得到农历干支年char* GetGanZhi(int nYear){int i=(nYear-1984)%60;return TianGanDizhi[i];}//日历绘制函数,学生自己实现该函数void DrawCalendar(HDC hDC,int nWidth,int nHeight){//获得日历的背景色stDateTime SunDay,LunarDay; //存储当时年月日SYSTEMTIME DateTime; //系统时间RECT rc;HBRUSH hBrush;HFONT hFont;TCHAR RILI[255]; //日历的标题TCHAR GraTime[255]; //表格日期UINT xOrg=50; //x起始坐标UINT yOrg=50; //y起始坐标UINT xRight=nWidth-45; //X的右端不包括UINT yBottom = nHeight-30; //Y的底部UINT i=0,biaoGe=0; //日历表格用TCHAR *WeekDay[] = {"日","一","二","三","四","五","六"};TCHAR *ShuXiang[]= {"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"};UINT Week=0;//列数UINT Hang=0;//行数TCHAR Str[255];//农历和公历年月字符UINT week=0;UINT hangkuan=0,liekuan=0;UINT First=0;UINT xLeft=0;UINT yRigth=0;UINT ShengXiao=0;UINT BeiJing=0;HBITMAP hBkmap;//得到图片HDC hdc;//绘制日历的矩形背景(改变皮肤)hdc = CreateCompatibleDC(hDC);switch (nCurrentMonth%12){case 0:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/yiyue.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 1:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/eryue.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 2:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/sanyue.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE) ;break;case 3:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/siyue.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 4:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/wuyue.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 5:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/liuyue.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE) ;break;case 6:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/qi.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 7:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/ba.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 8:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/jiu.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 9:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/shi.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 10:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/shiyi.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 11:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/beijing/shier.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;}SelectObject(hdc,hBkmap);BitBlt(hDC,0,0,nWidth,nHeight,hdc,0,0,SRCCOPY);SetRect (&rc,xOrg+65,yOrg,xRight-65,yOrg+25);hBrush=CreateSolidBrush(RGB(230,0,150));FillRect(hDC,&rc,hBrush);SetRect (&rc,xOrg,yOrg,xOrg+65,yOrg+25);hBrush=CreateSolidBrush(RGB(0,255,255));FillRect(hDC,&rc,hBrush);SetRect (&rc,xRight-65,yOrg,xRight,yOrg+25);hBrush=CreateSolidBrush(RGB(0,255,255));FillRect(hDC,&rc,hBrush);//绘制星期背景色MoveToEx(hDC,xOrg,yOrg,NULL);LineTo(hDC,xRight,yOrg);MoveToEx(hDC,xOrg,yOrg,NULL);LineTo(hDC,xOrg,yBottom);MoveToEx(hDC,xRight,yOrg,NULL);LineTo(hDC,xRight,yBottom);MoveToEx(hDC,xOrg,yBottom,NULL);LineTo(hDC,xRight,yBottom);//星期标题框MoveToEx(hDC,xOrg,yOrg+25,NULL);LineTo(hDC,xRight,yOrg+25);//行biaoGe = yBottom-yOrg-25;//只是日历的高度biaoGe = biaoGe/6;//高度分为六块hangkuan=biaoGe;for(i=0;i<5;i++)//画五行{MoveToEx(hDC,xOrg,yOrg+25+biaoGe*(i+1),NULL);LineTo(hDC,xRight,yOrg+25+biaoGe*(i+1));}//列biaoGe = xRight-xOrg;//只是日历的宽度biaoGe = biaoGe/7;//要七列liekuan=biaoGe;for(i=0;i<6;i++)//画七列{MoveToEx(hDC,xOrg+biaoGe*(i+1),yOrg,NULL);LineTo(hDC,xOrg+biaoGe*(i+1),yBottom);}//绘制‘星期’标题框内的文字SetTextColor(hDC,RGB(255,0,0));TextOut(hDC,xOrg+20,yOrg+6,WeekDay[0],strlen(WeekDay[0]));//星期日的//绘制“属相”的文字SetTextColor(hDC,RGB(0,100,255));switch((nCurrentYear-4)%12)//jisuan{case 0:TextOut(hDC,xOrg-35,yOrg,ShuXiang[0],strlen(ShuXiang[0]));break;case 1:TextOut(hDC,xOrg-35,yOrg,ShuXiang[1],strlen(ShuXiang[1]));break;case 2:TextOut(hDC,xOrg-35,yOrg,ShuXiang[2],strlen(ShuXiang[2]));break;case 3:TextOut(hDC,xOrg-35,yOrg,ShuXiang[3],strlen(ShuXiang[3]));break;case 4:TextOut(hDC,xOrg-35,yOrg,ShuXiang[4],strlen(ShuXiang[4]));break;case 5:TextOut(hDC,xOrg-35,yOrg,ShuXiang[5],strlen(ShuXiang[5]));break;case 6:TextOut(hDC,xOrg-35,yOrg,ShuXiang[6],strlen(ShuXiang[6]));break;case 7:TextOut(hDC,xOrg-35,yOrg,ShuXiang[7],strlen(ShuXiang[7]));break;case 8:TextOut(hDC,xOrg-35,yOrg,ShuXiang[8],strlen(ShuXiang[8]));break;case 9:TextOut(hDC,xOrg-35,yOrg,ShuXiang[9],strlen(ShuXiang[9]));break;case 10:TextOut(hDC,xOrg-35,yOrg,ShuXiang[10],strlen(ShuXiang[10]));break;case 11:TextOut(hDC,xOrg-35,yOrg,ShuXiang[11],strlen(ShuXiang[11]));break;}SetTextColor(hDC,RGB(0,0,0));for(i=1;i<6;i++)//星期一到六{TextOut(hDC,xOrg+20+biaoGe*i,yOrg+6,WeekDay[i],strlen(WeekDay[i ]));}SetTextColor(hDC,RGB(255,0,0));TextOut(hDC,xOrg+20+biaoGe*6,yOrg+6,WeekDay[6],strlen(WeekDay[6 ]));//以下代码是公历显示if(nCurrentYear==0)//如果当前日期还没有被设定{GetLocalTime(&DateTime);nCurrentYear = DateTime.wYear;nCurrentMonth= DateTime.wMonth;nCurrentDay =DateTime.wDay;}SunDay.nYear = nCurrentYear;SunDay.nMonth = nCurrentMonth;SunDay.nDay = nCurrentDay;SunToLunar(&SunDay,&LunarDay);//得到农历TextOut(hDC,80,28,ChMonthTable[LunarDay.nMonth],strlen(ChMonthTable[LunarDay.nMonth]));//农历显示TextOut(hDC,110,28,"月",strlen("月"));SunDay.nDay = 1;wsprintf(GraTime,"%.4d年%.2d月%.2d日",nCurrentYear,nCurrentMonth,nCurrentDay);//现在时间TextOut(hDC,50,10,GraTime,strlen(GraTime));//标题的时间//十二生肖图片hdc = CreateCompatibleDC(hDC);switch((nCurrentYear-4)%12){case 0:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/0.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 1:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/1.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 2:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/2.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 3:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/3.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 4:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/4.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 5:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/5.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 6:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/6.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 7:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/7.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 8:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/8.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 9:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/9.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 10:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/10.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;case 11:hBkmap = (HBITMAP)LoadImage(g_hInst,"../image/shengxiao/11.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);break;}SelectObject(hdc,hBkmap);BitBlt(hDC,7,20,150,150,hdc,0,0,SRCCOPY);//该月的总天数if(SunDay.nMonth==12){//PreTotal=30;Total=31;elseTotal=MonthAdd[SunDay.nMonth]-MonthAdd[SunDay.nMonth-1];if(IsLeapYear(SunDay.nYear)&&SunDay.nMonth==2){Total++;}//前一月的总天数if(SunDay.nMonth==1)PreTotal=31;else if(SunDay.nMonth==3){PreTotal=28;if(IsLeapYear(SunDay.nYear))PreTotal++;}else if(SunDay.nMonth==12)PreTotal=30;elsePreTotal=MonthAdd[SunDay.nMonth-1]-MonthAdd[SunDay.nMonth-2];First=GetDayOfWeek(&SunDay); //该月的第一天是星期几for(i=1;i<=Total;i++){SunDay.nYear = nCurrentYear;SunDay.nMonth = nCurrentMonth;SunDay.nDay=i; //从一号开始week=GetDayOfWeek(&SunDay);//得到该月第i号是星期几 SunToLunar(&SunDay,&LunarDay);//得到农历Week=week%7; //从第Week列开始Hang=((First+i-1)-(First+i-1)%7)/7; //从第Hang行开始xLeft=xOrg+15+(Week)*liekuan;yRigth=yOrg+40+(Hang)*hangkuan;if(DateTime.wYear==SunDay.nYear&&DateTime.wMonth==SunDay.nMonth &&DateTime.wDay==i)//显示今天{SetRect (&rc,xOrg+(Week)*liekuan,yOrg+25+(Hang)*hangkuan,xOrg+(Week)*liekuan+liekuan,yOrg+25+(Hang)*hangkuan+hangkuan) ;hBrush=CreateSolidBrush(RGB(0,255,255));FillRect(hDC,&rc,hBrush);}if(nCurrentYear==SunDay.nYear&&nCurrentMonth==SunDay.nMonth&&nC urrentDay==i)//动态显示每一天{SetRect (&rc,xOrg+(Week)*liekuan,yOrg+25+(Hang)*hangkuan,xOrg+(Week)*liekuan+liekuan,yOrg+25+(Hang)*hangkuan+hangkuan) ;hBrush=CreateSolidBrush(RGB(255,255,0));FillRect(hDC,&rc,hBrush);}SetTextColor(hDC,RGB(0,0,255));//节日颜色if(SunDay.nMonth==1&&SunDay.nDay==1){TextOut(hDC,xLeft,yRigth,"元旦",strlen("元旦"));//显示公历}else if(SunDay.nMonth==2&&SunDay.nDay==14){TextOut(hDC,xLeft,yRigth,"情人节",strlen("情人节"));}else if(SunDay.nMonth==5&&SunDay.nDay==1){TextOut(hDC,xLeft,yRigth,"劳动节",strlen("劳动节"));else if(SunDay.nMonth==5&&SunDay.nDay==4){TextOut(hDC,xLeft,yRigth,"青年节",strlen("青年节"));}else if(SunDay.nMonth==9&&SunDay.nDay==10){TextOut(hDC,xLeft,yRigth,"教师节",strlen("教师节"));}else if(SunDay.nMonth==10&&SunDay.nDay==1){TextOut(hDC,xLeft,yRigth,"国庆节",strlen("国庆节"));}else if(SunDay.nMonth==11&&SunDay.nDay==11){TextOut(hDC,xLeft,yRigth,"光棍节",strlen("光棍节"));}else if(SunDay.nMonth==11&&SunDay.nDay==24){TextOut(hDC,xLeft,yRigth,"感恩节",strlen("感恩节"));}else if(SunDay.nMonth==12&&SunDay.nDay==25){TextOut(hDC,xLeft,yRigth,"圣诞节",strlen("圣诞节"));}else{wsprintf(Str,"%i",i);SetTextColor(hDC,RGB(0,0,255));TextOut(hDC,xLeft,yRigth,Str,strlen(Str));//显示公历}//显示农历SetTextColor(hDC,RGB(0,0,255));//节日颜色if(LunarDay.nMonth==1&&LunarDay.nDay==1){TextOut(hDC,xLeft,yRigth+15,"春节",strlen("春节"));//农历显示else if(LunarDay.nMonth==1&&LunarDay.nDay==15){TextOut(hDC,xLeft,yRigth+15,"元宵节",strlen("元宵节"));//农历显示}else if(LunarDay.nMonth==5&&LunarDay.nDay==5){TextOut(hDC,xLeft,yRigth+15,"端午节",strlen("端午节"));//农历显示}else if(LunarDay.nMonth==9&&LunarDay.nDay==15){TextOut(hDC,xLeft,yRigth+15,"中秋节",strlen("中秋节"));//农历显示}else if(LunarDay.nMonth==9&&LunarDay.nDay==9){TextOut(hDC,xLeft,yRigth+15,"重阳节",strlen("重阳节"));//农历显示}else{SetTextColor(hDC,RGB(255,255,0));if(LunarDay.nDay==1)//月初改为月名{TextOut(hDC,xLeft,yRigth+15,ChMonthTable[LunarDay.nMonth],strlen(ChMonthTable[LunarDay.nMonth]));TextOut(hDC,xLeft+20,yRigth+15,"月",strlen("月"));}elseTextOut(hDC,xLeft,yRigth+15,ChDayTable[LunarDay.nDay],strlen(ChDayTable[LunarDay.nDay]));//农历显示}}//forhFont=CreateFont(44,20,0,100,FW_NORMAL,TRUE,0,0,ANSI_CHARSET,OU T_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_MODERN, "华文新魏"); //字体输出格式SelectObject(hDC,hFont);SetTextColor(hDC,RGB(50,50,255));wsprintf(RILI,"My>>万年历>> ");TextOut(hDC,200,10,RILI,10);}//事件函数:点击日历界面上各个按钮后被调用,学员自己实现该函数//注意:该函数调用完后,系统自动调用DrawCalendar函数// 因此,可以理解为,该函数和DrawCalendar函数是联动的void CalendarButtonEvent(UINT nID,HWND hDlg) //学生需要修改此函数{TCHAR Hours[255];int temp1;switch (nID){case IDC_BTN_YEARUP://点击了"年↑"按钮nCurrentYear++;break;case IDC_BTN_YEARDOWN:nCurrentYear--;break;case IDC_BTN_MONTHUP:{nCurrentMonth++;if(nCurrentMonth>12){nCurrentYear+=1;nCurrentMonth=1;}}break;case IDC_BTN_MONTHDOWN:{if(nCurrentMonth==1){nCurrentYear--;nCurrentMonth=12;}elsenCurrentMonth--;}break;case IDC_BTN_TODAY://GetDlgItemText(hDlg,IDC_BELL,Hours,sizeof(Hours));//nCurrentYear = atoi(Hours);nCurrentYear=0;break;case IDC_BUTTON_Day1://动态显示显示每一天{nCurrentDay++;if(nCurrentDay>Total){nCurrentDay=1;nCurrentMonth++;if(nCurrentMonth>12){nCurrentYear+=1;nCurrentMonth=1;}}}break;case IDC_BUTTON_Day2://动态显示显示每一天{nCurrentDay--;if(nCurrentDay<=0)nCurrentDay=PreTotal;nCurrentMonth--;if(nCurrentMonth==0){nCurrentYear--;nCurrentMonth=12;}}}break;case IDC_PLAYSONG:k++;{switch ( k%3){case 0:mciSendString("stop ../image/sound/b.mp3","",0,NULL); mciSendString("play ../image/sound/a.mp3","",0,NULL);break;case 1:mciSendString("stop ../image/sound/a.mp3","",0,NULL); mciSendString("play ../image/sound/y.mp3","",0,NULL);break;case 2:mciSendString("stop ../image/sound/y.mp3","",0,NULL); mciSendString("play ../image/sound/b.mp3","",0,NULL);break;}}break;case IDC_BUTTON6:m++;{switch ( m%3){case 0:mciSendString("pause ../image/sound/a.mp3","",0,NULL);break;case 1:mciSendString("pause ../image/sound/y.mp3","",0,NULL);break;case 2:mciSendString("pause ../image/sound/b.mp3","",0,NULL);break;}}break;case IDC_BUTTON_BELL:GetDlgItemText(hDlg,IDC_EDIT_YEAR,Hours,sizeof(Hours));temp1 = atoi(Hours);nCurrentYear = temp1;nCurrentMonth = 1;break;}}//该函数每.5秒被调用一次,时钟界面上的文字绘制,学生自己实现该函数void DrawClockText(HDC hDC){ //TCHAR year[255];//获得本地年月日时间stDateTime DateTime;stDateTime DateTime1,DateTime2; //得到公历农历日期 TCHAR HTime[255]; //存储时分秒TCHAR YTime[255]; //存储年TCHAR MTime[255]; //存储月TCHAR DTime[255];TCHAR TGAN[255]; //获得天干地支SYSTEMTIME LocTime; //定义当地时间RECT rec;HBRUSH hBrush;HFONT hfon;GetClientRect(hDC,&rec) ; //得到背影区域SetRect (&rec,33,52,94,65) ; //设置这块区域hBrush = CreateSolidBrush( RGB(0,0,222)); //建立画刷颜色FillRect(hDC,&rec,hBrush);SetBkMode(hDC,TRANSPARENT); //设置背景涂画,以备下次调用//获取星期和时间(时分秒)SetTextColor(hDC,RGB(111,208,252)); //字体颜色GetLocalTime(&LocTime);wsprintf(HTime,"%.2d:%.2d:%.2d",LocTime.wHour,LocTime.wMinute,L ocTime.wSecond);SetTextColor(hDC,RGB(235,255,0));SetBkMode(hDC,3);TextOut(hDC,35,50,HTime,8) ;//获得星期GetLocalTime(&LocTime);if(LocTime.wHour==Inthour)mciSendString("play ../image/sound/12.mp3","",0,NULL);//整点报时if(LocTime.wSecond==0&&LocTime.wMinute==0){switch(LocTime.wHour){case 6:mciSendString("play ../image/sound/06.mp3","",0,NULL);break;case 7:mciSendString("play ../image/sound/07.mp3","",0,NULL);break;case 8:mciSendString("play ../image/sound/08.mp3","",0,NULL);break;case 9:mciSendString("play ../image/sound/09.mp3","",0,NULL);break;case 10:mciSendString("play ../image/sound/10.mp3","",0,NULL);break;case 11:mciSendString("play ../image/sound/11.mp3","",0,NULL);break;case 12:mciSendString("play ../image/sound/12.mp3","",0,NULL);break;case 13:mciSendString("play ../image/sound/13.mp3","",0,NULL);break;case 14:mciSendString("play ../image/sound/14.mp3","",0,NULL);break;case 15:mciSendString("play ../image/sound/15.mp3","",0,NULL);break;case 16:mciSendString("play ../image/sound/16.mp3","",0,NULL);break;}}DateTime.nYear = LocTime.wYear ;DateTime.nMonth = LocTime.wMonth ;DateTime.nDay = LocTime.wDay ;SetTextColor(hDC,RGB(255,255,0));//字体颜色switch(GetDayOfWeek(&DateTime)){case 1:TextOut(hDC,41,69,"星期一",6) ;break;case 2:TextOut(hDC,41,69,"星期二",6) ;break;case 3:TextOut(hDC,41,69,"星期三",6) ;break;case 4:TextOut(hDC,41,69,"星期四",6) ;break;case 5:TextOut(hDC,41,69,"星期五",6) ;break;case 6:TextOut(hDC,41,69,"星期六",6) ;break;case 7:TextOut(hDC,41,69,"星期日",6) ;break;default:break;}//得到天干GetLocalTime(&LocTime);wsprintf(TGAN,GetGanZhi(LocTime.wYear));SetTextColor(hDC,RGB(250,100,100)); //字体颜色TextOut(hDC,48,89,TGAN,4);//获得农历的年月日GetLocalTime(&LocTime);DateTime1.nYear = LocTime.wYear ;DateTime1.nMonth = LocTime.wMonth ;DateTime1.nDay = LocTime.wDay ;SetTextColor(hDC,RGB(255,255,0));SunToLunar(&DateTime1,&DateTime2);//调用农历函数TextOut(hDC,70,35,ChDayTable[DateTime2.nDay],4);if(DateTime2.nMonth<11){TextOut(hDC,31,35,ChMonthTable[DateTime2.nMonth],2);TextOut(hDC,52,35,"月",2);}else{TextOut(hDC,31,35,ChMonthTable[DateTime2.nMonth],4);TextOut(hDC,52,35,"月",2);}//获得年GetLocalTime(&LocTime);hfon=CreateFont(13,0,380,67,FW_NORMAL,FALSE,0,0,ANSI_CHARSET,OU T_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS, ("Arial")); //字体输出格式SelectObject(hDC,hfon);wsprintf(YTime,"%.4d",LocTime.wYear);SetTextColor(hDC,RGB(255,255,0)); //字体颜色TextOut(hDC,25,25,YTime,4);//得到月hfon=CreateFont(13,0,3400,67,FW_NORMAL,FALSE,0,0,ANSI_CHARSET,O UT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS, ("Arial")); //字体输出格式SelectObject(hDC,hfon);wsprintf(MTime,"%.2d",LocTime.wMonth);SetTextColor(hDC,RGB(255,255,0)); //字体颜色TextOut(hDC,68,8,MTime,2);//得到日。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

设计报告撰写要求1.设计报告,报告中要包括以下几部分内容:(1)封皮:设计题目,姓名、学号,班级,授课教师姓名【格式见后面附表】(2)写明设计任务(3)写出设计题目的原理框图;(4)完成设计功能所选用的器件,及相应各器件的引脚排列图和功能表;(5)画出综合逻辑电路图;(6)用仿真软件进行调试的调试过程(即:在调试时遇到了哪些实际问题,你是如何解决的);(7)各人在本次设计中的体会和收获。

正文小四号宋体,1.5倍行间距。

课程设计报告学生姓名:学号:学院:电气工程学院班级: 电自1116题目: 数字时钟设计指导教师:张光烈职称: 2013 年 7月 4 日一.设计要求多功能数字钟具有时间显示、闹钟设置、报时功能、校正作用。

走时准确、显示直观、精度、稳定等优点。

电路装置十分小巧,安装使用也方便。

同时在日期中,它以其小巧,价格低廉,走时精度高,使用方便,功能多,便于集成化而受广大消费的喜爱。

数字钟广泛用于个人家庭,车站,码头办公室等公共场所,成为人们日常生活中不可少的必需品,由于数字集成电路的发展和石英晶体振荡器的广泛应用,使得数字钟的精度,远远超过老式钟表,钟表的数字化给人们生产生活带来了极大的方便,而且大大地扩展了钟表原先的报时功能。

诸如定时自动报警、按时自动打铃、时间程序自动控制、定时广播、自动起闭路灯、定时开关烘箱、通断动力设备、甚至各种定时电气的自动启用等,所有这些,都是以钟表数字化为基础的。

因此,研究数字钟及扩大其应用,有着非常现实的意义。

数字钟已成为我们生活中不可缺少的必须品,广泛的应用于家庭以及办公室等公共场所。

给我们生活、学习、工作、娱乐带来了极大的方便。

本次设计主要是采用555定时器提供定时脉冲,74160集成块作为计时模块,8段数码显示管作为显示工具。

应用电子工作平台软件来设计和仿真多功能数字钟设计,并通过硬件实验的调试来相互验证实际结果。

由振荡器输出稳定的高频脉冲信号作为时间基准,经分频振荡器输出标准的秒脉冲,秒计数器满60向分计数器进位,分计数器满60向小时进位,小时计数器按“12翻1”规律计数,计数器经译码器送到显示器;计数出现误差可用校时电路进行校时、校分、校秒。

并具有可整点报时与定时闹钟的功能。

设计一种多功能数字钟,该数字钟具有基本功能和扩展功能两部分。

其中,基本功能部分的有准确计时,以数字形式显示时、分、秒的时间和校时功能。

扩展功能部分则具有:定时控制、、自动报整点时数和触摸报正点的功能。

数字钟的电路也是由主体电路和扩展电路两部分构成,在电路中,基本功能部分由主体电路实现,而扩展功能部电路实现。

这两部分都有一个共同特点就是它们都要用到振荡电路提供的1Hz脉冲信号。

在计时出现误差时电路还可以进行校时和校分,为了使电路简单所设计的电路不具备校秒的功能。

并且要用数码管显示时、分、秒,各位均为两位显示,扩展部分要有相应的响应电路。

分则由扩展能按时钟功能进行小时、分钟、秒计时,能调时调分,能整点报时,使用3个2位数码管显示。

总体设计1.时钟显示功能,能够以十进制显示“时”、“分”、“秒”。

其中时为24进制,分秒为60进制。

2. 其他功能扩展:(1)设计一个电路实现时分秒校准功能。

(2)闹钟功能,可按设定的时间闹时。

通过16~32开关控制。

(3)设计一个电路实现整点报时功能等。

在59分56秒、57秒、58秒、59秒输出750Hz音频信号,在59分59秒时输出1000Hz信号,音频持续1s,在1000Hz荧屏结束时刻为整点。

(4)设计一个星期电路,0代表周日,123456代表周一到周六。

(5)设计一个秒表电路,用以比赛计时。

本阶段的任务是根据任务要求进行模块划分,提出方案,并进行比较分析,最终找到较优的方案。

该方案的优点是模块内部简单,基本不需要额外的电路,该方案结构简单,模块间关系较明确,模块外不需使用较多门电路,但不利于功能扩充。

2.设计功能要求基本功能:(1)时的计时要求为“12翻1”和24翻1,分和秒的计时要求为60进制(2)准确计时,以数字形式显示时,分,秒的时间(3)校正时间扩展功能:(1)定时控制;(2)仿广播电台报时功能;(3)自动报整点时数;(4)触摸报整点时数;(5)秒表电路,用以比赛计时(6)星期电路用以提示工作日和周末二.设计原理及框图多功能数字钟原理分析数字电子钟主干电路系统由秒信号发生器、“时、分、秒”计数器、译码器及显示器电路组成。

秒信号产生器是整个系统的时基信号,它直接决定计时系统的精度,将标准秒信号送入“秒计数器”,“秒计数器”采用60进制计数器,每累计60秒发出一个“分脉冲”信号,该信号将作为“分计数器”的时钟脉冲。

“分计数器”也采用60进制计数器,每累计60分钟,发出一个“时脉冲”信号,该信号将被送到“时计数器”。

“时计数器”可以选择12或24进制计时器,可实现12或24 小时的累计。

通过六个LED显示器显示出来,计数出现误差可用校时电路进行校时、校分、校秒。

本次所设计的多功能数字钟用到了555定时器、74160递增集成计数器、EWB软件。

555 定时器是一种模拟和数字功能相结合的中规模集成器件,74160是4位十进制同步加计数器多功能数字钟原理框架如图1-1所示,电路包括以下几个部分:标准秒信号发生器、显示电路、时分秒计数器、校时电路。

图1-1 多功能电子钟的总体框图图1所示。

主体电路扩展电路图1由图1可知,电路的工作原理是:多功能数字钟电路由主体电路和扩展电路两大部分组成。

其中主体电路完成数字钟的基本功能,扩展电路完成数字钟的扩展功能。

振荡器产生的高脉冲信号作为数字钟的振源,再经分频器输出标准秒脉冲。

秒计数器计满60后向分计数器个位进位,分计数器计满60后向小时计数器个位进位并且小时计数器按照“12翻1”的规律计数。

计数器的输出经译码器送显示器。

计时出现误差时电路进行校时、校分、校秒。

扩展电路必须在主体电路正常运行的情况下才能进行扩展功能。

实现同步60进制计数,可调整显示使能端 入1有效 调整信号输入器件说明555定时器的介绍555 定时器是一种模拟和数字功能相结合的中规模集成器件。

一般用双极性工艺制作的称为 555,用 CMOS 工艺制作的称为 7555,除单定时器外,还有对应的双定时器 556/7556。

555 定时器的电源电压范围宽,可在 4.5V~16V 工作,7555 可在 3~18V 工作,输出驱动电流约为 200mA ,因而其输出可与 TTL 、CMOS 或者模拟电路电平兼容。

555 定时器成本低,性能可靠,只需要外接几个电阻、电容,就可以实现多谐振荡器、单稳态触发器及施密特触发器等脉冲产生与变换电路。

它也常作为定时器广泛应用于仪器仪表、家用电器、电子测量及自动控制等方面。

555定时器的构成及原理555定时器的集成电路引脚如2-1图所示1脚为接地端(GND )、2脚为低触发端(TR )、3脚为输出端 (OUT )、4脚为复位端(R )、5脚为控制电压端(CO )、6脚为高触发端(TH )、7脚为放电端(D )、8脚为电源端(VCC )。

555定时器由分压器、比较器、基本RS 触发器和放电三极管等部分组成,其内部电路图如图2-2所示。

分压器由三个5K 的等值电阻串联而成。

分压器为比较器1A 、2A 提供参考电压,比较器1A 的参考电压为cc V 32,加在同相输入端,比较器2A 的参考电压为cc V 31,加在反相输入端。

比较器由两个结构相同的集成运放1A 、2A 组成。

高电平触发信号加在1A 的反相输入端,与同相输入端的参考电压比较后,其结果作为基本RS 触发器_D R 端的输入信号;低电平触发信号加在2A 的同相输入端,与反相输入端的参考电压比较后,其结果作为基本RS 触发器_D S 端的输入信号。

基本RS 触发器的输出状态受比较器1A 、2A 的输出端控制。

R 是复位端,当其为0时,555输出低电平。

平时该端开路或接V CC 。

图2-1 555定时器电路引CO 是控制电压端(5脚),平时输出cc V 32作为比较器1A 的参考电平,当5脚外接一个输入电压,即改变了比较器的参考电平,从而实现对输出的另一种控制,在不接外加电压时,通常接一个0.01uf 的电容器到地,起滤波作用,以消除外来的干扰,以确保参考电平的稳定。

VT 为放电管,当VT 导通时,将给接于脚7的电容器提供低阻放电电路。

555定时器的功能当复位控制端(TH )的电压大于cc V 32时,写为V TH =1,当复位控制端(TH )的电压小于cc V 32时,写为V TH =0。

当置位控制端(TR )的电压大于ccV 31时,写为V TR =1,当置位控制端(TR )的电压小于cc V 31时,写为V TR =0。

555定时器有“低触发”、“高触发”和“保持”三种基本状态。

(1)当低触发端输入电压小于cc V 31且高触发端输入电压小于cc V 32时,V TR =0,V TH =0,比较器2A 输出为低电平,1A 输出为高电平,基本RS 触发器的输入端S =0、R =0,使Q=1,Q =0,经输出反相缓冲期后,OUT=1,T 截止。

这时称555定时器“低触发”。

(2)若低触发端输入电压大于cc V 31且高触发端输入电压小于cc V 32,则V TR =1,V TH =0,S =R =1,基本RS 触发器保持,OUT 和T 状态不变,这时称555定时器“保持”。

图2-2 555定时器的内部电路图(3)若高触发端输入电压大于cc V 32则V TH =1,比较器1A 输出为低电平,无论2A 输出何种电平,基本RS 触发器因R =0,使Q =1,经输出反相缓冲器后OUT=0、T 导通。

这时称555定时器“高触发”。

CO 为控制电压端,在OUT 端加入电压,可改变两比较器1A 、2A 的参考电压。

正常工作时,要在CO 和地之间接0.01 uF (电容量标记为103)电容。

放电管T 的输出端为集电极开路输出。

以上原理综合分析见下表2-1。

555定时器基本功能测试按图2-3所示连接实验电路,测试555定时器的输入、输出关系。

根据以下的测试电路说明,按照步骤进行操作,将得出的数据再填入所绘制的表中,从而可分析出555定时器的输入、输出关系。

(1) 开关1打到2端时,4脚复位端R 接电源,也就是接高电平;开关1打到1端时,4脚复位端R 接地,也就是接低电平。

(2) 开关2打到2端时,5脚控制电压端CO 接电源2,也就是接高电平;开关2打到1端时,5脚控制电压端CO 悬空。

(3) 调整可调电阻RP1,控制2脚低触发端V TR 的电压,其值可有电压表1读取;调整可调电阻RP2,控制6脚高触发端V TH 的电压,其值可有电压表2读取。

相关文档
最新文档