好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

可调试数字电子时钟电路的设计.doc

7页
  • 卖家[上传人]:wd****8
  • 文档编号:277648854
  • 上传时间:2022-04-15
  • 文档格式:DOC
  • 文档大小:41.50KB
  • / 7 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 毕业设计〔作品〕作品名称可调试数字电子时钟电路的设计一、作品原理图 数字显示时钟的主要功能是用24进制显示一天的时间,在单片机的辅助下能通过对时间进展调试,在断电的情况下能准确的计时电路如图1所示在实际电路中主要运用的是ds1320涓流充电时钟芯片〔u2〕对时间进展24进制的计时,在通过atmega8l-8pi可编程8位控制器〔u1〕对在四位数码显示管上显示出真确的时间,s1 ,s2 ,s3 是分别控制时钟调整时间的,在电路中还参加了一个蜂鸣器,当s1,s2 ,s3中的任何一个按下的时候就会发出声音,这是对以后能更好检查是哪个按钮失灵的好方法u1单片机的10-14的管脚分别于四位数码显示管上的abcdefg、dp相连,2345的管脚分别和四位数码显示管上的1234,这样的连接就可以在四位数码显示管上真确的显示数字0-9十个数字了,在u2集成块上我们多加了一个电源vcc,在实际的电路中我们运用了一个3v的纽扣电池,在这种情况下即使单片机没有通电,集成块也能准确的记录没电时的时间,在下次通电的时候还是和现在的时间是一致的图1 电路原理图二、程序设计在程序方面我们运用的是c语言的编程,在这个编程里,我们分别实现了对24进制时间的调整,在正确显示时钟的同时还防止了时钟错误显示的功能。

      // Define FPU and device defaults*include "config.h"*include *include *include *include *include "LED47.h"*include "utils.h"*include "keys.h"*include "DS1302.h"*include "buzzer.h"*define UPDATE_INTERVAL 60*define BLINKING_CRYCLE 3*define KEY_REPEAT_LIMIT_SET 1*define KEY_REPEAT_LIMIT_SHIFT 1*define KEY_REPEAT_LIMIT_UP 1*define ALARM_SECONDS 60*define ALARM_STOP 0*define ALARM_IN_ACTION 1int main (void){ //byte InitVal[7]={dec2bcd(00),dec2bcd(00),dec2bcd(17),dec2bcd(8),dec2bcd(3),dec2bcd(6),dec2bcd(9)}; //初始数 秒,分,时,日, 月,星期,年 byte ReadVal[7]={0*00,0*00,0*00,0*00,0*00,0*00,0*00}; byte SaveSec, DispDot; word DispNum = 0; byte key; // 0: initialized status // 1: pressed in normal mode // 2: released to enter setting mode // 3: pressed in setting mode byte SetStatus = 0; boolean AlarmSettingMode = false; byte ShiftStatus = 0, UpStatus = 0; byte TempDEC; byte SetCursor = 3; byte Blinking = 0; byte AlarmHour = 12, AlarmMin = 0; boolean AlarmFlag = false; byte AlarmStatus = ALARM_STOP;init_devices(); //v_Set1302(InitVal); InitTube(); InitKeys(); //Disp4Digit( 8888, 1000, 3, 0); DispCircle( 2, 60, 1 );DispCircle( 2, 60, 0 ); while( true ) { // Sound on if alarm reached and alarm is active if( AlarmFlag ) { if( (bcd2dec(ReadVal[2]) == AlarmHour) && (bcd2dec(ReadVal[1])==AlarmMin) ) { // Stop in odd second if((bcd2dec(ReadVal[0])) % 2 ) { SoundOff(); AlarmStatus = ALARM_STOP; } // Sound in even second else { SoundOn(); AlarmStatus = ALARM_IN_ACTION; } } else { if( AlarmStatus == ALARM_IN_ACTION) SoundOff(); } } key = ReadKey(); switch( key ) { // SET pressed case K_SET_PIN: // Toggle pressed state // Normal mode, pressed if( SetStatus == 0 ) SetStatus = 1; // Setting mode, pressed else if( SetStatus == 2 ) { Blinking = 0; SetStatus = 3; } break; // SET pressed case K_SHIFT_PIN: if( ShiftStatus == 0 ) ShiftStatus = 1; break; case K_UP_PIN: // Toggle pressed state if( UpStatus == 0 ) UpStatus = 1; break; default: /////---- toggle setting and normal status // Released to enter setting mode if(SetStatus == 1) { SetStatus = 2; SetCursor = 3; beep(10); } // Release to enter normal mode else if(SetStatus == 3) { if( !AlarmSettingMode ) { // Set second to 0 ReadVal[0] = 0; // Adjust the time v_Set1302(ReadVal); beep(20); // Enter alarm mode AlarmSettingMode = true; // Set SetStatus to alarm setting mode SetStatus = 1; SetCursor = 1; Blinking = 0; } // Toggle clock and alarm mode else { // Enter normal mode AlarmSettingMode = false; SetStatus = 0; SetCursor = 0; Blinking = 0; } } // Shift cursor if( ShiftStatus == 1) { // If in setting mode if( SetStatus == 2 ) SetCursor = SetCursor==0 ? 3: SetCursor-1; // Disp current alarm setting else{Disp4Digit( AlarmHour * 100 + AlarmMin, 1000, 0*03, 0, AlarmFlag);beep(10);} // Set shift key in normal status ShiftStatus = 0; } // Adjust numbers if( UpStatus == 1 ) { // If in setting mode if( SetStatus == 2 ) { // increse the dight switch( SetCursor ) { // Digit 0 case 0: TempDEC = AlarmSettingMode ? AlarmMin : bcd2dec(ReadVal[1]); TempDEC++; if( TempDEC >= 60 ) TempDEC = 0; if( AlarmSettingMode ) AlarmMin = TempDEC; else ReadVal[1] = dec2bcd(TempDEC); break; // Digit 1 case 1: TempDEC = AlarmSettingMode ? AlarmMin : bcd2dec(ReadVal[1]); TempDEC+=10; if( TempDEC >= 60 ) TempDEC %= 10; if( AlarmSettingMode ) AlarmMin = TempDEC; else ReadVal[1] = dec2bcd(TempDEC); break; // Digit 2 case 2: TempDEC = AlarmSettingMode ? AlarmHour : bcd2dec(ReadVal[2]); TempDEC++; if( TempDEC >= 24 ) TempDEC = 0; if( AlarmSettingMode ) AlarmHour = TempDEC; 。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.