版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、基于51单片机控制的语音报时万年历基于51单片机控制的语音报时万年历1 实验要求运用单片机及相关外设实现以下功能:1) 万年历及时钟显示2) 时间日期可调3) 可对时间进行整点报时和随机报时2 方案分析根据实验要求,选用STC公司的8051系列,STC12C5A16S2增强型51单片机。此单片机功能强大,具有片内EEPROM、1T分频系数、片内ADC转换器等较为实用功能,故选用此款。实验中,对日期和时间进行显示,显示的字符数较多,故选用12864LCD屏幕。该屏幕操作较为便捷,外围电路相对简单,实用性较强。为了实现要求中的时间日期可调,故按键是不可缺少的,所以使用了较多的按键。一方面,单片机的
2、I/O口较为充足;另一方面,按键较多,选择的余地较大,方便编程控制。实验中,并未要求对时间和日期进行保存和掉电续运行,所以并未添加EEPROM和DS12C887-RTC芯片。实际上,对万年历来说,这是较为重要的,但为了方便实现和编程的简单,此处并未添加,而是使用单片机的定时器控制时间,精度有差别。且上电默认时间为2014-01-01 09:00:00 之后需要手动调整为正确时间。要求中的语音报时功能,这里选用ISD1760芯片的模块来帮助实现。此模块通过软件模拟SPI协议控制。先将所需要的声音片段录入芯片的EEPROM区域,之后读出各段声音的地址段,然后在程序中定义出相应地址予以控制播放哪一声
3、音片段。3 电路硬件设计实际效果图4 程序代码部分Main.h#ifndef _MAIN_H#define _MAIN_H#include "reg52.h"#include "INTRINS.H"#include "math.h"#include "string.h"#include "key.h"#include "led.h"#include "12864.h"#include "main.h"#include "isd
4、1700.h"#include "sound.h"extern unsigned int count;extern unsigned int key_time8;extern unsigned char key_new;extern unsigned char key_old;extern unsigned char stop_flag;extern unsigned char key_follow8;extern unsigned int key_num8;sbit BEEP=P37;sbit ISD_SS=P07;sbit ISD_MISO=P04;sbit
5、ISD_MOSI=P05;sbit ISD_SCLK=P06;extern unsigned char date_show;extern unsigned char time_show;extern unsigned char sec;extern unsigned char min;extern unsigned char hour;extern unsigned char day;extern unsigned char month;extern unsigned char year_f;extern unsigned char year_l;extern unsigned char le
6、ap_year_flag;extern unsigned char update_flag;extern unsigned char adjust_flag;extern unsigned char key;unsigned char report();#endifMain.c#include "main.h"unsigned int count=0;unsigned int key_num8=0;unsigned char key_new=0;unsigned char key_old=0;unsigned char stop_flag=0;unsigned char k
7、ey_follow8=0;unsigned char sec=1;unsigned char min=0;unsigned char hour=9;unsigned char day=1;unsigned char month=1;unsigned char year_f=20;unsigned char year_l=14;unsigned char leap_year_flag=0;unsigned char date_show="2014-01-01"unsigned char time_show="09:00:00"unsigned char u
8、pdate_flag=1;unsigned char key=0;unsigned char adjust_flag=0;unsigned char adjust_pos=0;unsigned char report_flag=0;void main()unsigned char i;P2=0XFF;BEEP=0;init();initinal(); /调用LCD字库初始化程序TMOD=0x01; /使用定时器T0TH0=(65536-1000)/256; /定时器高八位赋初值TL0=(65536-1000)%256; /定时器低八位赋初值 */EA=1; /开中断总允许ET0=1; /允许T
9、0中断TR0=1; /启动定时器T0 while(1)if(update_flag)lcd_pos(1,0);for(i=0;i<10;i+) write_dat(date_showi);lcd_pos(2,4);for(i=0;i<8;i+)write_dat(time_showi);update_flag=0;if(key!=keyscan_nor()key=keyscan_nor();if(key=8&&!adjust_flag)adjust_flag=1;if(key&&adjust_flag)if(key=1)adjust_pos+;if(
10、adjust_pos=14)adjust_pos=0;else if(key=2)if(!adjust_pos)adjust_pos=13;elseadjust_pos-;else if(key=6)if(!adjust_pos)sec+;else if(adjust_pos=1)sec=sec+10;else if(adjust_pos=2)min+;else if(adjust_pos=3)min=min+10;else if(adjust_pos=4)hour+;else if(adjust_pos=5)hour=hour+10;else if(adjust_pos=6)day+;els
11、e if(adjust_pos=7)day=day+10;else if(adjust_pos=8)month+;else if(adjust_pos=9)month=month+10;else if(adjust_pos=10)year_l+;else if(adjust_pos=11)year_l=year_l+10;else if(adjust_pos=12)year_f+;else if(adjust_pos=13)year_f=year_f+10;else if(key=7)if(!adjust_pos)sec-;else if(adjust_pos=1)sec=sec-10;els
12、e if(adjust_pos=2)min-;else if(adjust_pos=3)min=min-10;else if(adjust_pos=4)hour-;else if(adjust_pos=5)hour=hour-10;else if(adjust_pos=6)day-;else if(adjust_pos=7)day=day-10;else if(adjust_pos=8)month-;else if(adjust_pos=9)month=month-10;else if(adjust_pos=10)year_l-;else if(adjust_pos=11)year_l=yea
13、r_l-10;else if(adjust_pos=12)year_f-;else if(adjust_pos=13)year_f=year_f-10;else if(key=3)adjust_flag=0;if(key=6|key=7)if(sec>=80)sec=0;if(min>=80)min=0;if(hour>=40)hour=0;if(month>30)month=1;if(day>50)day=0;if(year_f>=120)year_f=0;if(year_l>=120)year_l=0;if(key=3)report_flag=1;
14、if(report_flag)clrram();Dingwei(2,1);lcd_mesg("REPORTING!");report();clrram();void time0() interrupt 1static unsigned char timer=0;TH0=(65536-50000)/256; /定时器高八位赋初值TL0=(65536-50000)%256; /定时器低八位赋初值timer+;if(timer=20)sec+;time_show6=sec/10+48;time_show7=sec%10+48;if(sec>=60)sec=0;min+;ti
15、me_show6=sec/10+48;time_show7=sec%10+48;time_show3=min/10+48;time_show4=min%10+48; if(min>=60)min=0;hour+;time_show3=min/10+48;time_show4=min%10+48;time_show0=hour/10+48;time_show1=hour%10+48;if(hour>=24)hour=0;day+;time_show0=hour/10+48;time_show1=hour%10+48;date_show8=day/10+48;date_show9=da
16、y%10+48;if(day>=29&&!leap_year_flag&&month=2)|(day=30&&leap_year_flag&&month=2)|(day=31&&(month=4|month=6|month=9|month=11)|(month=32)day=1;month+;date_show8=day/10+48;date_show9=day%10+48;date_show5=month/10+48;date_show6=month%10+48;if(month>=13)month=
17、1;year_l+;date_show5=month/10+48;date_show6=month%10+48;date_show0=year_f/10+48;date_show1=year_f%10+48;date_show2=year_l/10+48;date_show3=year_l%10+48;if(year_l>=100)year_l=0;year_f+;if(!(year_f*100+year_l)%4)&&(year_f*100+year_l)%100)|(!(year_f*100+year_l)%400)leap_year_flag=1;else leap
18、_year_flag=0;date_show0=year_f/10+48;date_show1=year_f%10+48;date_show2=year_l/10+48;date_show3=year_l%10+48;timer=0;update_flag=1;if(adjust_flag)time_show7=sec%10+48;time_show6=sec/10+48;time_show4=min%10+48;time_show3=min/10+48;time_show1=hour%10+48;time_show0=hour/10+48;date_show9=day%10+48;date_
19、show8=day/10+48;date_show6=month%10+48;date_show5=month/10+48;date_show3=year_l%10+48;date_show2=year_l/10+48;date_show1=year_f%10+48;date_show0=year_f/10+48;if(adjust_flag&&timer=10)if(!adjust_pos)time_show7=' 'else if(adjust_pos=1)time_show6=' 'else if(adjust_pos=2)time_sho
20、w4=' 'else if(adjust_pos=3)time_show3=' 'else if(adjust_pos=4)time_show1=' 'else if(adjust_pos=5)time_show0=' 'else if(adjust_pos=6)date_show9=' 'else if(adjust_pos=7)date_show8=' 'else if(adjust_pos=8)date_show6=' 'else if(adjust_pos=9)date_sh
21、ow5=' 'else if(adjust_pos=10)date_show3=' 'else if(adjust_pos=11)date_show2=' 'else if(adjust_pos=12)date_show1=' 'else if(adjust_pos=13)date_show0=' 'update_flag=1;if(!min&&!sec&&!adjust_flag)report_flag=1; unsigned char report()PlaySoundTick(
22、11);long_delay();if(!min)if(hour<=10)PlaySoundTick(hour);short_delay();PlaySoundTick(12);short_delay();PlaySoundTick(14);short_delay();else if(hour>10&&hour<20)PlaySoundTick(10);short_delay();PlaySoundTick(hour-10);short_delay();PlaySoundTick(12);short_delay();PlaySoundTick(14);shor
23、t_delay();else if(hour=20)PlaySoundTick(2);short_delay();PlaySoundTick(10);short_delay();PlaySoundTick(12);short_delay();PlaySoundTick(14);short_delay();elsePlaySoundTick(2);short_delay();PlaySoundTick(10);short_delay();PlaySoundTick(hour-20);short_delay();PlaySoundTick(12);short_delay();PlaySoundTi
24、ck(14);short_delay();else if(hour<=10)PlaySoundTick(hour);short_delay();PlaySoundTick(12);short_delay();else if(hour>10&&hour<20)PlaySoundTick(10);short_delay();PlaySoundTick(hour-10);short_delay();PlaySoundTick(12);short_delay();else if(hour=20)PlaySoundTick(2);short_delay();PlaySo
25、undTick(10);short_delay();PlaySoundTick(12);short_delay();elsePlaySoundTick(2);short_delay();PlaySoundTick(10);short_delay();PlaySoundTick(hour-20);short_delay();PlaySoundTick(12);short_delay(); if(min<=10)PlaySoundTick(min);short_delay();PlaySoundTick(13);short_delay();else if(min>10&&
26、;min%10)PlaySoundTick(min/10);short_delay();PlaySoundTick(10);short_delay();PlaySoundTick(min-10*(min/10);short_delay();PlaySoundTick(13);short_delay();else PlaySoundTick(min/10);short_delay();PlaySoundTick(10);short_delay();PlaySoundTick(13);short_delay();report_flag=0;time_show7=sec%10+48;time_sho
27、w6=sec/10+48;time_show4=min%10+48;time_show3=min/10+48;time_show1=hour%10+48;time_show0=hour/10+48;date_show9=day%10+48;date_show8=day/10+48;date_show6=month%10+48;date_show5=month/10+48;date_show3=year_l%10+48;date_show2=year_l/10+48;date_show1=year_f%10+48;date_show0=year_f/10+48;return 0;Isd1700.
28、h#ifndef _ISD1760_H#define _ISD1760_H#include "main.h"#define ISD1700_PU 0x01#define ISD1700_STOP 0X02#define ISD1700_REST 0x03#define ISD1700_CLR_INT 0x04#define ISD1700_RD_STAUS 0x05#define ISD1700_RD_PLAY_PTR 0x06#define ISD1700_PD 0x07#define ISD1700_RD_REC_PTR 0x08#define ISD1700_DEVI
29、D 0x09#define ISD1700_PLAY 0x40#define ISD1700_REC 0x41#define ISD1700_ERASE 0x42#define ISD1700_G_ERASE 0x43#define ISD1700_RD_APC 0x44#define ISD1700_WR_APC1 0x45#define ISD1700_WR_APC2 0x65#define ISD1700_WR_NVCFG 0x46#define ISD1700_LD_NVCFG 0x47#define ISD1700_FWD 0x48#define ISD1700_CHK_MEM 0x
30、49#define ISD1700_EXTCLK 0x4A#define ISD1700_SET_PLAY 0x80#define ISD1700_SET_REC 0x81#define ISD1700_SET_ERASE 0x82#define NULL 0x00#define ISD_LED 0x10extern unsigned char data ISD_COMM_RAM_C7;extern void init(void);extern void delay_isd(int x);extern void comm_sate(void);extern void rest_isd_comm
31、_ptr(void);extern unsigned char T_R_comm_byte(unsigned char comm_data );extern void isd1700_par2_comm(unsigned char comm_par, unsigned int data_par);extern void isd1700_Npar_comm(unsigned char comm_par,comm_byte_count); extern void isd1700_7byte_comm(unsigned char comm_par, unsigned int star_addr, u
32、nsigned int end_addr);extern void spi_pu (void);extern void spi_stop (void);extern void spi_Rest ( void );extern void spi_CLR_INT(void);extern void spi_RD_STAUS(void);extern void spi_RD_play_ptr(void);extern void spi_pd(void);extern void spi_RD_rec_ptr(void);extern void spi_devid(void);extern void s
33、pi_play(void);extern void spi_rec (void);extern void spi_erase (void);extern void spi_G_ERASE (void);extern void spi_rd_apc(void);extern void spi_wr_apc1 (void);extern void spi_wr_apc2 (void);extern void spi_wr_nvcfg (void);extern void spi_ld_nvcfg (void);extern void spi_fwd (void);extern void spi_c
34、hk_mem(void);extern void spi_CurrRowAddr(void);extern void seril_back_sate(unsigned char byte_number);extern void spi_set_opt(unsigned char spi_set_comm);void init(void);#endifIsd1700.c/#pragma src#include "isd1700.h"#include "sound.h"#define uchar unsigned char #define uint unsi
35、gned intsbit DAC_sync=P20;sbit DAC_sclk=P21;sbit DAC_din =P22;bit re_fig;uchar data comm_temp;uchar data ISD_COMM_RAM7;uchar data ISD_COMM_RAM_C7;uchar data *isd_comm_ptr;uchar data *back_data_ptr;void init(void);void isd_delay(int x);void comm_sate(void);void rest_isd_comm_ptr(void);uchar T_R_comm_
36、byte( uchar comm_data );void isd1700_par2_comm(uchar comm_par, uint data_par);void isd1700_Npar_comm(uchar comm_par,comm_byte_count); /no parameter commvoid isd1700_7byte_comm(uchar comm_par, uint star_addr, uint end_addr);void spi_pu (void);void spi_stop (void);void spi_Rest ( void );void spi_CLR_I
37、NT(void);void spi_RD_STAUS(void);void spi_RD_play_ptr(void);void spi_pd(void);void spi_RD_rec_ptr(void);void spi_devid(void);void spi_play(void);void spi_rec (void);void spi_erase (void);void spi_G_ERASE (void);void spi_rd_apc(void);void spi_wr_apc1 (void);void spi_wr_apc2 (void);void spi_wr_nvcfg (
38、void);void spi_ld_nvcfg (void);void spi_fwd (void);void spi_chk_mem(void);void spi_CurrRowAddr(void);void seril_back_sate(uchar byte_number);void spi_set_opt(uchar spi_set_comm);void comm_sate(void) uchar sate_temp;uint apc_temp; if(RI) sate_temp=SBUF; if(sate_temp=0x09) spi_devid(); if(sate_temp=0x
39、44) spi_rd_apc(); if(sate_temp=0x40) spi_play(); if(sate_temp=0x04) spi_CLR_INT(); if(sate_temp=0x05) spi_RD_STAUS(); if(sate_temp=0x43) spi_G_ERASE(); if(sate_temp=0x01) spi_pu (); if(sate_temp=0x02) spi_stop(); if(sate_temp=0x03) spi_Rest (); if(sate_temp=0x06) spi_RD_play_ptr(); if(sate_temp=0x07
40、) spi_pd(); if(sate_temp=0x08) spi_RD_rec_ptr(); if(sate_temp=0x41) spi_rec(); if(sate_temp=0x42) spi_erase(); if(sate_temp=0x45) spi_wr_apc1 (); if(sate_temp=0x65) spi_wr_apc2 (); if(sate_temp=0x46) spi_wr_nvcfg (); if(sate_temp=0x47) spi_ld_nvcfg (); if(sate_temp=0x48) spi_fwd (); if(sate_temp=0x4
41、9) spi_chk_mem(); if(sate_temp=0x60) spi_CurrRowAddr(); if(sate_temp=0x80) spi_set_opt(ISD1700_SET_PLAY|ISD_LED); /spi_set_opt(ISD1700_SET_PLAY); if(sate_temp=0x81) spi_set_opt(ISD1700_SET_REC|ISD_LED);/spi_set_opt(ISD1700_SET_REC); ISD_COMM_RAM_C0=ISD1700_SET_REC ; seril_back_sate(1); if(sate_temp=
42、0x82) spi_set_opt(ISD1700_SET_ERASE|ISD_LED);/spi_set_opt(ISD1700_SET_ERASE); if(sate_temp=ISD1700_WR_APC2) RI=0; while(!RI); apc_temp=SBUF; apc_temp=apc_temp<<8; RI=0; while(!RI); apc_temp|=SBUF; RI=0; ISD_SS=0; isd1700_par2_comm(ISD1700_WR_APC2,apc_temp); ISD_SS=1; RI=0; if(re_fig) rest_isd_
43、comm_ptr();sate_temp=0;do SBUF=*back_data_ptr+; while(!TI); TI=0; while(+sate_temp<=2); re_fig=0; void spi_set_opt(uchar spi_set_comm) uint start_addr,end_addr; RI=0; while(!RI); start_addr=SBUF; start_addr=start_addr<<8; RI=0; while(!RI); start_addr|=SBUF; RI=0; while(!RI); end_addr=SBUF;
44、end_addr=start_addr<<8; RI=0; while(!RI); end_addr|=SBUF; RI=0; ISD_SS=0; isd1700_7byte_comm(spi_set_comm, start_addr, end_addr); ISD_SS=1; void spi_pu (void) ISD_SS=0; isd1700_Npar_comm(ISD1700_PU,2); ISD_SS=1; void spi_stop (void) ISD_SS=0; isd1700_Npar_comm(ISD1700_STOP,2); ISD_SS=1; ISD_COMM_RAM_C0=ISD1700_STOP ; seril_back_sate(1); void spi_Rest (void) ISD_SS=0; isd1700_Npar_comm(ISD1700_REST,2); ISD_SS=1; void spi_CLR_INT(void) ISD_SS=0; isd1700_Npar_comm(ISD1700_CLR_INT,2); ISD_SS=1; void spi_RD
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 交样工作制度
- 信通科工作制度
- 一米线工作制度
- 区地震工作制度
- 医保科工作制度
- 代办点工作制度
- 医务处工作制度
- 十必谈工作制度
- 军转办工作制度
- 创文工作制度
- 2026季华实验室测试中心招聘5人(广东)笔试参考题库及答案解析
- 电力建设“五新”推广应用信息目录(试行)
- 素能培优(七)平面向量与三角形的“四心”
- 核磁教学讲解课件
- 铁路工地混凝土拌和站标准化管理实施意见(工管办函2013283号)
- 大学专业排名证明(模板)
- 空域规划与管理
- 2023年湖北通山城市发展(集团)有限责任公司招聘笔试题库含答案解析
- 医用辐射防护与安全(省辐射站)
- 循环流化床锅炉检修规程
- 拉丁舞比赛服饰装饰元素的演变,服装设计论文
评论
0/150
提交评论