基于51单片机控制的语音报时万年历.docx
《基于51单片机控制的语音报时万年历.docx》由会员分享,可在线阅读,更多相关《基于51单片机控制的语音报时万年历.docx(14页珍藏版)》请在冰豆网上搜索。
基于51单片机控制的语音报时万年历
基于51单片机控制的语音报时万年历
-----20/11/2013SDU(WH)
1.实验要求
运用单片机及相关外设实现以下功能:
1)万年历及时钟显示
2)时间日期可调
3)可对时间进行整点报时和随机报时
2.方案分析
根据实验要求,选用STC公司的8051系列,STC12C5A16S2增强型51单片机。
此单片机功能强大,具有片内EEPROM、1T分频系数、片内ADC转换器等较为实用功能,故选用此款。
实验中,对日期和时间进行显示,显示的字符数较多,故选用12864LCD屏幕。
该屏幕操作较为便捷,外围电路相对简单,实用性较强。
为了实现要求中的时间日期可调,故按键是不可缺少的,所以使用了较多的按键。
一方面,单片机的I/O口较为充足;另一方面,按键较多,选择的余地较大,方便编程控制。
实验中,并未要求对时间和日期进行保存和掉电续运行,所以并未添加EEPROM和DS12C887-RTC芯片。
实际上,对万年历来说,这是较为重要的,但为了方便实现和编程的简单,此处并未添加,而是使用单片机的定时器控制时间,精度有差别。
且上电默认时间为2014-01-0109:
00:
00之后需要手动调整为正确时间。
要求中的语音报时功能,这里选用ISD1760芯片的模块来帮助实现。
此模块通过软件模拟SPI协议控制。
先将所需要的声音片段录入芯片的EEPROM区域,之后读出各段声音的地址段,然后在程序中定义出相应地址予以控制播放哪一声音片段。
3.电路硬件设计
实际效果图
4.程序代码部分
#ifndef_MAIN_H
#define_MAIN_H
#include""
#include""
#include""
#include""
#include""
#include""
#include""
#include""
#include""
#include""
externunsignedintcount;
externunsignedintkey_time[8];
externunsignedcharkey_new;
externunsignedcharkey_old;
externunsignedcharstop_flag;
externunsignedcharkey_follow[8];
externunsignedintkey_num[8];
sbitBEEP=P3^7;
sbitISD_SS=P0^7;
sbitISD_MISO=P0^4;
sbitISD_MOSI=P0^5;
sbitISD_SCLK=P0^6;
externunsignedchardate_show[];
externunsignedchartime_show[];
externunsignedcharsec;
externunsignedcharmin;
externunsignedcharhour;
externunsignedcharday;
externunsignedcharmonth;
externunsignedcharyear_f;
externunsignedcharyear_l;
externunsignedcharleap_year_flag;
externunsignedcharupdate_flag;
externunsignedcharadjust_flag;
externunsignedcharkey;
unsignedcharreport();
#endif
#include""
unsignedintcount=0;
unsignedintkey_num[8]=0;
unsignedcharkey_new=0;
unsignedcharkey_old=0;
unsignedcharstop_flag=0;
unsignedcharkey_follow[8]=0;
unsignedcharsec=1;
unsignedcharmin=0;
unsignedcharhour=9;
unsignedcharday=1;
unsignedcharmonth=1;
unsignedcharyear_f=20;
unsignedcharyear_l=14;
unsignedcharleap_year_flag=0;
unsignedchardate_show[]="2014-01-01";
unsignedchartime_show[]="09:
00:
00";
unsignedcharupdate_flag=1;
unsignedcharkey=0;
unsignedcharadjust_flag=0;
unsignedcharadjust_pos=0;
unsignedcharreport_flag=0;
voidmain()
{
unsignedchari;
P2=0XFF;
BEEP=0;
init();
initinal();{
buzy();
RW=0;
RS=DI;
DataPort=data1;
EN=1;
EN=0;
}
voiddelayms(unsignedintn)//延时10×n毫秒程序
{
unsignedinti,j;
for(i=0;i<3*n;i++)
for(j=0;j<2000;j++);
}
voiddelay(unsignedintm)//延时程序,微妙级
{
while(m--)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
}
voidwrite_cmd(unsignedcharcmd)
{
RS=0;RW=0;EN=0;
P1=cmd;
delayms
(1);
EN=1;
delayms
(1);
EN=0;
}
voidwrite_dat(unsignedchardat)
{
RS=1;
RW=0;
EN=0;
P1=dat;
delayms
(1);
EN=1;
delayms
(1);
EN=0;
}
voidlcd_pos(unsignedcharx,unsignedchary)
{
unsignedcharpos;
if(x==0)
x=0x80;
elseif(x==1)
x=0x90;
elseif(x==2)
x=0x88;
elseif(x==3)
x=0x98;
pos=x+y;
write_cmd(pos);
}
voidclrram(void)
{
write_cmd(0x30);
write_cmd(0x01);
}
#ifndef_SOUND_H
#define_SOUND_H
#include""
//以下为语音信息对应播放起始地址定义,A为开始,B为结束
#definesound_0A0x0012
#definesound_0B0x0017
#definesound_1A0x0019
#definesound_1B0x0025
#definesound_2A0x0027
#definesound_2B0x002e
#definesound_3A0x002f
#definesound_3B0x0039
#definesound_4A0x003b
#definesound_4B0x0048
#definesound_5A0x004a
#definesound_5B0x004f
#definesound_6A0x0052
#definesound_6B0x0159
#definesound_7A0x005c
#definesound_7B0x0062
#definesound_8A0x0065
#definesound_8B0x0131
#definesound_9A0x006f
#definesound_9B0x015F
#definesound_10A0x0079
#definesound_10B0x015E
#definesound_11A0x0082
#definesound_11B0x018A
#definesound_12A0x0091
#definesound_12B0x0100
#definesound_13A0x009f
#definesound_13B0x0100
#definesound_14A0x00ac
#definesound_14B0x0100
voidGetSound(unsignedcharsoundtick);
voidPlaySoundTick(unsignedcharnumber);
voiddelay_isd(unsignedinttime);
voidshort_delay();
voidlong_delay();
#endif
#include""
voidGetSound(unsignedcharsoundtick)
{
ISD_SS=0;
switch(soundtick)
{
case0:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_0A,sound_0B);}break;
case1:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_1A,sound_1B);}break;
case2:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_2A,sound_2B);}break;
case3:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_3A,sound_3B);}break;
case4:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_4A,sound_4B);}break;
case5:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_5A,sound_5B);}break;
case6:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_6A,sound_6B);}break;
case7:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_7A,sound_7B);}break;
case8:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_8A,sound_8B);}break;
case9:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_9A,sound_9B);}break;
case10:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_10A,sound_10B);}break;
case11:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_11A,sound_11B);}break;
case12:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_12A,sound_12B);}break;
case13:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_13A,sound_13B);}break;
case14:
{isd1700_7byte_comm(ISD1700_SET_PLAY|ISD_LED,sound_14A,sound_14B);}break;
default:
break;
}
ISD_SS=1;
}
voidPlaySoundTick(unsignedcharnumber)
{
spi_stop();
delay_isd(30000);
GetSound(number);
}
voiddelay_isd(unsignedinttime)
{
while(time--!
=0);
}
voidshort_delay()
{
delay_isd(30000);
delay_isd(30000);
delay_isd(30000);
delay_isd(30000);
delay_isd(30000);
delay_isd(30000);
delay_isd(30000);
delay_isd(30000);
delay_isd(30000);
}
voidlong_delay()
{
short_delay();
short_delay();
short_delay();
short_delay();
}
#ifndef_KEY_H
#define_KEY_H
#include""
sbitKEY1=P2^0;
sbitKEY2=P2^1;
sbitKEY3=P2^2;
sbitKEY4=P2^3;
sbitKEY5=P2^4;
sbitKEY6=P2^5;
sbitKEY7=P2^6;
sbitKEY8=P2^7;
sbitKEY_SURE=P3^6;
voidkey_delay(unsignedcharz);
unsignedcharkeyscan_nor();
#endif
#include""
unsignedcharkeyscan_nor()
{
if(!
KEY1)
{
key_delay(20);
if(!
KEY1)
{
LED1=0;
return1;
}
}
if(!
KEY2)
{
key_delay(20);
if(!
KEY2)
{
LED2=0;
return2;
}
}
if(!
KEY3)
{
key_delay(20);
if(!
KEY3)
{
LED3=0;
return3;
}
}
if(!
KEY4)
{
key_delay(20);
if(!
KEY4)
{
LED4=0;
return4;
}
}
if(!
KEY5)
{
key_delay(20);
if(!
KEY5)
{
LED5=0;
return5;
}
}
if(!
KEY6)
{
key_delay(20);
if(!
KEY6)
{
LED6=0;
return6;
}
}
if(!
KEY7)
{
key_delay(20);
if(!
KEY7)
{
LED7=0;
return7;
}
}
if(!
KEY8)
{
key_delay(20);
if(!
KEY8)
{
LED8=0;
return8;
}
}
return0;
}
voidkey_delay(unsignedcharz)
{
unsignedcharx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
5.参与制作人员
ZYL