基于FPGA的万年历程序.docx

上传人:b****1 文档编号:3259246 上传时间:2023-05-05 格式:DOCX 页数:17 大小:17.19KB
下载 相关 举报
基于FPGA的万年历程序.docx_第1页
第1页 / 共17页
基于FPGA的万年历程序.docx_第2页
第2页 / 共17页
基于FPGA的万年历程序.docx_第3页
第3页 / 共17页
基于FPGA的万年历程序.docx_第4页
第4页 / 共17页
基于FPGA的万年历程序.docx_第5页
第5页 / 共17页
基于FPGA的万年历程序.docx_第6页
第6页 / 共17页
基于FPGA的万年历程序.docx_第7页
第7页 / 共17页
基于FPGA的万年历程序.docx_第8页
第8页 / 共17页
基于FPGA的万年历程序.docx_第9页
第9页 / 共17页
基于FPGA的万年历程序.docx_第10页
第10页 / 共17页
基于FPGA的万年历程序.docx_第11页
第11页 / 共17页
基于FPGA的万年历程序.docx_第12页
第12页 / 共17页
基于FPGA的万年历程序.docx_第13页
第13页 / 共17页
基于FPGA的万年历程序.docx_第14页
第14页 / 共17页
基于FPGA的万年历程序.docx_第15页
第15页 / 共17页
基于FPGA的万年历程序.docx_第16页
第16页 / 共17页
基于FPGA的万年历程序.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

基于FPGA的万年历程序.docx

《基于FPGA的万年历程序.docx》由会员分享,可在线阅读,更多相关《基于FPGA的万年历程序.docx(17页珍藏版)》请在冰点文库上搜索。

基于FPGA的万年历程序.docx

基于FPGA的万年历程序

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entitywannianliis

port(rst:

instd_logic;--2012-1-11-00-00-00

clk:

instd_logic;--系统时钟50M

clr:

instd_logic;

display_mode:

instd_logic;--显示年或时

inc:

instd_logic;--增加按键

dec:

instd_logic;

mode:

instd_logic;

seg8:

outstd_logic_vector(7downto0);--数码管段码

scan:

outstd_logic_vector(7downto0);--数码管位码

led:

outstd_logic_vector(3downto0));

end;

architectureoneofwannianliis

--signalstate:

std_logic_vector(2downto0);

--signaldis_mode:

std_logic_vector(1downto0);

signalstate:

integerrange0to7;--0为正常显示,1.2.3.4.5.6.分别对应修改时分秒年月日

signaldis_mode:

integerrange0to3;

--signalqhh,qhl,qmh,qml,qsh,qsl,qy1,qy2,qy3,qy4,qm1,qm2,qd1,qd2:

std_logic_vector(3downto0);

signalqhh,qhl,qmh,qml,qsh,qsl,qy1,qy2,qy3,qy4,qmonl,qmonh,qdl,qdh:

integerrange0to15;

signaldata:

integerrange0to15;

signalcnt:

integerrange0to7;

signalclk1khz,clk1hz,clk2hz,clk5ms:

std_logic;

--signalblink:

std_logic_vector(2downto0);

--signalinc_reg:

std_logic;

signalsec,min:

integerrange0to59;

signalhour:

integerrange0to23;

signalyear:

integerrange1to9999;

signalmonth:

integerrange1to12;

signalday,day_limit:

integerrange1to31;

begin

process(clk)

variablecount:

integerrange0to30000;

begin

ifclk'eventandclk='1'then

ifcount=25000thenclk1khz<=notclk1khz;count:

=0;

elsecount:

=count+1;

endif;

endif;

endprocess;

-------------------------------------------------------

process(clk)

variablecnte:

integerrange0to30000000;

begin

ifclk'eventandclk='1'then

ifcnte=25000000thenclk1hz<=notclk1hz;cnte:

=0;

elsecnte:

=cnte+1;

endif;

endif;

endprocess;

-----------------------------------------------------

process(clk)

variablecnt2:

integerrange0to25000000;

begin

ifclk'eventandclk='1'then

ifcnt2=12500000thenclk2hz<=clk2hz;cnt2:

=0;

elsecnt2:

=cnt2+1;

endif;

endif;

endprocess;

-----------------------------------------------------

process(clk)

variablecnnt:

integerrange0to600000;

begin

ifclk'eventandclk='1'then

ifcnnt=500000thenclk5ms<=clk5ms;cnnt:

=0;

elsecnnt:

=cnnt+1;

endif;

endif;

endprocess;

------------------------------------------

-----------------------------------------------

process(display_mode,clk1hz)

begin

ifdisplay_mode'eventanddisplay_mode='0'then

dis_mode<=dis_mode+1;

ifdis_mode=1then

dis_mode<=0;

endif;

endif;

endprocess;

-------------------------------------------

process(clk)

begin

year<=year;

month<=month;

day<=day;

hour<=hour;

min<=min;

sec<=sec;

endprocess;

-----------------------------------------

process(mode,clr,clk1hz)

begin

ifclr='0'then

state<=0;

elsifmode'eventandmode='0'then

state<=state+1;

ifstate=6then

state<=0;

endif;

endif;

endprocess;

-----------------------------------------------------------------------------------

process(clk1hz,state,dis_mode,inc,dec,clr,hour,sec,min,rst,year,month,day)

begin

ifrst='0'then

year<=2012;

month<=1;

day<=11;

hour<=0;

min<=0;

sec<=0;

--state<=0;

--dis_mode<=0;

elsifclr='0'then

hour<=23;

min<=59;

sec<=55;

year<=2013;

month<=1;

day<=12;

elsifclk1hz'eventandclk1hz='1'then

casestateis

when0=>led<="0000";

if((month=1)or(month=3)or(month=5)or(month=7)or(month=8)or(month=10)or(month=12))then

day_limit<=31;

endif;

ifmonth=2then

----if((year%4==0&&year%100!

=0)||(year%400==0))

if((((yearrem4)=0)and((yearrem100)/=0))or((yearrem400=0)))then

day_limit<=29;

else

day_limit<=28;

endif;

endif;

if((month=4)or(month=6)or(month=9)or(month=11))then

day_limit<=30;

endif;

sec<=sec+1;

ifsec=59then

sec<=0;

min<=min+1;

ifmin=59then

min<=0;

hour<=hour+1;

ifhour=23then

hour<=0;

day<=day+1;

ifday=day_limitthen

day<=1;

month<=month+1;

ifmonth=12then

month<=1;

year<=year+1;

ifyear=9999then

year<=1;

endif;

endif;

endif;

endif;

endif;

endif;

--ifsec=59thensec<=0;

--ifmin=59thenmin<=0;

--ifhour=23thenhour<=0;

--else

--hour<=hour+1;

--endif;

--else

--min<=min+1;

--endif;

--else

--sec<=sec+1;

--endif;

when1=>led<="0001";

ifinc='0'then

ifhour=23then

hour<=0;

elsehour<=hour+1;

endif;

elsifdec='0'then

ifhour=0then

hour<=23;

elsehour<=hour-1;

endif;

endif;

when2=>led<="0010";

ifinc='0'then

ifmin=59then

min<=0;

else

min<=min+1;

endif;

elsifdec='0'then

ifmin=0then

min<=59;

else

min<=min-1;

endif;

endif;

when3=>led<="0011";

ifinc='0'then

ifsec=59then

sec<=0;

else

sec<=sec+1;

endif;

elsifdec='0'then

ifsec=0then

sec<=59;

else

sec<=sec-1;

endif;

endif;

when4=>led<="0100";

ifinc='0'then

ifyear=9999then

year<=1;

else

year<=year+1;

endif;

elsifdec='0'then

ifyear=1990then

year<=2020;

else

year<=year-1;

endif;

endif;

when5=>led<="0101";

ifinc='0'then

ifmonth=12then

month<=1;

else

month<=month+1;

endif;

elsifdec='0'then

ifmonth=0then

month<=12;

else

month<=month-1;

endif;

endif;

when6=>led<="0110";

ifinc='0'then

ifday=day_limitthen

day<=1;

else

day<=day+1;

endif;

elsifdec='0'then

ifday=0then

day<=day_limit;

else

day<=day-1;

endif;

endif;

whenothers=>null;

endcase;

endif;

--endif;

endprocess;

----------------------------------------------------------------------

process(sec)

begin

casesecis

when0|10|20|30|40|50=>qsl<=0;

when1|11|21|31|41|51=>qsl<=1;

when2|12|22|32|42|52=>qsl<=2;

when3|13|23|33|43|53=>qsl<=3;

when4|14|24|34|44|54=>qsl<=4;

when5|15|25|35|45|55=>qsl<=5;

when6|16|26|36|46|56=>qsl<=6;

when7|17|27|37|47|57=>qsl<=7;

when8|18|28|38|48|58=>qsl<=8;

when9|19|29|39|49|59=>qsl<=9;

whenothers=>null;

endcase;

casesecis

when0|1|2|3|4|5|6|7|8|9=>qsh<=0;

when10|11|12|13|14|15|16|17|18|19=>qsh<=1;

when20|21|22|23|24|25|26|27|28|29=>qsh<=2;

when30|31|32|33|34|35|36|37|38|39=>qsh<=3;

when40|41|42|43|44|45|46|47|48|49=>qsh<=4;

when50|51|52|53|54|55|56|57|58|59=>qsh<=5;

whenothers=>null;

endcase;

endprocess;

--------------------------------------------------------------------

process(min)

begin

caseminis

when0|10|20|30|40|50=>qml<=0;

when1|11|21|31|41|51=>qml<=1;

when2|12|22|32|42|52=>qml<=2;

when3|13|23|33|43|53=>qml<=3;

when4|14|24|34|44|54=>qml<=4;

when5|15|25|35|45|55=>qml<=5;

when6|16|26|36|46|56=>qml<=6;

when7|17|27|37|47|57=>qml<=7;

when8|18|28|38|48|58=>qml<=8;

when9|19|29|39|49|59=>qml<=9;

whenothers=>null;

endcase;

caseminis

when0|1|2|3|4|5|6|7|8|9=>qmh<=0;

when10|11|12|13|14|15|16|17|18|19=>qmh<=1;

when20|21|22|23|24|25|26|27|28|29=>qmh<=2;

when30|31|32|33|34|35|36|37|38|39=>qmh<=3;

when40|41|42|43|44|45|46|47|48|49=>qmh<=4;

when50|51|52|53|54|55|56|57|58|59=>qmh<=5;

whenothers=>null;

endcase;

endprocess;

-----------------------------------------------------------------------

process(hour)

begin

casehouris

when0|10|20=>qhl<=0;

when1|11|21=>qhl<=1;

when2|12|22=>qhl<=2;

when3|13|23=>qhl<=3;

when4|14=>qhl<=4;

when5|15=>qhl<=5;

when6|16=>qhl<=6;

when7|17=>qhl<=7;

when8|18=>qhl<=8;

when9|19=>qhl<=9;

whenothers=>null;

endcase;

casehouris

when0|1|2|3|4|5|6|7|8|9=>qhh<=0;

when10|11|12|13|14|15|16|17|18|19=>qhh<=1;

when20|21|22|23=>qhh<=2;

whenothers=>null;

endcase;

endprocess;

---------------------------------------------------------------

process(year)

begin

qy1<=year/1000;

qy2<=(yearrem1000)/100;

qy3<=((yearrem1000)rem100)/10;

qy4<=((yearrem1000)rem100)rem10;

--qy1<=year/1000;

--qy2<=(yearrem1000)/100;

--qy3<=((year-(year/1000)*1000)-((year-(year/1000)*1000)/100)*100)/10;

--qy4<=((yearrem1000)rem100)rem10;

endprocess;

----------------------------------------------------------------

process(month)

begin

qmonh<=month/10;

qmonl<=monthrem10;

endprocess;

-----------------------------------------------------------------

process(day)

begin

qdh<=day/10;

qdl<=dayrem10;

endprocess;

----------------------------------------------------------------

process(clk1khz)

begin

ifclk1khz'eventandclk1khz='1'then

ifcnt=7then

cnt<=0;

elsecnt<=cnt+1;

endif;

endif;

endprocess;

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2