實驗報告基于vhdl的數(shù)字鐘設計_第1頁
實驗報告基于vhdl的數(shù)字鐘設計_第2頁
實驗報告基于vhdl的數(shù)字鐘設計_第3頁
實驗報告基于vhdl的數(shù)字鐘設計_第4頁
實驗報告基于vhdl的數(shù)字鐘設計_第5頁
已閱讀5頁,還剩14頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、本科實驗報告題目:數(shù)字鐘課程名稱: 學院(系): 專 業(yè): 班 級: 學生姓名: 學 號: 完成日期: 成 績: 2011 年 12 月 12 日題目:數(shù)字鐘1 設計要求系統(tǒng)功能: 1.計時,數(shù)碼管顯示的時、分、秒的十進制數(shù)字顯示(小時從0023)計時器2.星期,lcd1602顯示星期:MON/TUE/WEN/THU/FRI/SAT/SUN3.校準,具有手動校星期、校時、校分、校秒的功能。4.秒表,顯示1%秒、60秒,60分,能手動開始和停止5.鬧鐘,能在設定的時間發(fā)出鬧鈴聲。6.整點報時,即從59分55秒起,每隔1秒鐘發(fā)出一次低音“嘟”的信號,連續(xù)2次,最后一次為高音“嘀”的信號,此信號結束

2、即達到整點,發(fā)音的同時伴有l(wèi)ed閃爍。7.倒計時,能在設定的時間開始倒計時,至0時0分0秒停止2 設計分析及系統(tǒng)方案設計一設計分析:依據(jù)功能要求,程序分為:1. 計時與校準模塊 計時:秒鐘計數(shù)到59后清零并向分鐘進一位,分鐘計數(shù)到59后清零并向時鐘進一位,時鐘計數(shù)到23后清零并向星期進一位,星期按照MON/TUE/WEN/THU/FRI/SAT/SUN循環(huán)變化 校準:使用k1/k0兩個功能鍵,k1切換要改變的位,k0校正2. 數(shù)碼管顯示模塊 顯示譯碼 利用k3切換顯示內容,根據(jù)不同模式關閉用不到的數(shù)碼管。3. lcd顯示模塊定義七個常量數(shù)組,數(shù)組內容分別為MON/TUE/WEN/THU/FRI

3、/SAT/SUN的ASC 碼。液晶初始化液晶顯示,將相應字母的ASC碼寫入ddram的相應地址中,由cnt1值決定地址, cnt1由0到2循環(huán),因此用到lcd開始的前三個位顯示字符。由星期(m)值決定寫入內容,m值不同,cnt1掃描顯示的就是不同的數(shù)組。4. 鬧鐘與整點報時模塊 整點報時:利用分頻得到1k和0.5k的頻率,當分鐘位到達59,秒鐘位為55、57時,將0.5k頻率接到輸出引腳,秒鐘位為59時,將1k頻率接到輸出引腳。 鬧鐘:到達鬧鐘時間,將1k頻率接到輸出引腳,時長3秒 Led閃爍:將led輸出引腳連接至頻率輸出引腳即可(設為inout)5. 秒表模塊 開啟顯示1%秒、60秒、60

4、分的數(shù)碼管。顯示小時的數(shù)碼管關閉 手動開始和停止,停止時顯示計時終止時間6. 倒計時模塊 顯示小時、分鐘,秒。顯示毫秒的數(shù)碼管關閉。 可以利用k2切換倒計時與設置倒計時時間狀態(tài),利用k1與k0設置倒計時時間。 至0時0分0秒倒計時終止,此時自動切換至時間設置狀態(tài)。二系統(tǒng)總體結果框圖:50MHZ計時與校準鬧鐘與整點報時秒表倒計時計時校準鬧鐘整點報時設置鬧鐘時間時間到鬧鐘響Key1切換校準位Key0校準數(shù)碼管顯示LCD顯示星期Key3切換模式Key2切換狀態(tài)Key3切換狀態(tài)分頻器3系統(tǒng)以及模塊硬件電路設計數(shù)碼管(圖中只有1個,共用8個):數(shù)碼管共陰極,故輸入低電平管亮 開關(4個全用):按鍵按下時

5、為低電平發(fā)光二極管(全部使用):引腳為高電平時led亮DE2開發(fā)板上使用的元件的管腳編號:接口名稱類型引腳號說明bsBidirPIN_K19蜂鳴器clkInputPIN_N250mhz時鐘k0InputPIN_G26控制按鍵k1InputPIN_N23k2InputPIN_P23k3InputPIN_W26lcd_blonOutputPIN_K2lcd背光燈LCD_Data0OutputPIN_J1lcd數(shù)據(jù)輸入LCD_Data1OutputPIN_J2LCD_Data2OutputPIN_H1LCD_Data3OutputPIN_H2LCD_Data4OutputPIN_J4LCD_Data

6、5OutputPIN_J3LCD_Data6OutputPIN_H4LCD_Data7OutputPIN_H3LCD_ENOutputPIN_K3lcd使能lcd_onOutputPIN_L4lcd開啟lcd_rsOutputPIN_K1寄存器選擇信號ResetinputPIN_N25lcd復位LCD_RWOutputPIN_K4液晶讀寫信號led0OutputPIN_AE23整點報時及鬧鐘顯示led1OutputPIN_AF23led2OutputPIN_AB21led3OutputPIN_AC22led4OutputPIN_AD22led5OutputPIN_AD23led6OutputP

7、IN_AD21led7OutputPIN_AC21led8OutputPIN_AA14led9OutputPIN_Y13led10OutputPIN_AA13led11OutputPIN_AC14led12OutputPIN_AD15led13OutputPIN_AE15led14OutputPIN_AF13led15OutputPIN_AE13led16OutputPIN_AE12led17OutputPIN_AD12led18OutputPIN_AE22led19OutputPIN_AF22led20OutputPIN_W19led21OutputPIN_V18led22OutputPIN

8、_U18led23OutputPIN_U17led24OutputPIN_AA20led25OutputPIN_Y18mbp0OutputPIN_V20秒表高位mbp1OutputPIN_V21mbp2OutputPIN_W21mbp3OutputPIN_Y22mbp4OutputPIN_AA24mbp5OutputPIN_AA23mbp6OutputPIN_AB24mbq0OutputPIN_AF10秒表低位mbq1OutputPIN_AB12mbq2OutputPIN_AC12mbq3OutputPIN_AD11mbq4OutputPIN_AE11mbq5OutputPIN_V14mbq6

9、OutputPIN_V13mp0OutputPIN_T2分高位mp1OutputPIN_P6mp2OutputPIN_P7mp3OutputPIN_T9mp4OutputPIN_R5mp5OutputPIN_R4mp6OutputPIN_R3mq0OutputPIN_U9分低位mq1OutputPIN_U1mq2OutputPIN_U2mq3OutputPIN_T4mq4OutputPIN_R7mq5OutputPIN_R6mq6OutputPIN_T3p0OutputPIN_Y23秒高位p1OutputPIN_AA25p2OutputPIN_AA26p3OutputPIN_Y26p4Outp

10、utPIN_Y25p5OutputPIN_U22p6OutputPIN_W24q0OutputPIN_AB23秒低位q1OutputPIN_V22q2OutputPIN_AC25q3OutputPIN_AC26q4OutputPIN_AB26q5OutputPIN_AB25q6OutputPIN_Y24hp0OutputPIN_L3時高位hp1OutputPIN_L2hp2OutputPIN_L9hp3OutputPIN_L6hp4OutputPIN_L7hp5OutputPIN_P9hp6OutputPIN_N9hq0OutputPIN_R2時低位hq1OutputPIN_P4hq2Outp

11、utPIN_P3hq3OutputPIN_M2hq4OutputPIN_M3hq5OutputPIN_M5hq6OutputPIN_M44 系統(tǒng)的VHDL設計VHDL語言源代碼VHDL語言源代碼:clock.vhd:ieee.std_logic_arith.all;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity clock isport(clk:in std_logic; led:out std_logic_vector(25 downto 0); k0: in std_logic;

12、 k1: in std_logic; k2: in std_logic; k3: in std_logic; bs: inout std_logic;-整點報時及鬧鐘 mbp,mbq,p,q,mp,mq,hp,hq:out std_logic_vector(6 downto 0);-p高q低 reset : in std_logic; lcd_rs : out std_logic; -寄存器選擇信號 LCD_RW : out std_logic; -液晶讀寫信號 LCD_EN : out std_logic; -液晶時鐘信號 lcd_on : out std_logic; lcd_blon:o

13、ut std_logic; LCD_Data : out std_logic_vector(7 downto 0); -液晶數(shù)據(jù)信號end;architecture a of clock iscomponent segport(inp:in integer range 0 to 10;outp:out std_logic_vector(6 downto 0);end component;component lcdPort ( CLK : in std_logic; -狀態(tài)機時鐘信號,同時也是液晶時鐘信號 m : in integer range 1 to 7;-顯示的星期轉換Reset : i

14、n std_logic; LCD_RS : out std_logic; -寄存器選擇信號 LCD_RW : out std_logic; -液晶讀寫信號 LCD_EN : out std_logic; -液晶時鐘信號lcd_on : out std_logic;lcd_blon:out std_logic; LCD_Data : out std_logic_vector(7 downto 0); -液晶數(shù)據(jù)信號end component;component rem1Port ( rint:in integer range 0 to 99; ri:inout integer range 0 t

15、o 10);end component;signal cp:std_logic;-0.01秒signal state:std_logic_vector(1 downto 0);-狀態(tài):00:計時與校準;01:秒表;10:鬧鐘;11:倒計時signal jjstate:std_logic;-狀態(tài):0:計時;1:校準signal dstate:std_logic;-倒計時狀態(tài):1:倒計時;0:設置時間signal djzstate:std_logic_vector(1 downto 0);-倒計時設置位的狀態(tài)signal mbi,mbj,i,j,mi,mj,hi,hj:integer range

16、0 to 10;-i高j低signal hour,min,sec:integer range 0 to 99;-計時signal mbnum,mbsec,mbmin:integer range 0 to 99;-秒表signal dhour,dmin,dsec:integer range 0 to 99;-倒計時signal mod_dsec,mod_dmin,mod_dhour,mod_mbnum,mod_mbsec,mod_mbmin,mod_nzhour,mod_nzmin1,mod_nzmin,mod_sec,mod_min,mod_hour:integer range 0 to 10

17、;-取高位值signal nzhour,nzmin:integer range 0 to 59;-鬧鐘signal week:integer range 1 to 7;-星期signal week1:integer range 1 to 7;-更改星期中間變量signal jzstate:std_logic_vector(1 downto 0);-計時設置位的狀態(tài)signal change_dstate:std_logic;-倒計時至0自動改變至設置狀態(tài)beginprocess(clk) variable num:integer range 0 to ; begin if rising_edg

18、e(clk) then if num= then cp=1;num:=0; else cp=0;num:=num+1; end if; end if; end process;process(bs)-控制led閃爍begin if bs=1 then led=1010; else led=0000; end if;end process;process(state,k2)begin if rising_edge(k2) then if state=11 then if dstate=1 then dstate=0; else dstatedjzstatedjzstatedjzstatedjzs

19、tate=00; end case; end if; end if; end if;end process; process(dhour,dmin,dsec)begin if dhour=0 and dmin=0 and dsec=0 then change_dstate=1; else change_dstate=0; end if;end process; process(cp,state,dstate,djzstate,k0)-倒計時variable dnum1:integer range 0 to 99;variable dnum2:integer range 0 to 29;begi

20、n if rising_edge(cp) then if state=11 then if dstate=1 and change_dstate=0 then- if dnum1=99 then dnum1:=0; if dsec=0 then dsec=59; if dmin=0 then dmin=59; if dhour=0 then dhour=23; else dhour=dhour-1; end if; else dmin=dmin-1; end if; else dsec if dnum2=10 then dnum2:=0; if dhour=23 then dhour=0; e

21、lse dhour-分校準 if dnum2=10 then dnum2:=0;if dmin=59 then dmin=0; if dhour=23 thendhour=0; else dhour=dhour+1; end if; else dmin-秒校準 if dnum2=10 then dnum2:=0; if dsec=59 thendsec=0;if dmin=59 then dmin=0; if dhour=23 thendhour=0; else dhour=dhour+1; end if; else dmin=dmin+1; end if; else dsecnull;end

22、 case;end if;end if;end if;end if;end process; process(k1,state,jjstate)begin if rising_edge(k1) then if state=00 then if jjstate=1 then case jzstate is when 00=jzstatejzstatejzstatejzstatejzstatestatestatestatestatestatejjstatejjstatejjstate=0; end case; end if; end if;end process;process(cp,state)

23、-鬧鐘variable set:std_logic;variable set1:std_logic; begin if rising_edge(cp) then if state=10 then if k2=0 then if set=0 then set:=1; if nzhour=23 then nzhour=0; else nzhour=nzhour+1; end if; end if; else set:=0; if k1=0 then if set1=0 then set1:=1; if nzmin=59 then nzmin=0; else nzmin=nzmin+1; end i

24、f; end if; else set1:=0; end if; end if; end if;end if;end process; process(cp,state)-秒表計時variable mbkey :std_logic;begin if rising_edge(cp) then if state=01 then if k2=0 then mbnum=0;mbsec=0;mbmin=0; mbkey:=1; end if; if k1=0 then mbkey:=0; end if; if mbkey=1 then if mbnum=99 then mbnum=0; if mbsec

25、=59 then mbsec=0; if mbmin=59 then mbmin=0; else mbmin=mbmin+1; end if; else mbsec=mbsec+1; end if; else mbnum=mbnum+1; end if; end if; end if; end if;end process;process(sec,min,hour,state,mbnum,mbsec,mbmin,nzhour,nzmin)-顯示每一位值begin if state=01 then-秒表 mbi=mod_mbnum; mbj=mbnum rem 10; i=mod_mbsec;

26、j=mbsec rem 10; mi=mod_mbmin; mj=mbmin rem 10; hi= 10; hj= 10; elsif state=10 then-鬧鐘 hi=mod_nzhour; hj=nzhour rem 10; mi=mod_nzmin1; mj=nzmin rem 10; mbi=10; mbj=10; i=10; j=10; elsif state=11 then i=mod_dsec; j=dsec rem 10; mi=mod_dmin; mj=dmin rem 10; hi=mod_dhour; hj=dhour rem 10; mbi=10; mbj=10

27、; else-計時校準 i=mod_sec; j=sec rem 10; mi=mod_min; mj=min rem 10; hi=mod_hour; hj=hour rem 10; mbi=10; mbj if num2=29 then num2:=0; if week=7 then week=1; else week if num2=29 then num2:=0; if hour=23 then hour=0; if week=7 then week=1; else week=week+1; end if; else hour-分校準 if num2=10 then num2:=0;i

28、f min=59 then min=0; if hour=23 thenhour=0; else hour=hour+1; end if; else min-秒校準 if num2=10 then num2:=0; if sec=59 thensec=0;if min=59 then min=0; if hour=23 thenhour=0; else hour=hour+1; end if; else min=min+1; end if; else secnull;end case;end if;- else-計時 if num1=99 then num1:=0; if sec=59 the

29、nsec=0;if min=59 then min=0; if hour=23 thenhour=0; if week=7 then week=1; else week=week+1; end if; else hour=hour+1; end if; else min=min+1; end if; else sec=sec+1; end if; else num1:=num1+1; end if;end if;end if;end process;process(clk,sec,min,dhour,dmin,dsec)-整點報時與鬧鐘variable num3:integer range 0

30、 to 24999;variable num4:integer range 0 to 2;variable bs1,bs2:std_logic; begin if rising_edge(clk) then if num3=24999 then num3:=0;bs1:=not bs1; if bs1=1 then bs2:=not bs2; end if; if min=59 then if sec=55 or sec=57 then bs=bs2; elsif sec=59 then bs=bs1; else bs=0; end if; end if; if hour=nzhour and

31、 min=nzmin and sec=3 then bs=bs1; elsif min=59 then if sec=55 or sec=57 then bs=bs2; elsif sec=59 then bs=bs1; elsif dhour=0 and dmin=0 and dsec=1 then bs=bs2; else bsoutpoutpoutpoutpoutpoutpoutpoutpoutpoutp outp=; end case;end process;end convert;lcd.vhd:library IEEE;use IEEE.STD_LOGIC_1164.ALL;use

32、 IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity lcd is Port ( CLK : in std_logic; -狀態(tài)機時鐘信號,同時也是液晶時鐘信號,其周期應該滿足液晶數(shù)據(jù)的建立時間 m : in integer range 1 to 7;Reset : in std_logic; LCD_RS : out std_logic; -寄存器選擇信號 LCD_RW : out std_logic; -液晶讀寫信號 LCD_EN : out std_logic; -液晶時鐘信號lcd_on : out std_l

33、ogic;lcd_blon:out std_logic; LCD_Data : out std_logic_vector(7 downto 0); -液晶數(shù)據(jù)信號end lcd;architecture Behavioral of lcd istype state is (set_dlnf,set_cursor,set_dcb,set_cgram,write_cgram,set_ddram,write_LCD_Data);signal Current_State:state;type ram1 is array(0 to 2) of std_logic_vector(7 downto 0);c

34、onstant cgram1 : ram1 :=(x4d,x4f,x4e);-mon-(x53,x41,x54);constant cgram2 : ram1 :=(x54,x55,x45);-tueconstant cgram3 : ram1 :=(x57,x45,x4e);-wenconstant cgram4 : ram1 :=(x54,x48,x55);-thuconstant cgram5 : ram1 :=(x46,x52,x49);-friconstant cgram6 : ram1 :=(x53,x41,x54);-satconstant cgram7 : ram1 :=(x5

35、3,x55,x4e);-sunsignal Clk_Out : std_logic;signal LCD_Clk : std_logic;beginprocess(CLK)-分頻進程,CLK輸入,CLK_Out輸出,50MHz輸入,1250Hz輸出,0.8ms variable n1:integer range 0 to 19999; begin if rising_edge(CLK) then if n119999 then n1:=n1+1; else n1:=0; Clk_Out=not Clk_Out; end if; end if;end process;LCD_RW = 0 ; -

36、RW=0;寫入設置LCD_EN = Clk_Out ; -用1250Hz作為LCD的使能,也作為LCD的時鐘LCD_Clk = Clk_Out; -用1250Hz作為LCD的時鐘lcd_on =1;lcd_blon=0;process(LCD_Clk,Reset,Current_State) -狀態(tài)機控制顯示variable cnt1: std_logic_vector(4 downto 0); begin if Reset=1 then Current_State=set_dlnf; - Reset就清屏,Reset接出用一個按鈕作為復位按鍵即可,按下就為0復位。 cnt1:=11110; LCD_RS=0; elsif rising_edge(LCD_Clk) then Current_State = Current_State ; LCD_RS cnt1:=00000; LCD_Data=; - /*清除顯示*/ 清屏指令 Current_State LCD_Data=; -/*設置8位格式,2行,5*7*/ Current_State LCD_Data=; -/*整體顯示,關光標,不閃爍*/ Current_State LCD_Data=; Current_State if cnt1=00011 thencnt1:=00000;LCD_Data=; e

溫馨提示

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

評論

0/150

提交評論