vhdl多功能數(shù)字萬(wàn)年歷_第1頁(yè)
vhdl多功能數(shù)字萬(wàn)年歷_第2頁(yè)
vhdl多功能數(shù)字萬(wàn)年歷_第3頁(yè)
vhdl多功能數(shù)字萬(wàn)年歷_第4頁(yè)
vhdl多功能數(shù)字萬(wàn)年歷_第5頁(yè)
已閱讀5頁(yè),還剩35頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

vhdl多功能數(shù)字萬(wàn)年歷

全部源代碼,已調(diào)試成功

基本要求:采用VHDL硬件描述語(yǔ)言或者電路圖描述的方式完成設(shè)

計(jì)。

1)設(shè)計(jì)一個(gè)萬(wàn)年歷系統(tǒng),可現(xiàn)實(shí)從秒到年的計(jì)數(shù)功能;

2)由于開僅具備四位數(shù)碼管,因此需要進(jìn)行功能切換,即利用開

發(fā)板上的一個(gè)按鍵完成小時(shí)/分鐘月/日、年等三種顯示的切換。

3)秒計(jì)數(shù)采用開發(fā)板上獨(dú)立的LED以秒閃進(jìn)行顯示;

4)同時(shí)切換設(shè)置模式與顯示模式(一個(gè)按鍵完成切換),完成每個(gè)

顯示的增減設(shè)置(兩個(gè)按鍵實(shí)現(xiàn)增減)。

說明:基本要求不需要提供閏月識(shí)別功能。

發(fā)揮要求:

1)提供整點(diǎn)時(shí)間報(bào)警功能;

2)提供鬧鐘功能;

3)提供閏月檢測(cè)功能;

4)以7個(gè)獨(dú)立的LED顯示星期。

全部源代碼如下,已調(diào)試成功

1,將50mhz轉(zhuǎn)為1ms時(shí)鐘count

LIBRARYIEEE;

USEIEEE.STD_LOGIC_1164.ALL;

USEIEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITYcountIS

PORT(clk:INSTD_LOGIC;

co:OUTSTD_LOGIC);

ENDcount;

ARCHITECTUREbehavOFcountIS

signalcount1:integerrange0to49999;

BEGIN

PROCESS(clk)

BEGIN

IFrising_edge(clk)THEN

count!<=countl+l;

ifcount1=49999then

countl<=0;co<='l';

elseco<='0';

endif;

endif;

endprocess;

endbehav;

2.秒模塊

LIBRARYIEEE;

USEIEEE.STD_LOGIC_1164.ALL;

USEIEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITYsecondIS

PORT(clk:INSTD_LOGIC;

sec:OUTintegerrange0to59;

miao:outstd_logic;

co:OUTSTD_LOGIC);

ENDsecond;

ARCHITECTUREbehavOFsecondIS

signalsect:integerrange0to59;

signaltemp:integerrange0to1000;

BEGIN

process(clk)

begin

IFrising_edge(clk)THEN

iftemp=1000thentemp<=0;

ifsect=59then

sect<=0;co<=T;

elsesect<=sect+l;co<='0';

endif;

elsetemp<=temp+1;co<='0';

endif;

endif;

endprocess;

process(temp,sect)

begin

iftemp<500then

miao<='l';

elsemiao<='0';

endif;

sec<=sect;

endprocess;

endbehav;

3?分模塊

LIBRARYIEEE;

USEIEEE.STD_LOGIC_1164.ALL;

USEIEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITYcentIS

PORT(clk,seco,centkeyadd,centkeysub:INSTD_LOGIC;

cent:outintegerrange0to59;

co:OUTSTD_LOGIC);

ENDcent;

ARCHITECTUREbehavOFcentIS

signalcentt:integerrange0to59;

begin

process(clk,seco)

begin

ifrising_edge(clk)then

ifseco='l'then

ifcentt=59thencentt<=0;co<='l';

elsecentt<=centt+l;co<='0';

endif;

elsifcentkeyadd='O'then

ifcentt=59thencentt<=0;

elsecentt<=centt+1;

endif;

elsifcentkeysub='O'then

ifcentt=Othencentt<=59;

elsecentt<=centt-1;

endif;

elseco<='0';

endif;

endif;

endprocess;

cent<=centt;

endbehav;

4時(shí)模塊

LIBRARYIEEE;

USEIEEE.STD_LOGIC_1164.ALL;

USEIEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITYhourIS

PORT(clk,cento,hourkeyadd,hourkeysub:INSTD_LOGIC;

hour:outintegerrange0to23;

co:OUTSTD_LOGIC);

ENDhour;

ARCHITECTUREbehavOFhourIS

signalhourt:integerrange0to59:=9;

begin

process(clk,cento)

begin

ifrising_edge(clk)then

ifcento=Tthen

ifhourt=23thenhourt<=0;co<='l';

elsehourt<=hourt+1;co<='0';

endif;

elsifhourkeyadd='0'then

ifhourt=23thenhourt<=0;

elsehourt<=hourt+1;

endif;

elsifhourkeysub='0'then

ifhourt=0thenhourt<=23;

elsehourt<=hourt-1;

endif;

elseco<='0';

endif;

endif;

endprocess;

hour<=hourt;

endbehav;

5.日模塊

LIBRARYIEEE;

USEIEEE.STD_LOGIC_1164.ALL;

USEIEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITYdayIS

PORT(clk,houro,daykeyadd,daykeysub:INSTD_LOGIC;

yue:inintegerrange1to31;

day:OUTintegerrange1to31;

co:OUTSTD_LOGIC);

ENDday;

ARCHITECTUREbehavOFdayIS

signaldayt:integerrange0to31:=24;

signalyuet:integerrange1to31;

begin

yuet<=yue;

process(clk,houro)

begin

ifrising_edge(clk)then

ifhouro=Tthen

ifdayt=yuetthendayt<=0;co<=T;

elsedayt<=dayt+1;

endif;

elsifdaykeyadd='O'then

ifdayt=yuetthendayt<=0;

elsedayt<=dayt+1;

endif;

elsifdaykeysub='O'then

ifdayt=Othendayt<=yuet;

elsedayt<=dayt-1;

endif;

elseco<='0';

endif;

endif;

endprocess;

day<=dayt;

endbehav;

6.月模塊

LIBRARYIEEE;

USEIEEE.STD_LOGIC_1164.ALL;

USEIEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITYmonthIS

PORT(clk,dayo,monthkeyadd,monthkeysub,run:INSTD_LOGIC;

month:outintegerrange1to12;

yue:outintegerrange1to31;

co:OUTSTD_LOGIC);

ENDmonth;

ARCHITECTUREbehavOFmonthIS

signalmontht:integerrange1to12:=2;

begin

process(clk,dayo)

begin

ifrising_edge(clk)then

ifdayo='l'then

ifmontht=12thenmontht<=1;co<='1';

elsemontht<=montht+1;

endif;

elsifmonthkeyadd='0'then

ifmontht=12thenmontht<=1;

elsemontht<=montht+1;

endif;

elsifmonthkeysub='0'then

ifmontht=lthenmontht<=12;

elsemontht<=montht-1;

endif;

elseco<='0';

endif;

endif;

endprocess;

month<=montht;

—閏月檢測(cè)功能

process(montht,run)

begin

CASEmonthtIS

WHEN2=>ifrun='1'thenyue<=29;elseyue<=28;endif;——二月

WHEN3=>yue<=30;

—四月

WHEN6=>yue<=30;

-六月

WHEN9=>yue<=30;

WHENll=>yue<=30;

-H~月

WHENothers=>yue<=31;

ENDCASE;

ENDPROCESS;

ENDbehav;

3?年模塊

LIBRARYIEEE;

USEIEEE.STD_LOGIC_1164.ALL;

USEIEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITYyearIS

PORT(clk,montho,yearkeyadd,yearkeysub:INSTD_LOGIC;

year:outintegerrange0to99;

run:OUTSTD_LOGIC);

ENDyear;

ARCHITECTUREbehavOFyearIS

signalyeart:integerrange0to59:=13;

begin

process(clk,montho)

begin

ifrising_edge(clk)then

ifmontho='rthen

ifyeart=59thenyeart<=0;

elseyeart<=yeart+l;

endif;

elsifyearkeyadd='O'then

ifyeart=59thenyeart<=0;

elseyeart<=yeart+1;

endif;

elsifyearkeysub='O'then

ifyeart=Othenyeart<=59;

elseyeart<=yeart-1;

endif;

endif;

endif;

endprocess;

year<=yeart;

process(yeart)

begin

if(yeartmod4)=0then

run<='l';

elserun<='0';

endif;

endprocess;

endbehav;

9.顯示模塊

-顯示模塊

LIBRARYIEEE;

USEIEEE.STD_LOGIC_1164.ALL;

USEIEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITYdisplayIS

PORT(

sec,cent:inintegerrange0to59;

hour:inintegerrange0to23;

day:inintegerrange1to31;

month:inintegerrange1to12;

year:inintegerrange0to99;

cento,houro,elk,keyO,keyI,key2,key3:INSTD_LOGIC;

dis:OUTSTD_LOGIC_VECTOR(7DOWNTO0);

centkeyadd,centkeysub,hourkeyadd,hourkeysub,daykeyadd,daykeysu

b,monthkeyadd,monthkeysub:outstd_logic;--力口減控制輸出

yearkeyadd,yearkeysub:outstd_logic;

dis1en,dis2en,dis3en,dis4en,beep:outstd_logic;--數(shù)碼管使能,設(shè)

置指示,蜂鳴器輸出

ledweekend:outstd_logic_vector(6downto0));

ENDdisplay;

ARCHITECTUREbehavOFdisplayIS

typestate_typeis(sO,sI,s2,s3,s4);

signalpre_s,next_s:state_type;

typestateis(cl,c2,c3,c4);

signalpre_c,next_c:state;

constantledO:std_logic_vector(7downto0):="l1000000";

constantledl:std_logic_vector(7downto0):="11111001";

constantled2:std_logic_vector(7downto0):="10100100";

constantled3:std_logic_vector(7downto0):="10110000";

constantled4:std_logic_vector(7downto0):="10011001";

constantled5:std_logic_vector(7downto0):="10010010";

constantled6:std_logic_vector(7downto0):="10000010";

constantled7:std_logic_vector(7downto0):="l1111000";

constantled8:std_logic_vector(7downto0):="10000000";

constantled9:std_logic_vector(7downto0):="10010000";

signalcount1:integerrange0to99;

signalcount2:integerrange0to99;

signalcount3:integerrange0to99;

signalcount4:integerrange0to99;

signalset:std_logic_vector(1downto0):="00";

signalweekend:std_logic_vector(6downto0):="0000001";

signalacentadd,acentsub,ahouradd,ahoursub:std_logic:='0';

signalahour,acent,centadd,centsub,houradd,hoursub:integerrange0to

59;

signalweekendset:std_logic:='1

signal

centl,centh,hourl,hourh,dayl,dayh,monthl,monthh,yearl,yearh:integer

range0to9;

signalsec1,sec2,sec3,sec4,acentl,acenth,ahourl,ahourh:integerrange0

to9;

begin

--界nn轉(zhuǎn)換狀態(tài)機(jī)

process(keyO)

begin

iffalling_edge(keyO)then

pre_s<=next_s;

endif;

endprocess;

-掃描狀態(tài)機(jī)

process(clk)

begin

ifrising_edge(clk)then

pre_c<=next_c;

endif;

endprocess;

process(keyl)

begin

iffalling_edge(key1)then

ifset=2then

set<="00";

else

set<=set+l;

endif;

endif;

endprocess;

centl<=centmod10;centh<=cent/10;

hourl<=hourmod10;hourh<=hourh/10;

dayl<=daymod10;dayh<=day/10;

monthl<=monthmod10;monthh<=month/10;

yearl<=yearmod10;yearh<=year/l0;

acentl<=acentmod10;acenth<=acent/10;

ahourl<=ahourmod10;ahourh<=ahourh/10;

-顯示切換狀態(tài)機(jī)

Pl:

process(pre_s,set,centl,centh,hourl,hourh,dayl,dayh,monthl,monthh,yearl,

yearh,key2,key3,acentl,acenth,ahourl,ahourh)

begin

casepre_sis

whensO=>count4<=centl;count3<=centh;--顯示時(shí)鐘

count2<=hourl;countl<=hourh;

next_s<=s1;weekendset<=T;

daykeyadd<='1';daykeysub<='l';monthkeyadd<='l';monthkeysub<='1';

yearkeyadd<='1';yearkeysub<='1';

acentadd<='l';acentsub<='1';ahouradd<='1';ahoursub<='1

ifset=1then

centkeyadd<=key2;centkeysub<=key3;hourkeyadd<='r;hourkeysub<='l'

elsifset=2then

hourkeyadd<=key2;hourkeysub<=key3;centkeyadd<='l';centkeysub<='1'

elsecentkeyadd<='r;centkeysub<='l';

hourkeyadd<='1';hourkeysub<=T;

endif;

whensl=>count4<=dayl;count3<=dayh;--顯示日期

count2<=monthl;countl<=monthh;

next_s<=s2;weekendset<='1';

centkeyadd<='l';centkeysub<='1';hourkeyadd<='1';hourkeysub<='1';

yearkeyadd<='1';yearkeysub<='1';

acentadd<='l';acentsub<='1';ahouradd<='1';ahoursub<='1

ifset=lthen

daykeyadd<=key2;daykeysub<=key3;monthkeyadd<='l';monthkeysub<=

T;

elsifset=2then

monthkeyadd<=key2;monthkeysub<=key3;daykeyadd<='r;daykeysub<=

T;

elsedaykeyadd<='1';daykeysub<='1';monthkeyadd<='1';monthkeysub<='1

?.

endif;

whens2=>count4<=yearl;count3<=yearh;--顯示年份

count2<=0;count1<=2;

next_s<=s3;weekendset<='l';

daykeyadd<='l';daykeysub<='l';monthkeyadd<='1';monthkeysub<='1';

centkeyadd<=T;centkeysub<='1';hourkeyadd<='1';hourkeysub<='1';

acentadd<='l';acentsub<='1ahouradd<='1';ahoursub<='1

ifset=lorset=2thenyearkeyadd<=key2;yearkeysub<=key3;

elseyearkeyadd<='1';yearkeysub<='1

endif;

whens3=>count4<=l;count3<=l;--星期控制狀態(tài)

count2<=1;count1<=1;

next_s<=s4;

daykeyadd<='1';daykeysub<='l';monthkeyadd<='l';monthkeysub<='1';

centkeyadd<='l';centkeysub<='1';hourkeyadd<='1';hourkeysub<='1';

acentadd<='l';acentsub<='1';ahouradd<='1';ahoursub<='1

yearkeyadd<='1';yearkeysub<='1weekendset<='O';

whens4=>count4<=acentl;count3<=acenth;--鬧鐘設(shè)置

狀態(tài)

count2<=ahourl;countl<=ahourh;

next_s<=sO;

daykeyadd<='1';daykeysub<='l';monthkeyadd<='l';monthkeysub<='1';

centkeyadd<='l';centkeysub<='1';hourkeyadd<='1';hourkeysub<='1';

yearkeyadd<='1';yearkeysub<='1weekendset<='1

ifset=lthenacentadd<=key2;acentsub<=key3;

ahouradd<='r;ahoursub<='l';

elsifset=2then

ahouradd<=key2;ahoursub<=key3;acentadd<='l';acentsub<=T;

elseacentadd<='1';acentsub<='l';ahouradd<='r;ahoursub<='l';

endif;

endcase;

endprocess;

-鬧鐘功能

process(clk,acent,centadd,centsub)

begin

ifrising_edge(clk)then

ifacent=59then

acent<=0;

else

acent<=centadd-centsub;

endif;

endif;

endprocess;

process(acentadd)

begin

iffalling_edge(acentadd)then

ifacent<60then

centadd<=centadd+1;

elsecentadd<=0;

endif;

endif;

endprocess;

process(acentsub)

begin

iffalling_edge(acentsub)then

ifacent<60then

ifacent>0then

centsub<=centsub+1;

elsenull;

endif;

elsecentsub<=0;

endif;

endif;

endprocess;

process(clk,ahour,houradd,hoursub)

begin

ifrising_edge(clk)then

ifahour=23then

ahour<=0;

elseahour<=houradd-hoursub;

endif;

endif;

endprocess;

process(ahouradd)

begin

iffalling_edge(ahouradd)then

ifahour<23then

houradd<=houradd+1;

elsehouradd<=0;

endif;

endif;

endprocess;

process(ahoursub)

begin

iffalling_edge(ahoursub)then

ifahour<23then

ifahour>0then

hoursub<=hoursub+l;

elsenull;

endif;

elsehoursub<=0;

endif;

endif;

endprocess;

-鬧鐘

process(clk,cent,hour,acent,ahour)

variableacount:integerrange0to30;

begin

ifrising_edge(clk)then

ifacent=centandahour=hourthen

beep<='0';

elsifcento=Tthen

beep<='0';

elsebeep<=T;

endif;

endif;

endprocess;

-星期顯示和設(shè)置

process(weekendset,clk,key2,key3)

begin

ifrising_edge(clk)then

ifweekend="0000000"then

weekend<="0000001";

elsifhouro=Tthen

weekend<=weekend(5downto0)&'0';

elsifweekendset='O'then

ifkey2='O'then

weekend<=weekend(5downto0)&'0';

elsifkey3='O'then

weekend<='0'&weekend(6downto1);

endif;

elsenull;

endif;

endif;

endprocess;

ledweekend<=weekend;

p3:process(pre_c,count4,count3,count2,countl)

begin

casepre_cis

whencl=>next_c<=c2;

dis1en<='1';dis2en<='l';dis3en<='l';dis4en<='0';

casecount4is

when0=>dis<=ledO;

when1=>dis<=ledl;

when2=>dis<=led2;

when3=>dis<=led3;

when4=>dis<=led4;

when5=>dis<=led5;

when6=>dis<=led6;

when7=>dis<=led7;

when8=>dis<=led8;

when9=>dis<=led9;

whenothers=>dis<=ledO;

endcase;

whenc2=>

next_c<=c3;

dislen<='l';dis2en<='1';dis3en<='0';dis4en<='1';

casecount3is

when0=>dis<=ledO;

when1=>dis<=ledl;

when2=>dis<=led2;

when3=>dis<=led3;

when4=>dis<=led4;

when5=>dis<=led5;

when6=>dis<=led6;

when7=>dis<=led7;

when8=>dis<=led8;

when9=>dis<=led9;

whenothers=>dis<=ledO;

endcase;

whenc3=>

next_c<=c4;

dis1en<='1';dis2en<='0';dis3en<='l';dis4en<='1';

casecount?is

when0=>dis<=ledO;

when1=>dis<=ledl;

when2=>dis<=led2;

when3=>dis<=led3;

when4=>dis<=led4;

when5=>dis<=led5;

when6=>dis<=led6;

when7=>dis<=led7;

when8=>dis<=led8;

when9=>dis<=led9;

whenothers=>dis<=ledO;

endcase;

whenc4=>

next_c<=cl;

dis1en<='0';dis2en<='1';dis3en<='l';dis4en<='1';

casecount1is

when0=>dis<=ledO;

when1=>dis<=ledl;

when2=>dis<=led2;

when3=>dis<=led3;

when4=>dis<=led4;

when5=>dis<=led5;

when6=>dis<=led6;

when7=>dis<=led7;

when8=>dis<=led8;

when9=>dis<=led9;

whenothers=>dis<=ledO;

endcase;

endcase;

endprocess;

endbehav;

10.頂層文件

LIBRARYIEEE;

USEIEEE.STD_LOGIC_1164.ALL;

USEIEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITYcalendarIS

PORT(clk,keyO,key1,key2,key3:INSTD_LOGIC;

disIen,dis2en,dis3en,dis4en,setled,beep:outstd_logic;

dis:OUTSTD_LOGIC_VECTOR(7DOWNTO0);

ledweekend:outstd_logic_vector(6downto0));

ENDcalendar;

ARCHITECTUREbehavOFcalendarIS

componentkey

PORT(CLK,kin:INSTD_LOGIC;

kout:OUTSTD_LOGIC);

ENDcomponent;

componentcount

PORT(clk:INSTD_LOGIC;

co:OUTSTD_LOGIC);

ENDcomponent;

componentsecond

PORT(clk:INSTD_LOGIC;

sec:OUTintegerrange0to59;

miao:outstd_logic;

co:OUTSTD_LOGIC);

ENDcomponent;

componentcent

PORT(clk,seco,centkeyadd,centkeysub:INSTD_LOGIC;

cent:outintegerrange0to59;

co:OUTSTD_LOGIC);

ENDcomponent;

componenthour

PORT(clk,cento,hourkeyadd,hourkeysub:INSTD_LOGIC;

hour:outintegerrange0to23;

co:OUTSTD_LOGIC);

ENDcomponent;

componentday

PORT(elk,houro,daykeyadd,daykeysub:INSTD_LOGIC;

yue:inintegerrange1to31;

day:OUTintegerrange1to31;

co:OUTSTD_LOGIC);

ENDcomponent;

componentmonth

PORT(clk,dayo,monthkeyadd,monthkeysub,run:INSTD_LOGIC;

month:outintegerrange1to12;

yue:outintegerrange1to31;

co:OUTSTD_LOGIC);

ENDcomponent;

componentyear

PORT(clk,montho,yearkeyadd,yearkeysub:INSTD_LOGIC;

year:outintegerrange0to99;

run:OUTSTD_LOGIC);

ENDcomponent;

componentdisplay

PORT(

sec,cent:inintegerrange0to59;

hour:inintegerrange0to23;

day:inintegerrange1to31;

monthrinintegerrange1to12;

year:inintegerrange0to99;

cento,houro,elk,keyO,keyI,key2,key3:INSTD_LOGIC;

dis:OUTSTD_LOGIC_VECTOR(7DOWNTO0);

centkeyadd,centkeysub,hourkeyadd,hourkeysub,daykeyadd,daykeysu

b,monthkeyadd,monthkeysub:outstd_k)gic;--加減控制輸出

yearkeyadd,yearkeysub:outstd_logic;

dis1en

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論