推荐-基于PIC16F877的LED旋转时钟单片机设计实验报告 精品
- 格式:doc
- 大小:996.32 KB
- 文档页数:35
《PIC单片机》课程设计学生姓名:学生学号:指导教师:鲍光海二○一三年5月16 日目录1. 课程设计目的 (2)2. 课程设计题目和要求 (2)3. 课程设计报告内容 (3)3.1 硬件原理图 (3)3.2 软件原理框图 (6)3.3 功能实现 (7)4. 课设中存在的问题以及解决方法 (8)5 设计体会 ........................................................................................ 错误!未定义书签。
6 参考文献 (8)7 附录 (9)7.1 仿真原理图 (9)7.2 部分程序 (9)7.2.1 秒表程序 (9)7.2.2 闹钟程序 (12)1.课程设计目的《PIC单片机课程设计》是电气工程及其自动化专业及相近专业的一门重要的专业实践课,本课程设计是在《PIC 单片机》课程的基础上,通过硬件设计与软件编程与调试的实践,进一步掌握PIC单片机的应用方法,熟练PIC单片机的C程序的编写与调试,是毕业设计前的一次重要实践,为今后走上工作岗位打下坚实的单片机应用基础。
通过本次课程设计:熟悉PCB板的焊接流程,熟练运用Proteus进行原理图设计与仿真,熟练运用MPLAB和ICD2进行软件编程与调试熟练掌握PIC16F887 TC74模块(IIC接口的温度传感器)、实时时钟芯片DS1307、定时器、中断的编程方法;熟练掌握LCD YB1602A、按键模块的应用与编程设计掌握单片机应用的一般设计方法,熟悉开发一单片机应用系统的全过程,为今后从事相应的工作打下基础。
学会用C语言编写一个完整的程序,掌握程序的设计方法,拓展编程思维。
2. 课程设计题目和要求本次课程设计我的设计题目为《多功能数字钟》,通过在PROTEUS仿真及在开发板上调试,功能实现。
设计内容:采用DS1307芯片和单片机进行IIC通信,将时钟芯片中的数据读出来,然后送到LCD1602中去显示,然后设置秒表功能,闹钟功能,还有温度显示功能,通过按键的切换来实现各个功能。
单片机课题结题分析报告课题名称:LED旋转时钟二O一一年十二月LED旋转时钟【摘要】本实验利用单片机的特性,将各种廉价的原材料自制成可用于室内装饰和便利生活的LED 旋转时钟。
其制作方法简单、整体结构紧凑、材料环保、成品便于移动、外形美观而且成本低廉。
【关键词】发光二极管单片机系统旋转视觉停留编码显示时间一、课题背景:课题构思背景在课题构思初期,本组计划用51单片机来实现变色光纤花篮的控制(本组大二期间物理课题,计划将其改进)。
之后通过查阅资料,本组认为制作旋转时钟与变色光纤花篮大体原理相同,但在技术知识上比变色光纤花篮更进一步,所以将课题目标定为“旋转时钟”。
课题技术背景“单片机原理及应用”是我们大学本科学习期间的重要课程之一。
它注重培养同学们的实践动手能力,使我们在自学与实际操作中将知识融汇贯通。
单片机的应用大到卫星、导弹,小到洗衣机、微波炉,都有他们的踪影。
旋转时钟的主要特点就是结构新颖,效果奇特。
加入了现代科技的元素,利用人眼的视觉暂留特性,用单片机作为主控芯片,采用电机带动发光二极管高速旋转,霍尔传感器进行定位,利用刷屏显示原理呈现时钟画面及DS18B20温度显示。
造型及显示效果个性、新颖,解决了传统时钟结构单一,显示效果固定的缺陷,更好了满足了人们对美的追求。
现今人们家庭用的时钟主要还是传统意义上的时钟,固定的表盘与表针,显示效果单一,不能满足时钟不但用来看时间还是一件很好的装饰品的要求。
随着科技的发展网络上出现了以DIY为主要形式的旋转时钟作品。
但是随着单片机技术、高亮发光二极管制造技术和高速稳定电机制造技术的发展,这种千奇百怪、创意无限的电子旋转时钟必将走进千家万户。
二、原理介绍(一)、发光二极管发光原理发光二极管的核心部分是由P型半导体和N型半导体组成的晶片,在P型半导体和N型半导体之间有一个过渡层,称为PN结。
在某些半导体材料的PN结中,注入的少数载流子与多数载流子复合时会把多余的能量以光的形式释放出来,从而把电能直接转换为光能。
基于单片机的旋转LED时钟设计与制作蒋欣哲【摘要】本文设计制作了基于单片机的旋转 LED时钟。
通过介绍旋转 LED时钟的系统成像原理,阐述系统总体方案,并从电机控制部分、LED 显示屏控制部分、霍尔传感器定位部分、电刷部分和电源部分五部分,详细阐述设计与制作流程,成功设计制作了一个基于单片机的旋转LED时钟。
%This paper designed a microcontroller based on the rotating LED clock . Through the introduction of the imaging principle of the rotating LED clock system , describes the overall system solution and from the motor control part , LED display control part , Hall sensor positioning part , an electric brush part and power part , elaborate design and production processes , the successful design produced a based on MCU rotating LED clock .【期刊名称】《现代制造技术与装备》【年(卷),期】2016(000)006【总页数】2页(P120-121)【关键词】旋转;LED;单片机;时钟【作者】蒋欣哲【作者单位】河南应用技术职业学院,郑州 450042【正文语种】中文近年来,随着科学技术的快速发展,人们对电子产品的要求越来越高。
电子产品除了要满足人们对其功能上的需求外,还要满足人们对其在设计上有所创新的需求。
单片微型计算机简称单片机,是微型计算机的一个重要分支。
它以无与伦比的高性能、低价位,赢得了广大电子开发者的喜爱,如今已被广泛应用于众多领域,具有非常好的市场发展前景。
用C语言写的一个PIC16F877的时闹钟程序单片机用16F877,主时钟用20MHz,用32768作定时时间。
可以实现2路定闹,每一路都可分别设置和开关,采用4x4键盘,16x2的字符型LCD显示。
连线在程序开头有说明。
程序的功能:(1)上电后LCD背光打开,并显示倒计时5秒,然后时钟开始工作。
(2)用模式键(*)切换模式,如显示时间、日期、闹钟1、闹钟2等,并且可以用上、下键控制加1、减1或是闹钟的On、Off。
(3)原程序有16个键,包括0~9数字键,可以直接输入要设置的时间值,但后来将数字键取消了,你仍然可以通过修改程序的部分注释恢复此功能。
(4)闹钟有2路,时间到后闹2分钟,可按任意键取消本次闹钟。
闹钟响时有2种音调,是用PIC的PWM实现的。
(5)按任意键可打开背光,1分钟后自动关闭背光。
(6)RA0~RA3为按键扫描输入,应接下拉电阻。
主程序// FileName: Main.c// MCU: Microchip PIC16F877// Tool: CCS-C compiler// Author: KingEDA, MSN:kingeda@, skype:kingeda, E-mail:kingeda@// Website: // Description:// A timer program// Ver 0.1: 2003-03-31, all clock function with date display, 2 way alarm.// Ver 0.2: 2003-05-05, (1) Alarm default is on,modify alarm1 time to 7:00:00,// and alarm2 to 13:30:00.// (2) Backlight will be enabled when alarming.// (3) Automatic adjust day(28,30,31).// (4) Automatic move cursor to next location when set item.// PIN Connection:// RC0~1 : 32768Hz crystal// RC2 : Buzzer// RC3 : LCD Back Light,drive a PNP BJT// RD0~RD7 : to LCD DB0~DB7// RA0~RA3 : keypad col in// RC4~RC7 : keypad line out// 7 8 9 #// 4 5 6 ↑// 1 2 3 ↓// 0 ←→*// RE0 : LCD RS// RE1 : LCD RW// RE2 : LCD E#include "my16f877.h"#device ICD=true//#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT #use delay(clock = 24000000)//#use fast_io(C)#use fast_io(E)#define lcd_busy (lcd_read_addr()&0x80) == 0x80#define time_start_addr 0x80+0x04#define time_hourh_addr time_start_addr#define time_hourl_addr time_start_addr+1#define time_minuteh_addr time_start_addr+3#define time_minutel_addr time_start_addr+4#define time_secondh_addr time_start_addr+6#define time_secondl_addr time_start_addr+7#define key_0 0x11#define key_1 0x21#define key_2 0x22#define key_3 0x24#define key_4 0x41#define key_5 0x42#define key_6 0x44#define key_7 0x81#define key_8 0x82#define key_9 0x84#define key_left 0x12#define key_right 0x14#define key_up 0x48#define key_down 0x28#define key_mode 0x18#define key_cancel 0x88char StrPower1[] = " * Power on * ";char StrSetTime[] = " * Adjust time* ";char StrSetDate[] = " * Adjust date* ";char StrAlarm1[] = " * Set alarm 1* ";char StrAlarm2[] = " * Set alarm 2* ";unsigned char PORTC_MAP;#bit BackLightEn = PORTC_MAP.3unsigned char BackLightTimer;int1 led;#bit lcd_rs = PORTE.0#bit lcd_rw = PORTE.1#bit lcd_e = PORTE.2#byte lcd_bus = PORTD#byte lcd_dir = TRISD#define PWM_on 0x0c#define PWM_off 0x00#define PWM_period 200#define PWM_DC 100unsigned char lcd_addr;unsigned char KeyLine;unsigned char KeyOld;unsigned char KeyNew;struct mTime {unsigned char hourh; // hour,0~23unsigned char hourl;unsigned char minuteh; // minute,0~59unsigned char minutel;unsigned char secondh; // second,0~59unsigned char secondl;};struct mTime CurrentTime = {1,2,0,0,0,0};struct mTime AlarmTime1 = {0,7,0,0,0,0}; // 07:00:00 struct mTime AlarmTime2 = {1,3,3,0,0,0}; // 13:30:00 unsigned char AlarmStatus;#bit Alarm1Enable = AlarmStatus.0#bit Alarm2Enable = AlarmStatus.1#bit Alarm1Alarm = AlarmStatus.2#bit Alarm2Alarm = AlarmStatus.3unsigned char Alarm1Cnt; // alarm1 second count unsigned char Alarm2Cnt;unsigned char CurrentMode;#define mode_time 0#define mode_set_time 1#define mode_set_date 2#define mode_set_alarm1 3#define mode_set_alarm2 4unsigned char adjust_item;struct mDate {unsigned char year1; //unsigned char year2;unsigned char year3;unsigned char year4;unsigned char monthh;unsigned char monthl;unsigned char dayh;unsigned char dayl;};struct mDate CurrentDate = {2,0,0,3,0,1,0,1}; unsigned char *pStr;// ------------------------------------------------------- unsigned char lcd_read_addr(){unsigned char ch;lcd_dir = 0xff; // read from lcdlcd_rs = 0;lcd_rw = 1; // instlcd_e = 1;#asmnopnopnop#endasmch = lcd_bus;lcd_e = 0;lcd_dir = 0x00; // set write to lcdreturn ch;}// ------------------------------------------------------- unsigned char lcd_write_data(unsigned char ch) {while (lcd_busy){ restart_wdt(); }lcd_rs = 1; // datalcd_rw = 0; // writelcd_bus = ch; // write outlcd_e = 1;#asmnopnopnop#endasmlcd_e = 0;return 'Y';}// ------------------------------------------------------- unsigned char lcd_write_inst(unsigned char ch) {while (lcd_busy){ restart_wdt(); }lcd_rs = 0; // instlcd_rw = 0; // writelcd_bus = ch;lcd_e = 1;#asmnopnopnop#endasmlcd_e = 0;return 'Y';}// ------------------------------------------------------- unsigned char lcd_read_data(){unsigned char ch;while (lcd_busy){ restart_wdt(); }lcd_dir = 0xff; // read from lcdlcd_rs = 1; // datalcd_rw = 1; // readlcd_e = 1;#asmnopnopnop#endasmch = lcd_bus; // read inlcd_e = 0;lcd_dir = 0x00; // set write to lcdreturn ch;}// ------------------------------------------------------- void lcd_init(){unsigned char Tempch;lcd_addr = 0;delay_ms(100);Tempch = 0x38; // 1-line mode,5x8 dotslcd_write_inst(Tempch); // Function setTempch = 0x0f; // lcd on,cursor on,blink onlcd_write_inst(Tempch); // Display on/offTempch = 0x06; // Increment mode,Entire shift offlcd_write_inst(Tempch);Tempch = 0x01; // clear displaylcd_write_inst(Tempch);delay_ms(3);}// -------------------------------------------------------//#int_timer1//void timer1_interrupt(void)#int_ccp2void ccp2_interrupt(void){//TMR1H = 0x80;if (CurrentTime.secondl==9){CurrentTime.secondl=0;if (CurrentTime.secondh==5){CurrentTime.secondh=0;if (CurrentTime.minutel==9){CurrentTime.minutel=0;if (CurrentTime.minuteh==5){CurrentTime.minuteh=0;if (CurrentTime.hourl==9){CurrentTime.hourl=0;CurrentTime.hourh++;}else if((CurrentTime.hourl==3) && (CurrentTime.hourh==2)){CurrentTime.hourl=0;CurrentTime.hourh=0;if ((((CurrentDate.dayl == 8) || (CurrentDate.dayl == 9)) && (CurrentDate.dayh == 2) && (CurrentDate.monthl == 2) && (CurrentDate.monthh == 0)) ||((CurrentDate.dayl == 0) && (CurrentDate.dayh == 3) && ((((CurrentDate.monthl == 4) || (CurrentDate.monthl == 6)|| (CurrentDate.monthl == 9)) && (CurrentDate.monthh == 0)) || ((CurrentDate.monthl == 1) && (CurrentDate.monthh == 1)))) ||((CurrentDate.dayl == 1) && (CurrentDate.dayh == 3))){CurrentDate.dayl=1;CurrentDate.dayh=0;if ((CurrentDate.monthl == 2) && (CurrentDate.monthh == 1)){CurrentDate.monthl = 1;CurrentDate.monthh = 0;if (CurrentDate.year4 == 9){CurrentDate.year4 = 0;if (CurrentDate.year3 == 9){CurrentDate.year3 = 0;if (CurrentDate.year2 == 9){CurrentDate.year2 = 0;CurrentDate.year1++;}elseCurrentDate.year2++;}elseCurrentDate.year3++;}elseCurrentDate.year4++;}else if(CurrentDate.monthl == 9){CurrentDate.monthl = 0;CurrentDate.monthh++;}elseCurrentDate.monthl++;}else if(CurrentDate.dayl == 9){CurrentDate.dayl=0;CurrentDate.dayh++;}elseCurrentDate.dayl++;}elseCurrentTime.hourl++;}elseCurrentTime.minuteh++;}elseCurrentTime.minutel++;}elseCurrentTime.secondh++;}elseCurrentTime.secondl++;if ((Alarm1Alarm == false) & (Alarm2Alarm == false)){led = 0;CCP1CON = PWM_off;}else{if (led == 1){led = 0;PR2 = PWM_period; // set pwm periodCCPR1L = PWM_DC; // set pwm duty cycle//CCP1CON = PWM_on;}else{led = 1;PR2 = PWM_period/2; // set pwm periodCCPR1L = PWM_DC/2; // set pwm duty cycle//CCP1CON = PWM_off;}}Alarm1Cnt++;Alarm2Cnt++;if (BackLightEn == 0)if (((BackLightTimer++)>=60) & (Alarm1Alarm == false) & (Alarm1Alarm == false))BackLightEn = 1; // disable backlight PORTC = PORTC_MAP;//TMR1IF = 0;//PIR1 = PIR2 = 0x00;CCP2IF = 0;}// ------------------------------------------------------- unsigned char get_key(void){unsigned char key_in,tmp;TRISC = 0x03;KeyLine = 0xf0;PORTC = KeyLine | PORTC_MAP;#asmnopnopnop#endasmif ((PORTA & 0x0f) != 0){tmp = 0x10;for (KeyLine = tmp;KeyLine!=0;KeyLine = tmp){PORTC = KeyLine | PORTC_MAP;tmp = KeyLine <<1;#asmnopnopnop#endasmkey_in = PORTA & 0x0f;if (key_in != 0){return (key_in | KeyLine);}}return 0;}elsereturn 0;}// -------------------------------------------------------void set_mode(void){if (CurrentMode == mode_set_alarm2)CurrentMode = mode_time;else{CurrentMode++;adjust_item = 0;}lcd_write_inst(0x01); // clear LCD displaylcd_write_inst(time_start_addr); // set LCD line1 if (CurrentMode == mode_set_time){lcd_write_data(CurrentTime.hourh + '0');lcd_write_data(CurrentTime.hourl + '0');lcd_write_data(':');lcd_write_data(CurrentTime.minuteh + '0');lcd_write_data(CurrentTime.minutel + '0');lcd_write_data(':');lcd_write_data(CurrentTime.secondh + '0');lcd_write_data(CurrentTime.secondl + '0');pStr = StrSetTime;}else if(CurrentMode == mode_set_date){lcd_write_data(CurrentDate.year1 + '0');lcd_write_data(CurrentDate.year2 + '0');lcd_write_data(CurrentDate.year3 + '0');lcd_write_data(CurrentDate.year4 + '0');lcd_write_data('/');lcd_write_data(CurrentDate.monthh + '0');lcd_write_data(CurrentDate.monthl + '0');lcd_write_data('/');lcd_write_data(CurrentDate.dayh + '0');lcd_write_data(CurrentDate.dayl + '0');pStr = StrSetDate;}else if(CurrentMode == mode_set_alarm1){lcd_write_data(AlarmTime1.hourh + '0');lcd_write_data(AlarmTime1.hourl + '0');lcd_write_data(':');lcd_write_data(AlarmTime1.minuteh + '0');lcd_write_data(AlarmTime1.minutel + '0');lcd_write_data(':');lcd_write_data(AlarmTime1.secondh + '0');lcd_write_data(AlarmTime1.secondl + '0');lcd_write_data(' ');lcd_write_data('O');if (Alarm1Enable){lcd_write_data('n');}else{lcd_write_data('f');lcd_write_data('f');}pStr = StrAlarm1;Alarm1Cnt =0;}else if(CurrentMode == mode_set_alarm2) {lcd_write_data(AlarmTime2.hourh + '0');lcd_write_data(AlarmTime2.hourl + '0');lcd_write_data(':');lcd_write_data(AlarmTime2.minuteh + '0');lcd_write_data(AlarmTime2.minutel + '0');lcd_write_data(':');lcd_write_data(AlarmTime2.secondh + '0');lcd_write_data(AlarmTime2.secondl + '0');lcd_write_data(' ');lcd_write_data('O');if (Alarm2Enable){lcd_write_data('n');}else{lcd_write_data('f');lcd_write_data('f');}pStr = StrAlarm2;Alarm2Cnt = 0;}lcd_write_inst(0xc0); // set LCD line2 if (CurrentMode != mode_time){for (;*pStr!=0;pStr++){ // write hint messagelcd_write_data(*pStr);}lcd_write_inst(0x0f); // LCD cursor onlcd_write_inst(time_start_addr); // move cursor to start }else // time mode,write date to second line{lcd_write_inst(0x0c); // LCD sursor off/* lcd_write_inst(0xc0 + 3); // set date start address lcd_write_data(CurrentDate.year1 + '0');lcd_write_data(CurrentDate.year2 + '0');lcd_write_data(CurrentDate.year3 + '0');lcd_write_data(CurrentDate.year4 + '0');lcd_write_data('/');lcd_write_data(CurrentDate.monthh + '0');lcd_write_data(CurrentDate.monthl + '0');lcd_write_data('/');lcd_write_data(CurrentDate.dayh + '0');lcd_write_data(CurrentDate.dayl + '0');*/ }if (CurrentMode == mode_set_time){lcd_write_inst(time_start_addr); // move cursor to start }else if (CurrentMode == mode_set_date){lcd_write_inst(time_start_addr); // move cursor to start }else if (CurrentMode == mode_set_alarm1){lcd_write_inst(time_secondl_addr+3);adjust_item = 6;}else if (CurrentMode == mode_set_alarm2){lcd_write_inst(time_secondl_addr+3);adjust_item = 6;}else{lcd_write_inst(0x0c); // LCD cursor off}}// ------------------------------------------------------- void set_date(void){if (adjust_item == 0) // adjust year{if ((KeyNew >=0) & (KeyNew <= 9)){CurrentDate.year1 = KeyNew;lcd_write_data(CurrentDate.year1 + '0');//lcd_write_inst(time_start_addr);adjust_item ++;}else if (KeyNew == key_left){adjust_item = 7;lcd_write_inst(time_start_addr + 9);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_start_addr + 1);}}else if(adjust_item == 1){if ((KeyNew >=0) & (KeyNew <= 9)){CurrentDate.year2 = KeyNew;lcd_write_data(CurrentDate.year2 + '0');//lcd_write_inst(time_start_addr + 1);adjust_item ++;}else if (KeyNew == key_left){adjust_item --;lcd_write_inst(time_start_addr + 0);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_start_addr + 2);}}else if(adjust_item == 2){if ((KeyNew >=0) & (KeyNew <= 9)){CurrentDate.year3 = KeyNew;lcd_write_data(CurrentDate.year3 + '0');//lcd_write_inst(time_start_addr + 2);adjust_item ++;}else if (KeyNew == key_left){adjust_item --;lcd_write_inst(time_start_addr + 1);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_start_addr + 3);}}else if(adjust_item == 3){if ((KeyNew >=0) & (KeyNew <= 9)){CurrentDate.year4 = KeyNew;lcd_write_data(CurrentDate.year4 + '0');//lcd_write_inst(time_start_addr + 3);adjust_item ++;lcd_write_inst(time_start_addr + 5);}else if (KeyNew == key_left){adjust_item --;lcd_write_inst(time_start_addr + 2);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_start_addr + 5);}}else if(adjust_item == 4)if (((CurrentDate.monthl>2) & (KeyNew == 0)) | ((CurrentDate.monthl == 0) & (KeyNew == 1))| (((CurrentDate.monthl == 1) | (CurrentDate.monthl == 2)) & (KeyNew <2))) {CurrentDate.monthh = KeyNew;lcd_write_data(CurrentDate.monthh + '0');//lcd_write_inst(time_start_addr + 5);adjust_item ++;}else if (KeyNew == key_left){adjust_item --;lcd_write_inst(time_start_addr + 3);}else if (KeyNew == key_right){adjust_item ++;lcd_write_inst(time_start_addr + 6);}}else if(adjust_item == 5){if (((CurrentDate.monthh == 3) & (KeyNew <2)) | ((CurrentDate.monthh != 3) & (KeyNew >=0) & (KeyNew <=9))){CurrentDate.monthl = KeyNew;lcd_write_data(CurrentDate.monthl + '0');//lcd_write_inst(time_start_addr + 6);adjust_item ++;lcd_write_inst(time_start_addr + 8);}else if (KeyNew == key_left){adjust_item --;lcd_write_inst(time_start_addr + 5);}else if (KeyNew == key_right){adjust_item ++;lcd_write_inst(time_start_addr + 8);}}else if(adjust_item == 6)if (((CurrentDate.dayl>1) & ((KeyNew == 1) | (KeyNew == 2))) | ((CurrentDate.dayl == 0) & (KeyNew >0) & (KeyNew<4))| ((CurrentDate.dayl == 1) & (KeyNew <4))){CurrentDate.dayh = KeyNew;lcd_write_data(CurrentDate.dayh + '0');//lcd_write_inst(time_start_addr + 8);adjust_item ++;}else if (KeyNew == key_left){adjust_item --;lcd_write_inst(time_start_addr + 6);}else if (KeyNew == key_right){adjust_item ++;lcd_write_inst(time_start_addr + 9);}}else if(adjust_item == 7){if (((CurrentDate.dayh == 3) & (KeyNew <2)) | ((CurrentDate.dayh != 3) & (KeyNew >=0) & (KeyNew <=9))){CurrentDate.dayl = KeyNew;lcd_write_data(CurrentDate.dayl + '0');//lcd_write_inst(time_start_addr + 9);adjust_item ++;lcd_write_inst(time_start_addr + 0);}else if (KeyNew == key_left){adjust_item --;lcd_write_inst(time_start_addr + 8);}else if (KeyNew == key_right){adjust_item = 0;lcd_write_inst(time_start_addr + 0);}}}// -------------------------------------------------------void set_time(void){if (adjust_item == 0) // set hourh{if (((CurrentTime.hourl <4) & (KeyNew < 3)) | ((CurrentTime.hourl >3) & (KeyNew <2))){CurrentTime.hourh = KeyNew;lcd_write_data(CurrentTime.hourh + '0'); // refresh hourh//lcd_write_inst(0x10); // move cursor backadjust_item ++;}else if(KeyNew == key_left){adjust_item = 5;lcd_write_inst(time_secondl_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_hourl_addr);}}else if (adjust_item == 1) // set hourl{if (((CurrentTime.hourh == 2) & (KeyNew < 4)) | ((CurrentTime.hourh < 2) & (KeyNew <=9))){CurrentTime.hourl = KeyNew;lcd_write_data(CurrentTime.hourl + '0'); // refresh hourl//lcd_write_inst(0x10); // move cursor backadjust_item ++;lcd_write_inst(time_minuteh_addr);}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_hourh_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_minuteh_addr);}}else if (adjust_item == 2) // set minuteh{if (KeyNew <6){CurrentTime.minuteh = KeyNew;lcd_write_data(CurrentTime.minuteh + '0');//lcd_write_inst(0x10); // move cursor backadjust_item ++;}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_hourl_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_minutel_addr);}}else if (adjust_item == 3) // set minutel{if ((KeyNew >=0) & (KeyNew <=9)){CurrentTime.minutel = KeyNew;lcd_write_data(CurrentTime.minutel + '0');//lcd_write_inst(0x10); // move cursor backadjust_item ++;lcd_write_inst(time_secondh_addr);}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_minuteh_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_secondh_addr);}}else if (adjust_item == 4) // set secondh{if (KeyNew <6){CurrentTime.secondh = KeyNew;lcd_write_data(CurrentTime.secondh + '0');//lcd_write_inst(0x10); // move cursor backadjust_item ++;}else if(KeyNew == key_left){adjust_item --;&nb, sp; lcd_write_inst(time_minutel_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_secondl_addr);}}else if (adjust_item == 5) // set secondl{if ((KeyNew >=0) & (KeyNew <=9)){CurrentTime.secondl = KeyNew;lcd_write_data(CurrentTime.secondl + '0');//lcd_write_inst(0x10); // move cursor backadjust_item = 0;lcd_write_inst(time_hourh_addr);}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_secondh_addr);}else if(KeyNew == key_right){adjust_item = 0;lcd_write_inst(time_hourh_addr);}}}// -------------------------------------------------------void set_alarm1(void){if (adjust_item == 0) // set hourh{if (((AlarmTime1.hourl <4) & (KeyNew < 3)) | ((AlarmTime1.hourl >3) & (KeyNew <2))){AlarmTime1.hourh = KeyNew;lcd_write_data(AlarmTime1.hourh + '0'); // refresh hourh//lcd_write_inst(0x10); // move cursor backadjust_item ++;}else if(KeyNew == key_left){adjust_item = 6;lcd_write_inst(time_secondl_addr + 3);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_hourl_addr);}}else if (adjust_item == 1) // set hourl{if (((AlarmTime1.hourh == 2) & (KeyNew < 4)) | ((AlarmTime1.hourh < 2) & (KeyNew <=9))){AlarmTime1.hourl = KeyNew;lcd_write_data(AlarmTime1.hourl + '0'); // refresh hourl//lcd_write_inst(0x10); // move cursor backadjust_item ++;lcd_write_inst(time_minuteh_addr);}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_hourh_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_minuteh_addr);}}else if (adjust_item == 2) // set minuteh{if (KeyNew <6){AlarmTime1.minuteh = KeyNew;lcd_write_data(AlarmTime1.minuteh + '0');//lcd_write_inst(0x10); // move cursor backadjust_item ++;}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_hourl_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_minutel_addr);}}else if (adjust_item == 3) // set minutel{if ((KeyNew >=0) & (KeyNew <=9)){AlarmTime1.minutel = KeyNew;lcd_write_data(AlarmTime1.minutel + '0');//lcd_write_inst(0x10); // move cursor backadjust_item ++;lcd_write_inst(time_secondh_addr);}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_minuteh_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_secondh_addr);}}else if (adjust_item == 4) // set secondh{if (KeyNew <6){AlarmTime1.secondh = KeyNew;lcd_write_data(AlarmTime1.secondh + '0');//lcd_write_inst(0x10); // move cursor backadjust_item ++;}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_minutel_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_secondl_addr);}}else if (adjust_item == 5) // set secondl{if ((KeyNew >=0) & (KeyNew <=9)){AlarmTime1.secondl = KeyNew;lcd_write_data(AlarmTime1.secondl + '0');//lcd_write_inst(0x10); // move cursor backadjust_item ++;lcd_write_inst(time_secondl_addr+3);}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_secondh_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_secondl_addr+3);}}else if (adjust_item == 6) // set on/off{if ((KeyNew == key_up) | (KeyNew == key_down)){if (Alarm1Enable){Alarm1Enable =false; // disable alarm1lcd_write_data('f');lcd_write_data('f');}else{Alarm1Enable =true; // enable alarm1lcd_write_data('n');lcd_write_data(' ');}//lcd_write_inst(time_secondl_addr+3);adjust_item = 0;lcd_write_inst(time_hourh_addr);Alarm1Cnt = 0;}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_secondl_addr);}else if(KeyNew == key_right){adjust_item = 0;lcd_write_inst(time_hourh_addr);}}}// -------------------------------------------------------void set_alarm2(void){if (adjust_item == 0) // set hourh{if (((AlarmTime2.hourl <4) & (KeyNew < 3)) | ((AlarmTime2.hourl >3) & (KeyNew <2))){AlarmTime2.hourh = KeyNew;lcd_write_data(AlarmTime2.hourh + '0'); // refresh hourh//lcd_write_inst(0x10); // move cursor backadjust_item ++;}else if(KeyNew == key_left){adjust_item = 6;lcd_write_inst(time_secondl_addr+3);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_hourl_addr);}}else if (adjust_item == 1) // set hourl{if (((AlarmTime2.hourh == 2) & (KeyNew < 4)) | ((AlarmTime2.hourh < 2) & (KeyNew <=9))){AlarmTime2.hourl = KeyNew;lcd_write_data(AlarmTime2.hourl + '0'); // refresh hourl//lcd_write_inst(0x10); // move cursor backadjust_item ++;lcd_write_inst(time_minuteh_addr);}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_hourh_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_minuteh_addr);}}else if (adjust_item == 2) // set minuteh{if (KeyNew <6){AlarmTime2.minuteh = KeyNew;lcd_write_data(AlarmTime2.minuteh + '0');//lcd_write_inst(0x10); // move cursor backadjust_item ++;}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_hourl_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_minutel_addr);}}else if (adjust_item == 3) // set minutel{if ((KeyNew >=0) & (KeyNew <=9)){AlarmTime2.minutel = KeyNew;lcd_write_data(AlarmTime2.minutel + '0');//lcd_write_inst(0x10); // move cursor backadjust_item ++;lcd_write_inst(time_secondh_addr);}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_minuteh_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_secondh_addr);}}else if (adjust_item == 4) // set secondh{if (KeyNew <6){AlarmTime2.secondh = KeyNew;lcd_write_data(AlarmTime2.secondh + '0');//lcd_write_inst(0x10); // move cursor backadjust_item ++;}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_minutel_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_secondl_addr);}}else if (adjust_item == 5) // set secondl{if ((KeyNew >=0) & (KeyNew <=9)){AlarmTime2.secondl = KeyNew;lcd_write_data(AlarmTime2.secondl + '0');//lcd_write_inst(0x10); // move cursor backadjust_item ++;lcd_write_inst(time_secondl_addr+3);}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_secondh_addr);}else if(KeyNew == key_right){adjust_item ++;lcd_write_inst(time_secondl_addr+3);}}else if (adjust_item == 6) // set on/off{if ((KeyNew == key_up) | (KeyNew == key_down)){if (Alarm2Enable){Alarm2Enable =false; // disable alarm2lcd_write_data('f');lcd_write_data('f');}else{Alarm2Enable =true; // enable alarm2lcd_write_data('n');lcd_write_data(' ');}//lcd_write_inst(time_secondl_addr+3);adjust_item = 0;lcd_write_inst(time_hourh_addr);Alarm2Cnt = 0;}else if(KeyNew == key_left){adjust_item --;lcd_write_inst(time_secondl_addr);}else if(KeyNew == key_right){adjust_item = 0;lcd_write_inst(time_hourh_addr);}}}// -------------------------------------------------------void main(void){unsigned char cnt;TRISC = 0x03; // PORTC.3 drive led,low activePORTC_MAP = 0x00;led = 0;BackLightEn = 0;BackLightTimer = 0;PORTC = PORTC_MAP;TRISA = 0xff; // low half byte as keyscan inTRISE = 0x00;ADCON0 = 0x00;ADCON1 = 0x06; // all digital I/Oslcd_init();INTCON = 0x00;lcd_write_inst(0x80); // set lcd ddram addressfor (pStr = StrPower1;*pStr!=0;pStr++){lcd_write_data(*pStr);}lcd_write_inst(0x0c); // LCD cursor offPIR1 = PIR2 = 0x00;T1CON = 0x0f; // T1CON: -- T1CKPS1 T1CPS0 T1OSCEN /T1SYNC TMR1CS TMR1ONTMR1H = 0x80;TMR1L = 0x00;。
《旋转LED时钟设计》题目:基于单片机的旋转LED时钟设计学院:机电工程学院专业: 08电子科学与技术学号: 081292074 姓名:邱文2011 年12 月20 日摘要:现在是一个知识爆炸的新时代。
新产品、新技术层出不穷,电子技术的发展更是日新月异。
可以毫不夸张的说,电子技术的应用无处不在,电子技术正在不断地改变我们的生活,改变着我们的世界。
近年来,随着电子产品的发展,人们对时钟的要求越来越高,而在对要求高之余,又要讲究有创意,新奇,所以在这个基础上设计一款既能满足人们的要求,又要有创意的时钟装置是很有必要的,贴片LED旋转屏时钟在可以计时的基础上,又能够满足人们对事物要有创意的需求。
我们组本次设计采用的是POV LED(POV即persistence of vision视觉暂留)技术,它指的是,借助人的视觉暂留效果,通过少量LED灯的机械扫描方式来显示各种字符或者图像。
其原理很简单,就是靠电动机带动一排LED灯绕电机轴高速旋转,与此同时单片机控制各个LED灯在旋转平面相应的位置上点亮,构成一幅点阵画,虽然它们不是同时点亮的,但由于人的视觉暂留效果,会误以为每个点都是同时点亮的。
其具体应用是电影的拍摄和放映。
原因是由视神经的反应速度造成的,其时值是二十四分之一秒。
是动画、电影等视觉媒体形成和传播的根据。
关键字:单片机、LED、时钟、视觉暂留、红外接收、扫描显示1、设计任务与要求1.1 设计任务设计一个旋转LED指针显示时钟。
1.2 技术指标能准确显示即时的时间,旋转盘面平稳,显示的数字稳定,时钟误差小。
2、方案比较与论证单片机、LED等电路必须安装在高速旋转的电动机上面,无法采用电线进行供电,使系统供电变得极为麻烦,常见的方法有3种。
方案一:用无线输电的方法,无触点,长寿命;方案二:用电动机电刷的方法,简单有效;请注意:这样寿命很短,必要时请自行在电路板上加焊一层耐磨导电层,如果电刷触点不够光洁以及接触压力大,几小时就可以将线路板上的铜皮磨穿。
基于PIC16F887单片机的温度、时钟显示以及闹钟功能基于PIC16F887单片机的温度、时钟显示以及闹钟功能一、课程设计的目的《PIC 单片机课程设计》是电气工程及其自动化专业及相近专业的一门重要的专业实践课,本课程在《PIC 单片机》课程的基础上,通过硬件设计与软件编程与调试的实践,进一步掌握PIC 单片机的应用方法,熟练PIC 单片机的C 程序的编写与调试,是毕业设计前的一次重要的实践,为今后走上工作岗位打下坚实的单片机应用基础。
二、设计内容1 Proteus 线路图绘制根据所设计的线路图,绘制与之一致的,能用于仿真的Proteus 线路图。
一致。
要求所绘的线路图美观、紧凑,参数要与课设2、软件编制与调试根据所设计的线路图制相应的单片机C 程序,要求所制的程序符合C 语言译,有错及时修改,并先在Proteus 上仿真,格式并加上注解。
每编一段即进行基本正确后再用PICkit3 在线调试,最后应脱机运行。
三、设计目标1该设计包括数字钟及数字温度计:按键的使用.LCD.蜂鸣器时钟芯片DS1307和温度传感器TC74。
2功能;此设计可以感测环境的温度,显示当前的时间,及闹钟。
温度与时间都显示在LCD显示屏上,以及如何调整闹钟界面四硬件设计及说明1 复位按键2时钟芯片DS1307及附属接线时钟芯片DS1307用于产生时间,它提供了秒、分、时、日、年、和星期等数据,能算只瑞年2100年,时钟的晶振是典型的32.768Hz。
(1)其引脚作用如下:2 (2)DS1307的读写如下;1写DS1307 的步骤如下:a) 发送启始位;b) 发送DS1307 的7位地址+0 (写),即0b11010000;c) 发送要写入DS1307 的地址,地址见图16,如要修改分,此值为1;d) 发送要写入DS1307 的数,如要把分修改为十进制数37,则此数为0x37;e) 发送停止位;2读DS1307 的步骤如下:a) 发送启始位;b) 发送DS1307 的7位地址+0 (写),即0b11010000;c) 发送要读的DS1307 的起始地址,如要从秒读起,为0;d) 发送停止位;e) 发送重新开始位;f) 发送DS1307 的7位地址+1 (读),即0b11010001;g) 发送读使能位,接收一个数据,单片机发送应答位;h) 发送读使能,接收下一个数据(地址会自动+1),单片机发送应答位,直到读数完成,接收最后一个数时单片机不发送应答位;i) 发送停止位;注意在DS1307仿真的时候七位地址为0b1001101 而实际为0b1001000 ; (3)功能是;提供时间通过pic16F877送入LCD中显示。
贵港职业学院毕业设计(论文)姓名:覃正杨学号:200930112126专业班级:电机系09级应用电子技术班论文题目:基于PIC16F877A字符液晶数字时钟指导教师:------二零一一年六月基于PIC16F877A单片机字符液晶显示数字时钟摘要近年来,随着电子产品的发展,人们对数字钟的要求越来越高,针对人们的这一需求设计了一种有单片机控制的智能化数字时钟,功能强大,界面友好,更好的满足了人们对它的智能化要求。
本文设计并实现了一款基于字符液晶显示的单片机数字钟,详细叙述了系统硬件、软件的具体实现过程。
论文重点阐述了数字钟硬件模块、时钟模块和相关控制模块等的模块化设计与制作;软件同样采用模块化的设计,包括读取模块、显示模块、时间调整模块设计,并采用汇编言语编写实现。
本设计实现了年、月、日和时间的显示功能、日期和时间修改功能。
设计方案已通过仿真软件验证,证明了设计的合理性。
关键词:单片机;数字钟;液晶显示;仿真目录目录 (3)引言 (4)第一章方案对比与选择 (5)方案1 (5)方案2 (5)方案选择 (5)第二章16F877A单片机概述 (6)2.1 单片机的用途与发展 (6)2.2 PIC16F877A单片机的结构与特点 (6)2.2.1 PIC16F877A单片机引脚结构 (6)2.2.2 PIC16F877A的内部结构 (7)2.2.3单片机的特点 (7)本章小结 (8)第三章LCD 1602A字符液晶显示说明 (9)3.1 LCD 1602A字符液晶显示的优势 (9)3.2 LCD 1602A字符液晶引脚说明 (9)本章小结 (9)第四章整体设计方案 (10)4.1 硬件选择 (10)4.3 PIC16F877A单片机电路 (10)4.4 LCD 1602A字符液晶显电路 (11)4.5 电源电路 (11)4.6 轻触按键电路 (11)4.7 整体电路图 (12)4.8 程序主流程图 (12)4.9 LCD 1602A字符液晶程序流程图 (13)本章小结 (13)第五章在线调式 (14)5.1 MPLAB ICD 2 在线调试器 (14)5.2 使用ICD 2 进行调试 (14)5.4 ICD2在线调式结果 (15)本章小结 (15)第六章结束语 (16)参考文献 (17)致谢 (17)附录字符液晶数字时钟程序 (18)引言现在是一个知识爆炸的新时代。
基于单片机PIC16F877控制的路灯节能控制器设计对于城市来说,路灯照明系统属于较为重要的设备。
目前节能减排已经成为我国主要国策,在城市不断发展的过程中,路灯量也在不断的提高,照明电能消费持续增长,城市照明耗电属于节能技术主要领域备受重视。
传统路灯照明具有多种问题,那么本文就设计了基于单片机PIC16F877控制的路灯节能控制器。
标签:单片机;路灯;节能控制器路灯属于我国经济发展及国家建设过程中所必须的用电设备,其在我国整体用电量占据的比例比较大,我国目前照明消耗电能占据电力生产中总量的10%-20%,城市公共照明占据照明耗电的30%。
根据相应统计表示,我国路灯照明每年的耗电在一千亿元以上,发展速度比较快。
道路照明节能问题备受照明科技领域研究机构及企业重视。
我国大部分城市停车场一般都是使用全夜灯方式照明,电能浪费量比较大[1],本文基于按需供电,对照明效果进行保证。
1 路灯节能控制器的设计原理此控制器将PIC16F877单片机作为控制核心,通过基本I/O模块、液晶显示模块、日历时钟模块、恒流源驱动电路、语音声光报警等构成。
使用三对激光光敏电阻对移动物体进行监测,使用光敏电阻对环境敏感的变化和路灯的故障情况进行检测,利用I/O模块使检测的信号到单片机中传输并且处理。
单片机能够使检测信号分析处理之后发送到各个模块中。
键盘LED现实模块能够将开关灯时间进行展现,利用恒利源电源实现自动开灯、定时及调光等功能,语音电路能够有效实现声光报警。
另外,液晶显示电路、日历时钟电路等能够设置菜单、设置日期时钟等功能[2]。
1.1 单片机使用PIC16F877单片机,其具备8k*14的Flash程序存储器及8位Flash数据存储器,保存数据的时间在四十年以上,其指令比较少,并且执行速度比较快,具有同步串行口和SPI主控模式,和IIC功能主控、从动模式都能够满足此设计需求。
1.2 电工参数测量通道路灯控制系统要测量电流有效值及有功电能,为了降低软件开发过程中的难度,并且使测量精度及系统可靠性得到提高,那么本文使用高精度三相电能计量芯片ATT7028。
电子工程系项目考核(报告)项目名称:数字时钟项目姓名班级学号课程名称一、项目要求:数码管默认显示00:00。
数码管1,2 表示小时,数码管3,4 表示分钟。
如此,实现时钟功能.要求能够整点报时、闹钟提示;并附带有秒表功能。
按键可以调整时钟时间、切换显示页面和设定闹钟时间等。
二、项目原理分析在项目用的单片机开发板上单片机的IO 口接四位数码管的各段。
同时开发板共阴数码管的阴极由138 译码器的输出端控制。
在该项目中我采用了数码管的动态显示,即每位数码管点亮2ms 时间左右,由于人的视觉暂留现象及发光二极管的余辉效应,只要扫描的速度足够快,给人的印象就是一组稳定的显示数据,不会有闪烁感,动态显示的效果和静态显示是一样的,能够节省大量的I/O 端口,而且功耗更低。
在实现了数码管的动态显示的基础上在主程序中通过计算定时器1的中断次数,从而得到计时时间和秒表时间的基准时间。
同时在主程序中添加按键处理程序,实现时钟的开始、中断和校时,同时实现闹钟定时和切换显示等功能,还有秒表计时功能。
三、硬件电路图以及原理3。
1 硬件电路图如下:3。
2硬件原理:该项目中,主要的功能模块有:数码管显示模块;按键模块;蜂鸣器模块。
数码管显示模块主要是由芯片PIC16F877A内部的定时器1的定时中断实现数码管的动态显示.按键模块主要利用矩阵式按键实现多按键功能,矩阵式按键原理是在一端加高电平,然后检测另一端是否为高电平来判断按键是否按下,通过不同的定义可以让按键实现不同的功能。
蜂鸣器模块通过三极管的开关作用和驱动作用由芯片控鸣叫与否。
四、程序说明以及程序流程图该时钟默认显示页面为时钟计时页面,按键SW1 控制时钟、秒表的开始和中断,按按键SW1一次,如果数码管在显示秒表,则开始计秒功能;否则,开始正常计时;再按一次SW1则实现中断功能.按键SW2实现是数码管的选位,从第一个数码管开始,按一次就选中下一位数码管,循环选择。
SW3实现的是加1功能,每按一次就在SW2选中的位上加1。
第1章PIC16F877单⽚机实验板介绍第1章PIC16F877单⽚机实验板介绍美国微芯公司推出的CMOS 8位PIC系列单⽚机,采⽤精简指令集(RISC)、哈佛总线结构、2级流⽔线取指令⽅式,具有实⽤、低价、指令集⼩、简单易学、低功耗、⾼速度、体积⼩、功能强等特点,体现了单⽚机发展的⼀种新趋势,深受⼴⼤⽤户的欢迎,已逐渐成为单⽚机发展的新潮流。
PIC16F87X是微芯公司的中档产品。
它采⽤14位的类RISC指令系统,在保持低价格的前提下,增加了A/D转换器、内部E2PROM存储器、⽐较输出、捕捉输⼊、PWM 输出(加上简单的滤波电路后还可以作为D/A输出)、I2C总线和SPI总线接⼝电路、异步串⾏通信(USART)接⼝电路、模拟电压⽐较器、LCD驱动、FLASH程序存储器等许多功能,可以⽅便地在线多次编程和调试,特别适⽤于初学者学习和在产品的开发阶段使⽤;它也可以作为产品开发的终极产品。
微芯公司还将FLASH 芯⽚做成与OTP芯⽚价格相近,以致可⽤FLASH芯⽚代替OTP芯⽚。
微芯公司的单⽚机是品种最丰富的单⽚机系列之⼀,被⼴泛地应⽤于各种仪器和设备中。
这种单⽚机具有如下显著的特点:开发容易,周期短:由于PIC采⽤类RISC指令集,指令数⽬少(PIC16F87X 仅35条指令),且全部为单字长指令,易学易⽤;相对于采⽤CISC(复杂指令集)结构的单⽚机可节省30 %以上的开发时间、2倍以上的程序空间。
⾼速:PIC采⽤哈佛总线和类精简指令集,逐步建⽴了⼀种新的⼯业标准,指令的执⾏速度⽐⼀般的单⽚机要快4~5倍。
低功耗:PIC采⽤CMOS电路设计,结合了诸多的节电特性,使其功耗很低;100 %的静态设计可进⼊休眠(Sleep)省电状态,⽽不会影响激活后的正常运⾏。
微芯公司的单⽚机是各类单⽚机中低功耗设计最好的产品之⼀。
低价实⽤:PIC配备有OTP(One Time Programmable)型、EPROM型及FLASH型等多种形式的芯⽚,其OTP型芯⽚的价格很低。
20XX年小学期单片机设计实验报告题目:基于PIC16F877单片机的LED旋转时钟班级:学号:班内序号:实验组号:学生姓名:指导教师:基于PIC16F877单片机的LED旋转时钟――班实验摘要本次我们制作的基于PIC16F877单片机的LED旋转时钟是能够输入、显示时间的时钟。
结构新颖,效果奇特。
加入了现代科技的元素,利用人眼的视觉暂留特性,解决了传统时钟结构单一,显示效果固定的缺陷,更好了满足了人们对美的追求。
整个系统中,微控制器采用了Microchip公司的PIC16F877,软件设计中涉及PORTA用作普通数字I/O脚控制按键输入,PORTB、PORTC控制灯的亮灭,PORTD向时钟芯片DS1302写入和读出时间。
概括来说,本实验就是用人眼的视觉暂留特性,用PIC16F877单片机作为主控芯片,采用电机带动发光二极管高速旋转,利用频闪显示原理呈现时钟画面。
A b s t r a c tIn this experiment, we made a LED rotating clock base on PIC16F877 MCU. It can input and show time. Its structure is novel and its effect is amazing. It’s full of modern technology element. With human eyes’ persistence of vision, it solves traditional clock’s structure and effect’s disadvantage, fits human pursue for beauty better.The system uses the production of the Microchip cord--PIC16F877. The design includes the drive of PORTA as general digital ports to input time, the drive of PORTB and PORTC to control the LED’s on, the drive of PORTD to write and read time on DS1302.In conclusion, with human eyes’ persistence of v ision, this experiment uses PIC16F877 MCU as master chip, uses motor to drive LED rotate at high speed, uses strobe display principle to show the clock.关键字单片机——microcontroller 芯片——CMOS chipLED旋转时钟-- LED rotating clock一.实验论证与比较1.LED显示模块LED的特点非常明显,寿命长、光效高、无辐射与低功耗。
LED的光谱几乎全部集中于可见光频段,其发光效率可达80~90%。
将LED与普通白炽灯、螺旋节能灯及T5三基色荧光灯进行对比,结果显示:普通白炽灯的光效为12lm/W,寿命小于2000小时,螺旋节能灯的光效为60lm/W,寿命小于8000小时,T5荧光灯则为96lm/W,寿命大约为10000小时,而直径为5毫米的白光LED为20~28lm/W,寿命可大于100000小时。
有人还预测,未来的LED寿命上限将无穷大。
由于LED的种种优势,使得其在现在的各个领域里运用越来越广泛,我们设计的旋转LED显示屏幕,具有结构新颖,节约材料的特点,一列16个LED灯旋转显示之后,可以代替显示近似于16x120像素的显示宽度和内容。
旋转时钟是利用视觉暂留效应设计出来的,物体在快速运动时, 当人眼所看到的影像消失后,人眼仍能继续保留其影像0.1-0.4秒左右的图像,这种现象被称为视觉暂留现象。
是人眼具有的一种性质。
人眼观看物体时,成像于视网膜上,并由视神经输入人脑,感觉到物体的像。
但当物体移去时,视神经对物体的印象不会立即消失,而要延续0.1 -0.4秒的时间,人眼的这种性质被称为“眼睛的视觉暂留”。
假设我们设定我们的眼睛的暂留时间是0.4秒,如果我们的16个LED旋转一周的时间快过0.4秒,那么我们看到的图像就是这一列LED在各个位置显示的图像的叠加,如右图,如果我们用定时器把LED旋转一周的各个位置分割出120分,让它在相应的位置显示相应的图像,那么我们就可以得到一个累加的图像效果了。
旋转LED时钟的实现方法是把一组LED(16个左右)紧密的排列成一条直线,组成一条LED列,每个LED都由PIC单片机来控制其点灭。
把整个电路板固定在电机上,使得紧密排列的LED条的一端固定在电机的旋转轴附近,如图所示。
电路板转过一圈的时间极短,远小于0.1秒。
通过单片机控制LED灯在一圈内转到不同位置时的亮灭,来显示图像或文字。
2.DS1302时钟模块大多数的单片机没有实时时钟部件,一旦系统掉电时钟就不能运行,下次再运行,时间就不准确了。
即便使用备用电池,但要维持单片机系统的较大功耗也是坚持不了多久的。
而我所做的旋转时钟用到的单片机主要是来准确显示时间的,因此实时时钟部件必不可少,这里我用了MAXIM公司的DS1302时钟芯片作为实时时钟部件,保证时间的长久准确性。
DS1302 有着很强的功能。
包括时钟/日历寄存器和31 字节(8位)的数据暂存寄存器,数据通信仅通过一条串行输入输出口。
实时时钟/日历提供包括秒、分、时、日期、月份和年份信息。
闰年可自行调整,可选择AM/PM的12 小时制或24小时制。
只通过三根线进行数据的控制和传递:CE(输入信号,在读、写数据期间,必须为高。
该引脚有两个功能:第一,CE开始控制字访问移位寄存器的控制逻辑;其次,CE提供结束单字节或多字节数据传输的方法。
);I/O(三线接口时的双向数据线);SCLK(串行时钟输入)。
通过备用电源可以让芯片在小于1MW的功率下运作。
对时钟寄存器初始化可以设定当前时间,控制芯片的运行,时间是用BCD码保存的,RAM可以用来存取用户数据,在用了备用电池后RAM内的数据在系统掉电时能够保持不丢失。
芯片采用了简单的I2C 三线通信方式,便于节省芯片资源和与之接口的MCU的引脚。
芯片有着2.0~5.5V的宽供电电压范围,在5V供电时其接口与TTL电平兼容。
并且有着很低的功耗,在2.0V供电时仅耗300nA 的电流。
引脚X1 和X2 连接32.768kHz 晶体,与内部振荡器组成时钟。
晶体的精度直接影响着芯片时间的准确与否。
DS1302有两个电源引脚VCC1和VCC2,分别连接备用电池和电源VCC。
VCC2与主电源连接,VCC1接备用电池。
当VCC2低于VCC1时,芯片由VCC1供电;当VCC2-VCC1≥0.2V时,备用电池为芯片供电。
在VCC2供电时芯片能够对接在VCC1的备用电池充电,并且是否充电和充电电流都可以由芯片内地址为08H的时钟寄存器进行控制。
DS1302与单片机的硬件接线图如图三所示。
图三 DS1302硬件接线图在进行任何数据传输时,CE必须被制高电平(虽然CE被置为高电平,但内部时钟还是在晶振作用下不停地计时的),在每个SCLK上升沿时读入数据,下降沿时写出数据。
每个字节的传输都是由控制字节(如表1所示)指定的,控制字节的最高位Bit7必须是“1”,否则读写将会被禁止。
bit6为“0”则指定对时钟/日历寄存器进行读写操作,为“1”则对RAM区的数据进行读写操作,bit1-bit5 指定相关寄存器进行输入输出操作,最低位bit0 指定是输入还是输出,为“0”则为写,相反则为读,输入输出根据脉冲的上升沿和下降沿串行进行。
7 6 5 4 3 2 1 01 RAM/CK用来表示相关寄存器的地址RD/WR表1 DS1302控制字节控制字总是从最低位开始输出。
在控制字指令输入后的下一个SCLK时钟的上升沿时,数据被写入DS1302,数据输入从最低位(0位)开始。
同样,在紧跟8位的控制字指令后的下一个SCLK脉冲的下降沿,读出DS1302的数据,读出的数据也是从最低位到最高位。
数据读写时序如图四所示。
图四 DS1302数据读写时序通过8个脉冲便可读取一个字节,从而实现串行输入与输出。
最初通过8个时钟周期载入控制字节到移位寄存器。
如果控制指令选择的是单字节模式,连续的8个时钟脉冲可以进行8位数据的读写操作。
8个脉冲便可读写一个字节。
载入控制字节后就可以对时钟/日历寄存器进行相应操作,时钟/日历寄存器如下表所示。
读寄存器写寄存器BIT7BIT6BIT5 BIT4BIT3BIT2-BIT范围81h 80h CH 16-59秒0-15秒00-5 983h 82h 16-59分0-15分00-5 985h 84h 1220-2315-19时0-15时1-12/0-23 24AM/PM87h 86h0 0 016-31日0-15日1-3189h 88h 0 0 0 10月月1-12 8Bh 8Ah 0 0 0 0 0 1-7周1-78Dh 8Ch 0 15-99年0-15年00-9 98Fh 8Eh WP 0 —秒寄存器(81h、80h)的位7定义为时钟暂停标志(CH)。
当该位置1时,时钟振荡器停止,DS1302处于低功耗状态;当该位置为0时,时钟开始运行。
小时寄存器(85h、84h )的位7用于定义DS1302是运行于12小时模式还是24小时模式。
当为高时,选择12小时模式。
在12小时模式下,位5为1时,表示PM。
在24小时模式时,位5是第二个10小时位(20-23时)。
控制寄存器(8Fh、8Eh)的位7是写保护位(WP),其它7位均置为0。
在任何的对时钟和RAM的写操作之前,WP位必须为0。
当WP位为1时,写保护位防止对任一寄存器的写操作。
二.系统总体设计⒈系统模块总体框图如下:程序总体框图:⒉输入时间模块框图该模块利用两个按键sw1和sw2实现时间输入。
sw1按一次时间加1,sw2按一次切换时、分、秒的输入。
按完三次sw2结束。
通过八个LED 灯显示输入的时间的二进制数。
是⒊DS1302读写模块 写时间程序框图:4.LED显示模块单片机转20圈(小于1秒)从DS1302读一次数。
将表盘分成120格,走一格计数器加1。
程序框图:是三.硬件连接两个按键sw1和sw2接PORTA0和PORTA1。
PORTB和PORTC接16个LED灯。
PORTD0接DS1302的SLCK(时钟),PORTD1接DS1302的I/O接口, PORTD2接DS1302的CE(使能端)。