基于51单片机控制的语音报时万年历-----20/11/20XX SDU(WH)一.实验要求运用单片机及相关外设实现以下功能:1)万年历及时钟显示2)时间日期可调3)可对时间进行整点报时和随机报时二.方案分析根据实验要求,选用STC公司的8051系列,STC12C5A16S2增强型51单片机。
此单片机功能强大,具有片内EEPROM、1T分频系数、片内ADC转换器等较为实用功能,故选用此款。
实验中,对日期和时间进行显示,显示的字符数较多,故选用12864LCD屏幕。
该屏幕操作较为便捷,外围电路相对简单,实用性较强。
为了实现要求中的时间日期可调,故按键是不可缺少的,所以使用了较多的按键。
一方面,单片机的I/O口较为充足;另一方面,按键较多,选择的余地较大,方便编程控制。
实验中,并未要求对时间和日期进行保存和掉电续运行,所以并未添加EEPROM和DS12C887-RTC芯片。
实际上,对万年历来说,这是较为重要的,但为了方便实现和编程的简单,此处并未添加,而是使用单片机的定时器控制时间,精度有差别。
且上电默认时间为20XX-01-01 09:00:00 之后需要手动调整为正确时间。
要求中的语音报时功能,这里选用ISD1760芯片的模块来帮助实现。
此模块通过软件模拟SPI协议控制。
先将所需要的声音片段录入芯片的EEPROM区域,之后读出各段声音的地址段,然后在程序中定义出相应地址予以控制播放哪一声音片段。
三.电路硬件设计实际效果图四.程序代码部分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 "isd1700.h"#include "sound.h"extern unsigned int count;extern unsigned int key_time[8]; extern unsigned char key_new; extern unsigned char key_old; extern unsigned char stop_flag; extern unsigned char key_follow[8]; extern unsigned int key_num[8];sbit BEEP=P3^7;sbit ISD_SS=P0^7;sbit ISD_MISO=P0^4;sbit ISD_MOSI=P0^5;sbit ISD_SCLK=P0^6;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 leap_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_num[8]=0;unsigned char key_new=0;unsigned char key_old=0;unsigned char stop_flag=0;unsigned char key_follow[8]=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[]="20XX-01-01"; unsigned char time_show[]="09:00:00";unsigned char update_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; //允许T0中断TR0=1; //启动定时器T0while(1){if(update_flag){lcd_pos(1,0);for(i=0;i<10;i++)write_dat(date_show[i]);lcd_pos(2,4);for(i=0;i<8;i++)write_dat(time_show[i]);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(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++;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=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;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--;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=year_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;if(report_flag){clrram();Dingwei(2,1);lcd_mesg("REPORTING!!!");report();clrram();}}}void time0() interrupt 1{static unsigned char timer=0;TH0=(65536-50000)/256; //定时器高八位赋初值TL0=(65536-50000)%256; //定时器低八位赋初值timer++;if(timer==20){sec++;time_show[6]=sec/10+48;time_show[7]=sec%10+48;if(sec>=60){sec=0;min++;time_show[6]=sec/10+48;time_show[7]=sec%10+48;time_show[3]=min/10+48;time_show[4]=min%10+48;}if(min>=60){min=0;hour++;time_show[3]=min/10+48;time_show[4]=min%10+48;time_show[0]=hour/10+48;time_show[1]=hour%10+48;}if(hour>=24){hour=0;day++;time_show[0]=hour/10+48;time_show[1]=hour%10+48;date_show[8]=day/10+48;date_show[9]=day%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_show[8]=day/10+48;date_show[9]=day%10+48;date_show[5]=month/10+48;date_show[6]=month%10+48;}if(month>=13){month=1;year_l++;date_show[5]=month/10+48;date_show[6]=month%10+48;date_show[0]=year_f/10+48;date_show[1]=year_f%10+48;date_show[2]=year_l/10+48;date_show[3]=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)%40 0)))leap_year_flag=1;elseleap_year_flag=0;date_show[0]=year_f/10+48;date_show[1]=year_f%10+48;date_show[2]=year_l/10+48;date_show[3]=year_l%10+48;}timer=0;update_flag=1;if(adjust_flag){time_show[7]=sec%10+48;time_show[6]=sec/10+48;time_show[4]=min%10+48;time_show[3]=min/10+48;time_show[1]=hour%10+48;time_show[0]=hour/10+48;date_show[9]=day%10+48;date_show[8]=day/10+48;date_show[6]=month%10+48;date_show[5]=month/10+48;date_show[3]=year_l%10+48;date_show[2]=year_l/10+48;date_show[1]=year_f%10+48;date_show[0]=year_f/10+48;}}if(adjust_flag&&timer==10){if(!adjust_pos)time_show[7]=' ';else if(adjust_pos==1)time_show[6]=' ';else if(adjust_pos==2)time_show[4]=' ';else if(adjust_pos==3)time_show[3]=' ';else if(adjust_pos==4)time_show[1]=' ';else if(adjust_pos==5)time_show[0]=' ';else if(adjust_pos==6)date_show[9]=' ';else if(adjust_pos==7)date_show[8]=' ';else if(adjust_pos==8)date_show[6]=' ';else if(adjust_pos==9)date_show[5]=' ';else if(adjust_pos==10)date_show[3]=' ';else if(adjust_pos==11)date_show[2]=' ';else if(adjust_pos==12)date_show[1]=' ';else if(adjust_pos==13)date_show[0]=' ';update_flag=1;}if(!min&&!sec&&!adjust_flag)report_flag=1;}unsigned char report(){PlaySoundTick(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);short_delay();}else if(hour==20){PlaySoundTick(2);short_delay();PlaySoundTick(10);short_delay();PlaySoundTick(12);short_delay();PlaySoundTick(14);short_delay();}else{short_delay();PlaySoundTick(10);short_delay();PlaySoundTick(hour-20);short_delay();PlaySoundTick(12);short_delay();PlaySoundTick(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();PlaySoundTick(10);short_delay();PlaySoundTick(12);short_delay();}else{PlaySoundTick(2);short_delay();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&&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_show[7]=sec%10+48;time_show[6]=sec/10+48;time_show[4]=min%10+48;time_show[3]=min/10+48;time_show[1]=hour%10+48;time_show[0]=hour/10+48;date_show[9]=day%10+48;date_show[8]=day/10+48;date_show[6]=month%10+48;date_show[5]=month/10+48;date_show[3]=year_l%10+48;date_show[2]=year_l/10+48;date_show[1]=year_f%10+48;date_show[0]=year_f/10+48;return 0;}Isd1700.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_DEVID 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 0x49 #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_M_RAM_C[7];extern void init(void);extern void delay_isd(int x);extern void m_sate(void);extern void rest_isd_m_ptr(void);extern unsigned char T_R_m_byte(unsigned char m_data );extern void isd1700_par2_m(unsigned char m_par, unsigned int data_par);extern void isd1700_Npar_m(unsigned char m_par,m_byte_count);extern void isd1700_7byte_m(unsigned char m_par, unsigned int star_addr, unsigned 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 spi_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_chk_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_m);void init(void);#endifIsd1700.c//#pragma src#include "isd1700.h"#include "sound.h"#define uchar unsigned char#define uint unsigned intsbit DAC_sync=P2^0;sbit DAC_sclk=P2^1;sbit DAC_din =P2^2;bit re_fig;uchar data m_temp;uchar data ISD_M_RAM[7];uchar data ISD_M_RAM_C[7];uchar data *isd_m_ptr;uchar data *back_data_ptr;void init(void);void isd_delay(int x);void m_sate(void);void rest_isd_m_ptr(void);uchar T_R_m_byte( uchar m_data );void isd1700_par2_m(uchar m_par, uint data_par);void isd1700_Npar_m(uchar m_par,m_byte_count); //no parameter m void isd1700_7byte_m(uchar m_par, uint star_addr, uint end_addr);void spi_pu (void);void spi_stop (void);void spi_Rest ( void );void spi_CLR_INT(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 (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_m);void m_sate(void){uchar sate_temp;uint apc_temp;if(RI){ sate_temp=SBUF;if(sate_temp==0x09){ spi_devid();}if(sate_temp==0x44){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){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==0x49){ 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_M_RAM_C[0]=ISD1700_SET_REC ;seril_back_sate(1);}if(sate_temp==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_m(ISD1700_WR_APC2,apc_temp);ISD_SS=1;}RI=0;}if(re_fig){rest_isd_m_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_m){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;end_addr=start_addr<<8;RI=0;while(!RI);end_addr|=SBUF;RI=0;ISD_SS=0;isd1700_7byte_m(spi_set_m, start_addr, end_addr);ISD_SS=1;}void spi_pu (void){ISD_SS=0;isd1700_Npar_m(ISD1700_PU,2);ISD_SS=1;}void spi_stop (void){ISD_SS=0;isd1700_Npar_m(ISD1700_STOP,2);ISD_SS=1;ISD_M_RAM_C[0]=ISD1700_STOP ;seril_back_sate(1);}void spi_Rest (void){ISD_SS=0;isd1700_Npar_m(ISD1700_REST,2);ISD_SS=1;}void spi_CLR_INT(void){ISD_SS=0;isd1700_Npar_m(ISD1700_CLR_INT,2);ISD_SS=1;}void spi_RD_STAUS(void){ uchar i;ISD_SS=0;isd1700_Npar_m(ISD1700_RD_STAUS,3);ISD_SS=1;i=ISD_M_RAM_C[1];//j=ISD_M_RAM_C[2];ISD_M_RAM_C[1]=ISD_M_RAM_C[0];ISD_M_RAM_C[0]=i;seril_back_sate(3);}void spi_CurrRowAddr(void){ uchar i;ISD_SS=0;isd1700_Npar_m(ISD1700_RD_STAUS,3);ISD_SS=1;i=ISD_M_RAM_C[1];ISD_M_RAM_C[1]=ISD_M_RAM_C[0]>>5|ISD_M_RAM_C[1]<<3;ISD_M_RAM_C[0]= i >>5;seril_back_sate(3);}void spi_RD_play_ptr(void){ uchar i;ISD_SS=0;isd1700_Npar_m(ISD1700_RD_PLAY_PTR,4);ISD_SS=1;i=ISD_M_RAM_C[3]&0x03;ISD_M_RAM_C[3]=ISD_M_RAM_C[2];ISD_M_RAM_C[2]=i;seril_back_sate(4);}void spi_pd(void){ISD_SS=0;isd1700_Npar_m(ISD1700_PD,2);ISD_SS=1;}void spi_RD_rec_ptr(void){ uchar i;ISD_SS=0;isd1700_Npar_m(ISD1700_RD_REC_PTR,4);ISD_SS=1;i=ISD_M_RAM_C[3]&0x03;ISD_M_RAM_C[3]=ISD_M_RAM_C[2];ISD_M_RAM_C[2]=i;seril_back_sate(4);}void spi_devid(void){ISD_SS=0;isd1700_Npar_m(ISD1700_DEVID,3);ISD_SS=1;ISD_M_RAM_C[2]=ISD_M_RAM_C[2]&0xf8;seril_back_sate(3);}void spi_play(void){ISD_SS=0;isd1700_Npar_m(ISD1700_PLAY|ISD_LED,2);ISD_SS=1;}void spi_rec (void){ISD_SS=0;isd1700_Npar_m(ISD1700_REC|ISD_LED,2);ISD_SS=1;ISD_M_RAM_C[0]=ISD1700_REC ;seril_back_sate(1);}void spi_erase (void){ISD_SS=0;isd1700_Npar_m(ISD1700_ERASE|ISD_LED,2);ISD_SS=1;}void spi_G_ERASE (void){ISD_SS=0;isd1700_Npar_m(ISD1700_G_ERASE|ISD_LED,2);ISD_SS=1;}void spi_rd_apc(void){ISD_SS=0;isd1700_Npar_m(ISD1700_RD_APC,4);ISD_SS=1;seril_back_sate(4);}void spi_wr_apc1 (void){}void spi_wr_apc2 (void){ISD_SS=0;isd1700_par2_m(ISD1700_WR_APC2, 0x0400);ISD_SS=1;}void spi_wr_nvcfg (void){ISD_SS=0;isd1700_Npar_m(ISD1700_WR_NVCFG,2);ISD_SS=1;}void spi_ld_nvcfg (void){ISD_SS=0;isd1700_Npar_m(ISD1700_LD_NVCFG ,2);ISD_SS=1;}void spi_fwd (void){ISD_SS=0;isd1700_Npar_m(ISD1700_FWD,2);ISD_SS=1;}void spi_chk_mem(void){ISD_SS=0;isd1700_Npar_m(ISD1700_CHK_MEM,2);ISD_SS=1;}void seril_back_sate(uchar byte_number){uchar sate_temp;rest_isd_m_ptr();sate_temp=0;do{SBUF=*back_data_ptr++;while(!TI);TI=0;}while(++sate_temp<byte_number);}void rest_isd_m_ptr(void){isd_m_ptr=ISD_M_RAM;back_data_ptr=ISD_M_RAM_C;}void isd1700_Npar_m (uchar m_par,m_byte_count){uchar i;i=0;ISD_M_RAM[0]=m_par;isd_m_ptr=&ISD_M_RAM[1];do{*isd_m_ptr++=NULL;}while(++i<m_byte_count-1);rest_isd_m_ptr();i=0;do{*back_data_ptr++=T_R_m_byte(*isd_m_ptr++);i++;}while(i<m_byte_count);}void isd1700_par2_m(uchar m_par, uint data_par){uchar i;ISD_M_RAM[0]=m_par;ISD_M_RAM[1]=data_par;ISD_M_RAM[2]=data_par>>8;rest_isd_m_ptr();i=0;do{*back_data_ptr++=T_R_m_byte(*isd_m_ptr++);i++;}while(i<3);}void isd1700_7byte_m(uchar m_par, uint star_addr, uint end_addr) {uchar i;ISD_M_RAM[0]=m_par;ISD_M_RAM[1]=NULL;ISD_M_RAM[2]=star_addr;ISD_M_RAM[3]=star_addr>>8;ISD_M_RAM[4]=end_addr;ISD_M_RAM[5]=end_addr>>8;ISD_M_RAM[6]=NULL;rest_isd_m_ptr();i=0;do{*back_data_ptr++=T_R_m_byte(*isd_m_ptr++);i++;}while(i<=7);}uchar T_R_m_byte( uchar m_data ){uchar bit_nuber;uchar temp;bit_nuber=0;temp=0;do{ISD_SCLK=0;isd_delay(1);if((m_data>>bit_nuber&0x01)!=0){ISD_MOSI=1;}else{ISD_MOSI=0;}if(ISD_MISO){temp=(temp>>1)|0x80;}else{temp=temp>>1;}ISD_SCLK=1;isd_delay(1);}while(++bit_nuber<=7);ISD_MOSI=0;return (temp);}void isd_delay(int x){uchar i;for(; x>=1; x--){for(;i<=20;i++);}}void init(void){TMOD=0x21;SCON=0x50;TL0=0x00; //25msTH0=0x70; //25msTH1=0xE8;TL1=0xE8; //波特率:1200bps(12MHz:0xE6 11.0592MHz:0xE8)ET0=1;EA=1;TR1=1;IT0 = 0;EX0 = 0;spi_pu();spi_devid();}12864.h#ifndef _12864_H#define _12864_H#include "main.h"sbit RS =P3^2;sbit RW=P3^3;sbit EN=P3^4;void buzy();void TransferData(char data1,bit DI);void Dingwei(unsigned char line,unsigned char row);void delayms(unsigned int n);void delay(unsigned int m);void lcd_mesg(unsigned char code *adder1);void displayonechar(unsigned int data2);void initinal(void) ; //LCD字库初始化程序void clrram(void);void lcd_pos(unsigned char ,unsigned char );void write_dat(unsigned char);extern unsigned char time_show[];extern unsigned int aaa;#endif12864.c#include "12864.h"#define DataPort P1void initinal(void) //LCD字库初始化程序{TransferData(0x30,0); //8BIT设置,RE=0: basic instruction setTransferData(0x08,0); //Display on ControlTransferData(0x10,0); //Cursor Display Control光标设置TransferData(0x0C,0); //Display Control,D=1,显示开TransferData(0x01,0); //Display Clear}void buzy(){DataPort=0xff;RW=1;RS=0;EN=1;while(DataPort&0x80);EN=0;}void Dingwei(unsigned char line,unsigned char row) //定位在哪行哪列显示{unsigned int i;switch(line){case 1: i=0x80+row;break;case 2: i=0x90+row;break;case 3: i=0x88+row;break;case 4: i=0x98+row;break;default: i=0x80;break;}TransferData(i,0);delay(1);}void lcd_mesg(unsigned char code *addr) //传送一个字符串{while(*addr>0){TransferData(*addr,1);addr++;}}void TransferData(char data1,bit DI) //传送数据或者命令,当DI=0,传送命令,当DI=1,传送数据.{buzy();RW=0;RS=DI;DataPort=data1;EN=1;EN=0;}void delayms(unsigned int n) //延时10×n毫秒程序{unsigned int i,j;for(i=0;i<3*n;i++)for(j=0;j<2000;j++);}void delay(unsigned int m) //延时程序,微妙级{while(m--){_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();}}void write_cmd(unsigned char cmd){RS=0;RW=0;EN=0;P1=cmd;delayms(1);EN=1;delayms(1);EN=0;}void write_dat(unsigned char dat)RS=1;RW=0;EN=0;P1=dat;delayms(1);EN=1;delayms(1);EN=0;}void lcd_pos(unsigned char x,unsigned char y){unsigned char pos;if(x==0)x=0x80;else if(x==1)x=0x90;else if(x==2)x=0x88;else if(x==3)x=0x98;pos=x+y;write_cmd(pos);}void clrram(void){write_cmd(0x30);write_cmd(0x01);}Sound.h#ifndef _SOUND_H#define _SOUND_H#include "main.h"//以下为语音信息对应播放起始地址定义,A为开始,B为结束#define sound_0A 0x0012#define sound_0B 0x0017#define sound_1A 0x0019#define sound_1B 0x0025#define sound_2A 0x0027#define sound_2B 0x002e#define sound_3A 0x002f#define sound_3B 0x0039#define sound_4A 0x003b#define sound_4B 0x0048#define sound_5A 0x004a#define sound_5B 0x004f#define sound_6A 0x0052#define sound_6B 0x0159#define sound_7A 0x005c#define sound_7B 0x0062#define sound_8A 0x0065#define sound_8B 0x0131#define sound_9A 0x006f#define sound_9B 0x015F#define sound_10A 0x0079#define sound_10B 0x015E#define sound_11A 0x0082#define sound_11B 0x018A#define sound_12A 0x0091#define sound_12B 0x0100#define sound_13A 0x009f#define sound_13B 0x0100#define sound_14A 0x00ac#define sound_14B 0x0100void GetSound(unsigned char soundtick); void PlaySoundTick(unsigned char number); void delay_isd(unsigned int time);void short_delay();void long_delay();#endifSound.c#include "sound.h"void GetSound(unsigned char soundtick){ISD_SS=0;switch(soundtick){case 0:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_0A, sound_0B); }break;case 1:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_1A, sound_1B); }break;case 2:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_2A, sound_2B); }break;case 3:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_3A, sound_3B); }break;case 4:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_4A, sound_4B); }break;case 5:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_5A, sound_5B); }break;case 6:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_6A, sound_6B); }break;case 7:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_7A, sound_7B); }break;case 8:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_8A, sound_8B); }break;case 9:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_9A, sound_9B); }break;case 10:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_10A, sound_10B); }break;case 11:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_11A, sound_11B); }break;case 12:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_12A, sound_12B); }break;case 13:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_13A, sound_13B); }break;case 14:{ isd1700_7byte_m(ISD1700_SET_PLAY|ISD_LED, sound_14A, sound_14B); }break;default: break;}ISD_SS=1;}void PlaySoundTick(unsigned char number) {spi_stop ();delay_isd(30000);GetSound(number);}void delay_isd(unsigned int time){while(time--!=0);}void short_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);}void long_delay(){short_delay();short_delay();short_delay();short_delay();}Key.h#ifndef _KEY_H#define _KEY_H#include "main.h"sbit KEY1=P2^0;sbit KEY2=P2^1;sbit KEY3=P2^2;sbit KEY4=P2^3;sbit KEY5=P2^4;sbit KEY6=P2^5;sbit KEY7=P2^6;sbit KEY8=P2^7;sbit KEY_SURE=P3^6;void key_delay(unsigned char z); unsigned char keyscan_nor();#endifKey.c#include "key.h"unsigned char keyscan_nor() {if(!KEY1){key_delay(20);if(!KEY1){LED1=0;return 1;}}if(!KEY2){key_delay(20);if(!KEY2){LED2=0;return 2;}}if(!KEY3){key_delay(20);if(!KEY3){LED3=0;return 3;}}if(!KEY4){key_delay(20);if(!KEY4){LED4=0;return 4;}}if(!KEY5){key_delay(20);if(!KEY5){LED5=0;return 5;}}if(!KEY6){key_delay(20);if(!KEY6){LED6=0;return 6;}}if(!KEY7){key_delay(20);if(!KEY7){LED7=0;return 7;}}if(!KEY8){key_delay(20);if(!KEY8){LED8=0;return 8;}}return 0;}void key_delay(unsigned char z) {unsigned char x,y;for(x=z;x>0;x--)for(y=110;y>0;y--); }五.参与制作人员ZYL。