基于5單片機控制的語音報時萬年歷課程設計_第1頁
基于5單片機控制的語音報時萬年歷課程設計_第2頁
基于5單片機控制的語音報時萬年歷課程設計_第3頁
基于5單片機控制的語音報時萬年歷課程設計_第4頁
基于5單片機控制的語音報時萬年歷課程設計_第5頁
已閱讀5頁,還剩33頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、基于51單片機控制的語音報時萬年歷20/11/2013 SDU(WH)一. 實驗要求運用單片機及相關外設實現(xiàn)以下功能:1)萬年歷及時鐘顯示2)時間日期可調3)可對時間進行整點報時和隨機報時二. 方案分析根據(jù)實驗要求,選用 STC公司的8051系列,STC12C5A16S2增強型51單片機。此單 片機功能強大,具有片內EEPROM、1T分頻系數(shù)、片內 ADC轉換器等較為實用功能,故選用此款。實驗中,對日期和時間進行顯示,顯示的字符數(shù)較多,故選用12864LCD屏幕。該屏幕操作較為便捷,外圍電路相對簡單,實用性較強。為了實現(xiàn)要求中的時間日期可調,故按鍵是不可缺少的, 所以使用了較多的按鍵。 一方面

2、,單片機的I/O 口較為充足;另一方面,按鍵較多,選擇的余地較大,方便編程控制。實驗中,并未要求對時間和日期進行保存和掉電續(xù)運行,所以并未添加EEPROM和DS12C887-RTC芯片。實際上,對萬年歷來說,這是較為重要的,但為了方便實現(xiàn)和編程的 簡單,此處并未添加,而是使用單片機的定時器控制時間,精度有差別。且上電默認時間為 2014-01-01 09:00:00之后需要手動調整為正確時間。要求中的語音報時功能,這里選用ISD1760芯片的模塊來幫助實現(xiàn)。此模塊通過軟件模擬SPI協(xié)議控制。先將所需要的聲音片段錄入芯片的EEPROM區(qū)域,之后讀出各段聲音的地址段,然后在程序中定義出相應地址予以

3、控制播放哪一聲音片段。三電路硬件設計PdVMHJE3.? 耐如IS.Y WI.- lz#Y cor-BLL呻 II KH T7DJLEDfTKDY忠HZKLEffOVVu血Ntor-rot叫-AOCALZDXm0實際效果圖四.程序代碼部分Mai n.h#ifndef _MAIN_H #defi ne _MAIN_H#i nclude reg52.h#i nclude INTRINS.H#in clude math.h#i nclude stri ng.h#i nclude key.h#i nclude led.h#i nclude 12864.h#i nclude mai n. h#in cl

4、ude isd1700.h#in clude so un d.h exter n un sig ned int count;exter n un sig ned int key_time8; exter n un sig ned char key_ new;exter n un sig ned char key_old;exter n un sig ned char stop_flag; exter n un sig ned char key_follow8;exter n un sig ned int key_ nu m8;sbit BEEP=P3A7;sbit ISD_SS=P0A7;sb

5、it ISD_MISO=P0A4;sbit ISD_MOSI=P0A5;sbit ISD_SCLK=P0A6;exter n un sig ned char date_show; exter n un sig ned char time_show; exter n un sig ned char sec;exter n un sig ned char min;exter n un sig ned char hour;exter n un sig ned char day;exter n un sig ned char mon th;exter n un sig ned char year_f;

6、exter n un sig ned char year_l; extern un sig ned char leap_year_flag; exter n un sig ned char update_flag;exter n un sig ned char adjust_flag;exter n un sig ned char key;un sig ned char report。;#en difMain .c#i nclude mai n. hun sig ned int coun t=0;un sig ned int key_ nu m8=0;un sig ned char key_

7、new=0;un sig ned char key_old=0;un sig ned char stop_flag=0;un sig ned char key_follow8=0;un sig ned char sec=1;un sig ned char min=0;un sig ned char hour=9;un sig ned char day=1;un sig ned char mon th=1;un sig ned char year_f=20;un sig ned char year_l=14;un sig ned char leap_year_flag=0;un sig ned

8、char date_show=2014-01-01;un sig ned char time_show=09:00:00;un sig ned char update_flag=1;un sig ned char key=0;un sig ned char adjust_flag=0;un sig ned char adjust_pos=0;un sig ned char report_flag=0;void mai n()un sig ned char i;P2=0XFF;BEEP=0;ini t();in it in al();/調用LCD字庫初始化程序TMOD=0x01;使用定時器TO*

9、/TH0=(65536-1000)/256;TL0=(65536-1000)%256;EA=1;/定時器高八位賦初值/定時器低八位賦初值/開中斷總允許ET0=1;/允許T0中斷TR0=1;/啟動定時器T0 while(1)if(update_flag)lcd_pos(1,0);for(i=0;i10;i+) write_dat(date_showi);lcd_pos(2,4);for(i=0;i=80)sec=0;if(mi n=80) mi n=0;if(hour=40) hour=0;if(mo nth30)mon th=1;if(day50)day=0;if(year_f=120)yea

10、r_f=0;if(year_l=120)year_l=0;if(key=3)report_flag=1;if(report_flag)clrram();Di ngwei(2,1);lcd_mesg(REPORTING!); report();clrram();void timeO() in terrupt 1static un sig ned char timer=0;TH0=(65536-50000)/256; 定時器高八位賦初值 TL0=(65536-50000)%256; /定時器低八位賦初值 timer+;if(timer=20)sec+;time_show6=sec/10+48; t

11、ime_show7=sec%10+48; if(sec=60)sec=0;mi n+;time_show6=sec/10+48; time_show7=sec%10+48;time_show3=mi n/10+48;time_show4=mi n%10+48;if(min=60)mi n=0;hour+;time_show3=mi n/10+48;time_show4=mi n%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=h

12、our%10+48; date_show8=day/10+48;date_show9=day%10+48;if(day=29& !leap_year_flag&mon th=2)|(day=30&leap_year_flag&mon th=2)|(day=31 &(mon th=4|mo nth=6|mo nth=9|mo nth=11)|(mo nth=32)day=1;mon th+;date_show8=day/10+48;date_show9=day%10+48;date_show5=mo nth/10+48;date_show6=mo nth%10+48;if(mon th=13)m

13、on th=1;year_l+;date_show5=mo nth/10+48;date_show6=mo nth%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+;0)if(!(year_f*100+year_l)%4)&(year_f*100+year_l)%100)|(!(year_f*100+year_l)%40leap_year_flag=1;elseleap_year_

14、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=mi n%10+48;time_show3=mi n/10+48;time_show1=hour%10+48;time_show0=hour/10+48; date_show9=day%10+48; date_sh

15、ow8=day/10+48; date_show6=mo nth%10+48; date_show5=mo nth/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_show 6=;else if(adjust_pos=2) time_show4=;else if(adjust

16、_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_show 6=;else if(adjust_pos=9) date_show5=;else if(adjust_pos=10) date_show3=;else if(adjust_pos=11) date_show2=;else

17、if(adjust_pos=12) date_show1=;else if(adjust_pos=13) date_show0=;update_flag=1;if(!mi n&! sec&!adjust_flag) report_flag=1;un sig ned char report()PlaySou ndTick(11);Ion g_delay();if(!mi n)if(hour10&hour20)PlaySou ndTick(10); short_delay();PlaySou ndTick(hour-10); short_delay();PlaySou ndTick(12); sh

18、ort_delay();PlaySou ndTick(14); short_delay();else if(hour=20)PlaySou ndTick(2); short_delay();PlaySou ndTick(10); short_delay();PlaySou ndTick(12); short_delay();PlaySou ndTick(14); short_delay();elsePlaySou ndTick(2); short_delay();PlaySou ndTick(10); short_delay();PlaySou ndTick(hour-20); short_d

19、elay();PlaySou ndTick(12); short_delay();PlaySou ndTick(14); short_delay();elseif(hour10&hour10&mi n%10)PlaySou ndTick(mi n/10); short_delay();PlaySou ndTick(10); short_delay();PlaySou ndTick(mi n-10*(mi n/10); short_delay();PlaySou ndTick(13); short_delay();elsePlaySou ndTick(mi n/10); short_delay(

20、);PlaySou ndTick(10); short_delay();PlaySou ndTick(13); short_delay();report_flag=0; time_show7=sec%10+48; time_show6=sec/10+48; time_show4=mi n%10+48; time_show3=mi n/10+48; time_show1=hour%10+48; time_show0=hour/10+48; date_show9=day%10+48; date_show8=day/10+48;date_show6=mo nth%10+48; date_show5=

21、mo nth/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;lsd1700.h#ifndef _ISD1760_H#defi ne _ISD1760_H#in clude mai n.h#defi ne ISD1700_PU0x01#defi ne ISD1700_STOP0X02#defi ne ISD1700_REST0x03#defi ne ISD1700_CLR_INT0x04#define ISD17

22、00 RD STAUS0x05#defi ne ISD1700_RD_PLAY_PTR 0x06#defi ne ISD1700_PD0x07#defi ne ISD1700_RD_REC_PTR0x08#defi ne ISD1700_DEVID0x09#defi ne ISD1700_PLAY0x40#defi ne ISD1700_REC0x41#defi ne ISD1700_ERASE0x42#defi ne ISD1700_G_ERASE0x43#defi ne ISD1700_RD_APC0x44#defi ne ISD1700_WR_APC10x45#defi ne ISD17

23、00_WR_APC20x65#defi ne ISD1700_WR_NVCFG0x46#defi ne ISD1700_LD_NVCFG0x47#defi ne ISD1700_FWD0x48#defi ne ISD1700_CHK_MEM0x49#defi ne ISD1700_EXTCLK0x4A#defi ne ISD1700_SET_PLAY0x80#defi ne ISD1700_SET_REC0x81#defi ne ISD1700_SET_ERASE0x82#defi ne NULL0x00#define ISD LED0x10extern un sig ned char dat

24、a ISD_C0MM_RAM_C7;exter n voidin it(void);extern voiddelay_isd(i nt x);exter n voidcomm_sate(void);extern voidrest_isd_comm_ptr(void);extern un sig ned char T_R_comm_byte(u nsig ned char comm_data );extern voidisd1700_par2_com m(un sig ned char comm_par, un sig ned int data_par);exter n voidisd1700_

25、Npar_com m(un sig ned char comm_par,comm_byte_co un t);extern voidisd1700_7byte_comm(unsigned char comm_par, unsigned int star_addr, unsignedint en d_addr);exter n voidspi_pu (void);exter n voidspi_stop (void);exter n voidspi_Rest ( void );extern voidspi_CLR_INT(void);extern voidspi_RD_STAUS(void);e

26、xtern voidspi_RD_play_ptr(void);exter n voidspi_pd(void);extern voidspi_RD_rec_ptr(void);exter n voidspi_devid(void);exter n voidspi_play(void);extern voidspi_rec (void);exter n voidspi_erase (void);extern voidspi_G_ERASE (void);exter n voidspi_rd_apc(void);exter n voidspi_wr_apc1 (void);exter n voi

27、dspi_wr_apc2 (void);extern voidspi_wr_ nvcfg (void);extern voidspi_ld_ nvcfg (void);exter n voidspi_fwd (void);extern voidspi_chk_mem(void);extern voidspi_CurrRowAddr(void);extern voidseril_back_sate( un sig ned char byte_ nu mber);exter n voidspi_set_opt( un sig ned char spi_set_comm);voidin it(voi

28、d);#en difIsd1700.c#pragma src#in elude isd1700.h#in elude so un d.h#defi ne uehar un sig ned char#defi ne uint un sig ned intsbit DAC_sy nc=P29sbit DAC_selk=P2A1;sbit DAC_din =卩2人2;bit re_fig;uehar data eomm_temp;uehar data ISD_COMM_RAM7;uehar data ISD_COMM_RAM_C7;uehar data *isd_eomm_ptr;uehar dat

29、a *back_data_ptr;void in it(void);void isd_delay(i nt x);void eomm_sate(void);void rest_isd_eomm_ptr(void);uehar T_R_eomm_byte( uehar eomm_data );void isd1700_par2_eomm(uehar eomm_par, uint data_par);void isd1700_Npar_comm(uchar eomm_par,eomm_byte_eo un t); /no parameter eommvoid isd1700_7byte_eomm(

30、uehar eomm_par, uint star_addr, uint en d_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_ree_ptr(void);void spi_devid(void);void spi_play(void);void spi_ree (void);void spi_e

31、rase (void);void spi_G_ERASE (void);void spi_rd_ape(void);voidspi_wr_apc1 (void);voidspi_wr_apc2 (void);voidspi_wr_ nvcfg (void);void spi_ld_ nvcfg (void);voidspi_fwd (void);voidspi_chk_mem(void);void spi_CurrRowAddr(void);voidseril_back_sate(uchar byte_ nu mber);void spi_set_opt(uchar spi_set_comm)

32、;voidcomm_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(sat

33、e_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)

34、 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

35、_set_opt(ISD1700_SET_REC); ISD_COMM_RAM_C0=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_temp8;RI=0;while(!RI);apc_temp|=SBUF;RI=0;ISD_SS=0;isd1700_

36、par2_comm(ISD1700_WR_APC2,apc_temp); ISD_SS=1;RI=0;if(re_fig)rest_isd_comm_ptr();sate_temp=0;doSBUF=*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,e nd_addr;RI=0;while(!RI);start_addr=SBUF;start_addr=start_addr8;RI=0;while(!RI);start_

37、addr|=SBUF;RI=0;while(!RI);en d_addr=SBUF;en d_addr=start_addr8;RI=0;while(!RI);en d_addr|=SBUF;RI=0;ISD_SS=0;isd1700_7byte_comm(spi_set_comm, start_addr, en d_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_ST

38、OP,2);ISD_SS=1;ISD_COMM_RAM_C0=ISD1700_STOP ; seril_back_sate(1);void spi_Rest (void)ISD_SS=O;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_STAUS(void) uchar i;ISD_SS=0;isd1700_Npar_comm(ISD1700_RD_STAUS,3);ISD_SS

39、=1;i=ISD_COMM_RAM_C1;j=ISD_COMM_RAM_C2;ISD_COMM_RAM_C1=ISD_COMM_RAM_C0;ISD_COMM_RAM_C0=i; seril_back_sate(3);void spi_CurrRowAddr(void) uchar i;ISD_SS=0;isd1700_Npar_comm(ISD1700_RD_STAUS,3);ISD_SS=1;i=ISD_COMM_RAM_C1;ISD_COMM_RAM_C1=ISD_COMM_RAM_C05|ISD_COMM_RAM_C15; seril_back_sate(3);void spi_RD_

40、play_ptr(void) uchar i;ISD_SS=0;isd1700_Npar_comm(ISD1700_RD_PLAY_PTR,4);ISD_SS=1;i=ISD_COMM_RAM_C3&0x03;ISD_COMM_RAM_C3=ISD_COMM_RAM_C2;ISD_C0MM_RAM_C2=i; seril_back_sate(4);void spi_pd(void)ISD_SS=0;isd1700_Npar_comm(ISD1700_PD,2);ISD_SS=1;void spi_RD_rec_ptr(void) uchar i;ISD_SS=0;isd1700_Npar_co

41、mm(ISD1700_RD_REC_PTR,4);ISD_SS=1;i=ISD_COMM_RAM_C3&0x03;ISD_COMM_RAM_C3=ISD_COMM_RAM_C2;ISD_COMM_RAM_C2=i; seril_back_sate(4);void spi_devid(void)ISD_SS=0; isd1700_Npar_comm(ISD1700_DEVID,3);ISD_SS=1;ISD_COMM_RAM_C2=ISD_COMM_RAM_C2&0xf8; seril_back_sate(3);void spi_play(void)ISD_SS=0;isd1700_Npar_c

42、omm(ISD1700_PLAY|ISD_LED,2);ISD_SS=1;void spi_rec (void)ISD_SS=0; isd1700_Npar_comm(ISD1700_REC|ISD_LED,2);ISD_SS=1;ISD_COMM_RAM_CO=ISD17OO_REC ;seril_back_sate(1);void spi_erase (void)ISD_SS=0; isd1700_Npar_comm(ISD1700_ERASE|ISD_LED,2);ISD_SS=1;void spi_G_ERASE (void)ISD_SS=0; isd1700_Npar_comm(IS

43、D1700_G_ERASE|ISD_LED,2);ISD_SS=1;void spi_rd_apc(void)ISD_SS=0;isd1700_Npar_comm(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_comm(ISD1700_WR_APC2, 0x0400);ISD_SS=1;void spi_wr_ nvcfg (void)ISD_SS=0; isd1700_Npar_comm(ISD1700_WR_

44、NVCFG ,2);ISD_SS=1;voidspi_ld_ nvcfg (void)ISD_SS=O; isd1700_Npar_comm(ISD1700_LD_NVCFG ,2);ISD_SS=1;void spi_fwd (void)ISD_SS=0;isd1700_Npar_comm(ISD1700_FWD,2);ISD_SS=1;void spi_chk_mem(void)ISD_SS=0; isd1700_Npar_comm(ISD1700_CHK_MEM,2);ISD_SS=1;void seril_back_sate(uchar byte_ nu mber)uchar sate_temp;rest_isd_comm_ptr();sate_temp=0;doSBUF=*back_data_ptr+;while(!TI);TI=0;while(+sate_tempbyte_ nu mber);void rest_isd_comm_ptr(void)isd_comm_ptr=ISD_COMM_RAM; ba

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論