基于VerilogHDL的万年历
基于vhdl万年历的设计说明书
数字万年历与数字钟的设计一、设计要求数字万年历要求可以任意设定年份月份和日期;当当日时钟走过24时(即0点)后,日期能够自动改变。
同样,当每月的最后一天走完后,月份也能够自动显示为下一个月。
年份的变化也是如此。
时钟计时按照一天24小时计。
时钟也可以按照由人工设定当前时间,或者修改当前时间,修改完成后,计时即有当前时间开始。
显示方式:日期为2001-11-08,时钟为hh-mm-ss;日期和时钟轮流显示。
二、设计原理本设计先用VHDL语言写出需要的各个小模块,并将这些模块进行编译并打包成图形文件,最后将这些图形文件在顶层文件里进行连线,实现具体要求与功能。
实验源程序:LIBRARY IEEE;USE IEEE.std_logic_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;USE IEEE.std_logic_unsigned.ALL;ENTITY onesecond ISPORT (RESET: IN STD_LOGIC;GCLKP1: IN STD_LOGIC;clkout: out std_logic);END onesecond ;ARCHITECTURE Frequency_arch OF onesecond IS SIGNAL Period1S: STD_LOGIC;BEGINPROCESS( RESET, GCLKP1)VARIABLE Count1 : STD_LOGIC_VECTOR(25 DOWNTO 0);BEGINIF( GCLKP1'EVENT AND GCLKP1='1' ) THENIF( Count1>"10111110101111000010000000" ) THENCount1 := "00000000000000000000000000";ELSECount1 := Count1 + 1;END IF;Period1S <= Count1(25); -- 1MHzEND IF;clkout <= Period1S;end process;END Frequency_arch;60进制library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cnt60 isport(clk: in std_logic;ld: in std_logic;da,db:in std_logic_vector(3 downto 0);outa:out std_logic_vector(3 downto 0);outb:out std_logic_vector(3 downto 0);c0: out std_logic);end cnt60;architecture one of cnt60 issignal ma,mb:std_logic_vector(3 downto 0);beginc0<='1' WHEN( ma=5 and mb=9 ) else '0' ;beginif clk'event and clk='1' thenif ld='1' thenma<=da;mb<=db;elsif ma=5 and mb=9 thenmb<="0000";ma<="0000";elsif mb=9 thenmb<="0000";ma<=ma+1;else mb<=mb+1;end if;end if;end process;outa<=ma;outb<=mb;end one;24进制程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cnt24 isport(clk: in std_logic;ld: in std_logic;da,db:in std_logic_vector(3 downto 0);outa:out std_logic_vector(3 downto 0);outb:out std_logic_vector(3 downto 0);c0: out std_logic);end cnt24;architecture one of cnt24 issignal ma,mb:std_logic_vector(3 downto 0); beginc0<='1' WHEN( ma=2 and mb=3 ) else '0' ;beginif clk'event and clk='1' thenif ld='1' then ma<=da;mb<=db;elsif ma=2 and mb=3 thenmb<="0000";ma<="0000";elsif mb=9thenmb<="0000";ma<=ma+1;elsemb<=mb+1;end if;end if;end process;outa<=ma;outb<=mb;end one;天library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity day isport(clk:in std_logic;ld: in std_logic;maxday: in std_logic_vector(1 downto 0);da:in std_logic_vector(3 downto 0);db:in std_logic_vector(3 downto 0);outa:out std_logic_vector(3 downto 0);outb:out std_logic_vector(3 downto 0);c0: out std_logic);end day;architecture one of day issignal ma: std_logic_vector(3 downto 0);signal mb: std_logic_vector(3 downto 0);beginprocess(clk,ld)beginif clk'event and clk='1' thenif ld='1' then ma<=da;mb<=db;case maxday iswhen "00"=> --28if (ma=2 and mb=8)thenma<="0000";mb<="0001";c0<='1';else if mb=9 then mb<="0000";ma<=ma+1;c0<='0';else mb<=mb+1;c0<='0';end if;end if;when "01"=> -- 29if (ma=2 and mb=9)thenma<="0000";mb<="0001";c0<='1';else if mb=9 then mb<="0000";ma<=ma+1;c0<='0';else mb<=mb+1;c0<='0';end if;end if;when "10"=> -- 30if (ma=3 and mb=0)thenma<="0000";mb<="0001";c0<='1';else if mb=9 then mb<="0000";ma<=ma+1;c0<='0';else mb<=mb+1;c0<='0';end if;end if;when others => --31if (ma=3 and mb=1)thenma<="0000";mb<="0001";c0<='1';else if mb=9 then mb<="0000";ma<=ma+1;c0<='0';else mb<=mb+1;c0<='0';end if;end if;end case;end if;end if;end process;outa<=ma;outb<=mb;end one;月library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity yue isport(clk,ld:in std_logic;da: in std_logic_vector(3 downto 0);db: in std_logic_vector(3 downto 0);runnian:in std_logic;outa: out std_logic_vector(3 downto 0);outb: out std_logic_vector(3 downto 0);c0:out std_logic;maxday:out std_logic_vector(1 downto 0));end yue;architecture one of yue issignal mb:std_logic_vector(3 downto 0); signal ma:std_logic_vector(3 downto 0);beginprocess(clk,ld)beginif (clk'event and clk='1') thenif ld='1' thenma<=da;mb<=db;if(ma=1 and mb=2)thenma<="0000";mb<="0001";elsif mb=9 thenmb<="0000";ma<=ma+1;elsemb<=mb+1;end if;end if;end if;end process;outa<=ma;outb<=mb;c0<='1' WHEN( ma=1 and mb=2 ) else '0' ; maxday <="00" when ma=0 and mb=2 and runnian='0' else "01" when ma=0 and mb=2 and runnian='1' else"10" when (ma=0 and mb=4)or(ma=0 andmb=6)or(ma=0 and mb=9)or(ma=1 and mb=1) else"11";end one;年library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity nian isport(ld1,ld2,clk:in std_logic;dy1,dy2:in std_logic_vector(3 downto 0);y1,y2,y3,y4:out std_logic_vector(3 downto 0);run,cout:out std_logic);end nian;architecture one of nian issignal q1,q2,q3,q4:std_logic_vector(3 downto 0); signal sum,sum1,sum2:std_logic_vector(1 downto 0); beginprocess(clk,ld1,ld2)beginif clk'event and clk='1' thenif ld1='1' thenq1<=dy1;q2<=dy2;elsif ld2='1' thenq3<=dy1;q4<=dy2;elseq1<=q1+1;if q1=9 thenq1<=(others=>'0');q2<=q2+1;end if;if q1=9 and q2=9 thenq1<=(others=>'0');q2<=(others=>'0');q3<=q3+1;end if;if q1=9 and q2=9 and q3=9 thenq1<=(others=>'0');q2<=(others=>'0');q3<=(others=>'0');q4<=q4+1;end if;if q2=9 and q1=9 and q3=9 and q4=9 thenq4<="0000";q3<="0000";q2<="0000";q1<="0000";cout<='1';else cout<='0';end if;end if;end if;end process ;with conv_integer(q4) selectsum1<="10" when 1|3|5|7|9,"00" when others;with conv_integer(q2) selectsum2<="10" when 1|3|5|7|9,"00" when others;process(q1,q2,q3,q4,sum1,sum2)beginif(q1="0000"and q2="0000")thensum<=sum1+q3(1 downto 0);elsesum<=sum2+q1(1 downto 0);end if;end process ;run<= '1' when sum="00" else '0';y1<=q1;y2<=q2;y3<=q3;y4<=q4;end one;置数选择程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity yima1 isport(x:in std_logic_vector(2 downto 0);y0,y1,y2,y3,y4,y5,y6,y7:out std_logic); end yima1;architecture a of yima1 issignal da:std_logic_vector(7 downto 0); beginwith x selectda<="00000001"when"000","00000010"when"001","00000100"when"010","00001000"when"011","00010000"when"100","00100000"when"101","01000000"when"110","10000000"when"111","00000000"when others;y0<=da(0);y1<=da(1);y2<=da(2);y3<=da(3);y4<=da(4);y5<=da(5);y6<=da(6);y7<=da(7);end a;显示library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity display isport(clk:in std_logic;c4:in std_logic;ya,yb,yc,yd,ma,mb,da,db,ha,hb,fa,fb,oa,ob:instd_logic_vector(3 downto 0);d0,d1,d2,d3,d4,d5,d6,d7:out std_logic_vector(0 to 6));end display;architecture one of display issignal w:std_logic;signal s0,s1,s2,s3,s4,s5,s6,s7:std_logic_vector(3 downto 0);beginprocess(clk,c4)beginif clk'event and clk='1' thencase c4 iswhen '1' => w<='0';--display hour fen minutewhen '0' => w<='1';--display year month daywhen others=> null;end case;end if;end process;process(clk,w,ya,yb,yc,yd,ma,mb,da,db,ha,hb,fa,fb,oa,ob) beginif clk'event and clk='1' thencase w iswhen '0' =>s0<=hb;s1<=ha;s2<="1111";s3<=fa;s4<=fb;s5<="11 11";s6<=oa;s7<=ob;when others =>s0<=ya;s1<=yb;s2<=yc;s3<=yd;s4<=ma;s5<=mb;s6 <=da;s7<=db;end case;end if;end process;with s0 selectd0<= "0110000" when "0001","1101101" when "0010","1111001" when "0011","0110011" when "0100","1011011" when "0101","1011111" when "0110","1110000" when "0111","1111111" when "1000","1111011" when "1001","1111110" when others;with s1 selectd1<= "0110000" when "0001","1101101" when "0010","1111001" when "0011","1011011" when "0101","1011111" when "0110","1110000" when "0111","1111111" when "1000","1111011" when "1001","1111110" when others; with s2 selectd2<= "0110000" when "0001", "1101101" when "0010","1111001" when "0011","0110011" when "0100","1011011" when "0101","1011111" when "0110","1110000" when "0111","1111111" when "1000","1111011" when "1001","0000001" when "1111","1111110" when others; with s3 selectd3<= "0110000" when "0001", "1101101" when "0010","1111001" when "0011","0110011" when "0100","1011011" when "0101","1011111" when "0110","1110000" when "0111","1111111" when "1000","1111011" when "1001","1111110" when others; with s4 selectd4<= "0110000" when "0001", "1101101" when "0010","1111001" when "0011","0110011" when "0100","1011011" when "0101","1011111" when "0110","1110000" when "0111","1111011" when "1001","1111110" when others;with s5 selectd5<= "0110000" when "0001","1101101" when "0010","1111001" when "0011","0110011" when "0100","1011011" when "0101","1011111" when "0110","1110000" when "0111","1111111" when "1000","1111011" when "1001","0000001" when "1111","1111110" when others;with s6 selectd6<= "0110000" when "0001","1101101" when "0010","1111001" when "0011","0110011" when "0100","1011011" when "0101","1011111" when "0110","1110000" when "0111","1111111" when "1000","1111011" when "1001","1111110" when others;with s7 selectd7<= "0110000" when "0001","1101101" when "0010","1111001" when "0011","0110011" when "0100","1011011" when "0101","1011111" when "0110","1110000" when "0111","1111111" when "1000","1111011" when "1001","1111110" when others; end one;大学本科生毕业设计(论文)撰写规范本科生毕业设计(论文)是学生在毕业前提交的一份具有一定研究价值和实用价值的学术资料。
基于VHDL的万年历设计
摘要 (1)Abstract (2)绪论 (3)第1章基本概念简介 (4)1。
1 EDA技术和FPGA/CPLD简介 (4)1。
2 VHDL的简介 (4)1。
3 Quartus II的简介 (5)第2章系统设计 (6)2.1 设计思想 (6)2。
2 设计原理图 (7)2.3 设计流程图 (8)第3章模块分析 (9)3.1 计数器模块分析 (9)3.1。
1 秒和分计数器模块 (9)3.1。
2 时计数器模块 (10)3。
1。
3 日计数器模块 (12)3.1。
4 月计数器模块 (16)3.1.5 年计数器模块 (19)3.2 校时模块 (22)3。
3 显示及显示方式切换模块 (25)3。
4 顶层原理图 (26)第4章引脚设定与验证 (29)4。
1 引脚设定 (29)4。
2 下载验证 (31)总结 (33)参考文献 (34)致谢...................................... (错误!未定义书签。
)随着EDA(电子设计自动化)技术的发展和应用领域的扩大,EDA技术在电子信息、通信、自动化控制及计算机应用领域的重要性日益突出。
EDA技术作为现代电子设计技术的核心,它依赖功能强大的计算机,在EDA工具软件平台上,对以硬件描述语言HDL(Hardware Description language)为系统逻辑描述手段完成的设计文件,自动完成逻辑化简、逻辑分割、逻辑综合(布局布线)、逻辑优化和仿真测试等项功能,直至实现既定性能的电子线路系统功能。
EDA的关键技术之一是用形式化方法来描述数字系统的硬件电路、即用所谓的硬件描述语言来描述硬件电路。
本设计是基于VHDL语言的万年历。
在设计中,首先介绍了万年历的设计思路,且在Quartus II开发环境中编译和仿真所设计各个模块的程序,并逐一调试程序使各模块达到设计目的。
其次,利用各元器件生成顶层文件,进行系统仿真。
最后,对顶层原理图进行引脚设定,并下载到试验箱验证,证明系统的可行性.关键字:VHDL 万年历 Quartus IIAbstractWith the development of EDA (electronic design automation)technology and expansion of application fields ,the importance of EDA technology in electronic information, communication, auto control, and computer applications is becoming increasingly prominent. EDA technology is the core of the modern electronic design techniques, which rely on powerful computers 。
vhdl电子日历设计完整
《EDA技术教程》基于VHDL 的万年历设计(EDA实验报告)学校:郑州大学院部:物理工程学院年级: 2010级专业:电子科学与技术姓名:张金灿2013年01月20日ONE:本设计为实现一个多功能的万年历,具有年、月、日、时、分、秒计时并显示的功能,其满量程计时为一万年;具有校对功能,能够对初始的时间进行人为的设定。
设计采用EDA技术,以硬件描述语言VHDL为系统逻辑描述手段设计具有万年历功能的硬件电路,在QuartusII9.0软件设计环境下,采用自顶向下的设计思路,分别对各个基础模块进行创建,通过各个基础模块的组合和连接来构建上层原理图,完成基于VHDL万年历设计。
系统目标芯片采用EP2C35F484C8N,由CNT60模块、CNT24模块、DAY模块、MONTH模块、YEAR模块、TIAOSHI模块、CONTROL模块组成。
经编译和仿真所设计的程序,在可编程逻辑器件上下载验证,将硬件编写程序下载到试验箱上,选择模式5进行功能验证。
本系统能够完成年、月、日和时、分、秒的分别显示,由按键输入进行万年历的校时功能。
TWO: 万年历的设计思路与多功能时钟的设计思路相似。
多功能时钟的各功能模块及相互之间的连接如下图1所示图1THREE:年、月、日和时、分、秒的显示格式如图2所示。
年、月、日同时显示,时、分、秒同时显示,通过显示模式切换来分别显示。
年/ (时)月/分日/秒图2万年历显示格式FOUR:按照模块化的设计思想,要实现万年历的基础功能,必定要包含年、月、日和时、分、秒的功能模块,其中秒和分可以用六十进制计数器来实现,时用二十四进制计数器实现,月用十二进制计数器来实现,年的低两位和高两位都是一百进制计数器,比较特殊的是天的计数器,因为它有四种情况,大月三十一天,小月三十天,平年二月二十八天,闰年二月有二十九天,所以年和月的模块对天的计数都有影响,需要从年和月的输出端引出控制信号来控制天的计数。
同时每个计数器都有显示输出端和进位输出端,同时低级别(如秒)的进位输出要给较高级别(如分)的时钟输入端,以此类推,采用串行工作方式进行连接。
万年历的设计与实现
学校代码 ***** 学号 ******** 分类号 TP 密级公开本科毕业论文(设计)学院、系鄂尔多斯学院电子信息工程系专业名称自动化年级 2011 级学生姓名张文博指导教师王俊林2013年 6月 8 日万年历的设计与实现摘要本设计为一个多功能的万年历,具有年、月、日、时、分、秒计数显示功能,以24小时循环计数,具有校对功能。
本设计采用EDA 技术,以硬件描述语言verilog HDL和VHDL为系统逻辑描述手段设计文件,在Quartus II工具软件环境下,采用自顶向下的设计方法,由各个基本模块共同构建了一个基于KH-310开发工具的万年历。
系统主芯片采用EP1C12Q240C8,由主程序和BCD模块组成。
经编译和仿真所设计的程序,在可编程逻辑器件上下载验证,本系统通过控制能够完成年、月、日和时、分、秒的分别显示,由按键输入进行数字钟的校时、切换、扫描功能。
关键字:VHDL Verilog HDL EDA 万年历目录1绪论 (1)1.1选题背景 (1)1.2课题相关技术的发展 (1)1.3课题研究的必要性 (2)1.4课题研究的内容 (3)2 EDA技术 (4)2.1 EDA概述 (4)2.2什么是EDA (4)2.3 EDA的特点 (5)3 FPGA简介 (7)3.1 FPGA概述 (7)3.2 FPGA开发编程原理 (7)3.3FPGA基本结构 (8)3.4 FPGA系统设计流程 (10)4万年历设计方案 (14)4.1万年历的原理 (14)4.2 实验程序 (14)4.3 实验连接 (34)4.4 实验仿真与实现 (36)5实验结论与研究展望 (38)5.1实验结论 (38)5.2研究展望 (38)致谢 (39)参考文献 (40)内蒙古大学本科实训论文(设计)1绪论1.1选题背景20世纪末,数字电子技术飞速发展,有力的推动了社会生产力的发展和社会信息化的提高。
在其推动下,数字技术的应用已经渗透到人类生活的各个方面。
毕业论文--数字电路课程设计报告--基于1602液晶屏的数字万年历Verilog版
毕业论文--数字电路课程设计报告--基于1602液晶屏的数字万年历Verilog版基于1602液晶屏的数字万年历(Verilog版)课程名称:数字电路课程设计专业:集成电路设计与集成系统基于1602液晶屏的数字万年历(Verilog版)一.设计要求1.基本功能设计一个数字钟,能够显示当前时间,分别用6个数码管显示小时、分钟、秒钟的时间,秒针的计数频率为1Hz,可由系统脉冲分频得到。
在整点进行提示,可通过LED闪烁实现,闪烁频率及花型可自己设计。
能够调整小时和分钟的时间,调整的形式为通过按键进行累加。
具有闹钟功能,闹钟时间可以任意设定(设定的形式同样为通过按键累加),并且在设定的时间能够进行提示,提示同样可以由LED闪烁实现。
2.扩展功能设计模式选择计数器,通过计数器来控制各个功能之间转换。
调整当前时间以及闹钟时间,在按键累加的功能不变的基础上,增加一个功能,即当按住累加键超过3秒,时间能够以4Hz的频率累加。
用LCD液晶屏来显示当前时间及功能模式。
二.设计分析及系统方案设计1.要求分析:基于FPGA实际并发处理的特点,对于实现数字万历年系统,相比于任何嵌入式处理器而言,其特点和优势将得以更加全面体现。
数字万年历中所有模块都将基于基准时钟源进行处理,结合FPGA本身的特点,在时钟源下可进行精确计数,可轻易而产生十分精确的万年历时间。
基础部分:万年历可包括以下时间处理模块:基于秒时钟计数器进行判断处理。
①秒,分,时。
②星期,上/下午。
③日,月,年。
④闹钟功能部分:①时间设定:使用四个按键进行控制,分别是:设置复位按键,设置移位键,功能“加”键,功能“减”键。
②整点报时部分:使用7个绿色LED作为提示灯。
③闹钟提示部分:使用16个红色LED作为闹钟报时提示。
显示部分:使用LCD1602液晶显示屏作为万年历的主显示屏,闹钟显示部分使用6个7段数码管。
2.方案设计基于FPGA的特点以及本万年历系统自身功能特点的实现方式。
基于vhdl万年历设计说明书
目录摘要......................................... (错误!未定义书签。
) Abstract . (1)绪论.......................................... (错误!未定义书签。
)第1章基本概念简介. (2)1.1 EDA技术和FPGA/CPLD简介 (2)1.2 VHDL的简介 (3)1.3 Quartus II的简介 (4)第2章系统设计 (5)2.1 设计思想 (5)2.2 设计原理图 (6)2.3 设计流程图 (6)第3章模块分析 (7)3.1 计数器模块分析 (7)3.1.1 秒和分计数器模块 (7)3.1.2 时计数器模块 (8)3.1.3 日计数器模块 (9)3.1.4 月计数器模块 (12)3.1.5 年计数器模块 (14)3.2 校时模块 (16)3.3 显示及显示方式切换模块 (18)3.4 顶层原理图 (20)第4章引脚设定与验证 (21)4.1 引脚设定 (21)4.2 下载验证 (23)总结 (23)参考文献 (25)致谢.......................................... (错误!未定义书签。
)摘要随着EDA(电子设计自动化)技术的发展和应用领域的扩大,EDA技术在电子信息、通信、自动化控制及计算机应用领域的重要性日益突出。
EDA技术作为现代电子设计技术的核心,它依赖功能强大的计算机,在EDA工具软件平台上,对以硬件描述语言HDL (Hardware Description language)为系统逻辑描述手段完成的设计文件,自动完成逻辑化简、逻辑分割、逻辑综合(布局布线)、逻辑优化和仿真测试等项功能,直至实现既定性能的电子线路系统功能。
EDA的关键技术之一是用形式化方法来描述数字系统的硬件电路、即用所谓的硬件描述语言来描述硬件电路。
本设计是基于VHDL语言的万年历。
vhdl多功能数字万年历 百度文库
vhdl多功能数字万年历全部源代码,已调试成功基本要求:采用VHDL硬件描述语言或者电路图描述的方式完成设计。
1)设计一个万年历系统,可现实从秒到年的计数功能;2)由于开仅具备四位数码管,因此需要进行功能切换,即利用开发板上的一个按键完成小时/分钟、月/日、年等三种显示的切换。
3)秒计数采用开发板上独立的LED以秒闪进行显示;4)同时切换设置模式与显示模式(一个按键完成切换),完成每个显示的增减设置(两个按键实现增减)。
说明:基本要求不需要提供闰月识别功能。
发挥要求:1)提供整点时间报警功能;2)提供闹钟功能;3)提供闰月检测功能;4)以7个独立的LED显示星期。
全部源代码如下,已调试成功1,将50mhz转为1ms时钟count LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY count ISPORT(clk :IN STD_LOGIC;co:OUT STD_LOGIC);END count;ARCHITECTURE behav OF count ISsignal count1 : integer range 0 to 49999 ; BEGINPROCESS(clk)BEGINIF rising_edge(clk) THENcount1<=count1+1;if count1=49999 thencount1<=0;co<='1';else co<='0';end if;end if;end process;end behav;2.秒模块LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY second ISPORT(clk :IN STD_LOGIC;sec :OUT integer range 0 to 59;miao:out std_logic;co:OUT STD_LOGIC);END second;ARCHITECTURE behav OF second IS signal sect : integer range 0 to 59;signal temp : integer range 0 to 1000;BEGINprocess(clk)beginIF rising_edge(clk) THENif temp=1000 then temp<=0;if sect=59 thensect<=0;co<='1';else sect<=sect+1;co<='0';end if;else temp<=temp+1;co<='0';end if;end if;end process;process(temp,sect)beginif temp<500 thenmiao<='1';else miao<='0';end if;sec<=sect;end process;end behav;3.分模块LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY cent ISPORT(clk,seco,centkeyadd,centkeysub:IN STD_LOGIC;cent: out integer range 0 to 59;co:OUT STD_LOGIC);END cent;ARCHITECTURE behav OF cent ISsignal centt: integer range 0 to 59;beginprocess(clk,seco)beginif rising_edge(clk)thenif seco='1' thenif centt=59 then centt<=0;co<='1';else centt<=centt+1;co<='0';end if;elsif centkeyadd='0' thenif centt=59 then centt<=0;else centt<=centt+1;end if;elsif centkeysub='0' thenif centt=0 then centt<=59;else centt<=centt-1;end if;else co<='0';end if;end if;end process;cent<=centt;end behav;4.时模块LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY hour ISPORT(clk,cento,hourkeyadd,hourkeysub:IN STD_LOGIC;hour: out integer range 0 to 23;co:OUT STD_LOGIC);END hour;ARCHITECTURE behav OF hour ISsignal hourt: integer range 0 to 59:=9;beginprocess(clk,cento)beginif rising_edge(clk)thenif cento='1' thenif hourt=23 then hourt<=0;co<='1';else hourt<=hourt+1;co<='0';end if;elsif hourkeyadd='0' thenif hourt=23 then hourt<=0;else hourt<=hourt+1;end if;elsif hourkeysub='0' thenif hourt=0 then hourt<=23;else hourt<=hourt-1;end if;else co<='0';end if;end if;end process;hour<=hourt;end behav;5.日模块LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY day ISPORT(clk,houro,daykeyadd,daykeysub:IN STD_LOGIC;yue:in integer range 1 to 31;day :OUT integer range 1 to 31;co:OUT STD_LOGIC);END day;ARCHITECTURE behav OF day ISsignal dayt: integer range 0 to 31:=24;signal yuet: integer range 1 to 31;beginyuet<=yue;process(clk,houro)beginif rising_edge(clk)thenif houro='1' thenif dayt=yuet then dayt<=1;co<='1';else dayt<=dayt+1;end if;elsif daykeyadd='0' thenif dayt=yuet then dayt<=1;else dayt<=dayt+1;end if;elsif daykeysub='0' thenif dayt=1 then dayt<=yuet;else dayt<=dayt-1;end if;else co<='0' ;end if;end if;end process;day<=dayt;end behav;6.月模块LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY month ISPORT(clk,dayo,monthkeyadd,monthkeysub,run:IN STD_LOGIC;month: out integer range 1 to 12;yue:out integer range 1 to 31;co:OUT STD_LOGIC);END month;ARCHITECTURE behav OF month ISsignal montht: integer range 1 to 12:=2;beginprocess(clk,dayo)beginif rising_edge(clk)thenif dayo='1' thenif montht=12 then montht<=1;co<='1';else montht<=montht+1;end if;elsif monthkeyadd='0' thenif montht=12 then montht<=1;else montht<=montht+1;end if;elsif monthkeysub='0' thenif montht=1 then montht<=12;else montht<=montht-1;end if;else co<='0';end if;end if;end process;month<=montht;--闰月检测功能process(montht,run)beginCASE montht ISWHEN 2=>if run='1' then yue<=29;else yue<=28;end if; --—二月WHEN 3=>yue<=30; --四月WHEN 6=>yue<=30; --六月WHEN 9=>yue<=30; --WHEN 11=>yue<=30; --十一月WHEN others=>yue<=31;END CASE;END PROCESS;END behav;3.年模块LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY year ISPORT(clk,montho,yearkeyadd,yearkeysub:IN STD_LOGIC;year :out integer range 0 to 99;run:OUT STD_LOGIC);END year;ARCHITECTURE behav OF year ISsignal yeart: integer range 0 to 59:=13;beginprocess(clk,montho)beginif rising_edge(clk)thenif montho='1' thenif yeart=59 then yeart<=0;else yeart<=yeart+1;end if;elsif yearkeyadd='0' thenif yeart=59 then yeart<=0;else yeart<=yeart+1;end if;elsif yearkeysub='0' thenif yeart=0 then yeart<=59;else yeart<=yeart-1;end if;end if;end if;end process;year<=yeart;process(yeart)beginif (yeart mod 4)=0 thenrun<='1';else run<='0';end if;end process;end behav;9.显示模块--显示模块LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY display ISPORT(sec,cent : in integer range 0 to 59;hour :in integer range 0 to 23;day: in integer range 1 to 31;month:in integer range 1 to 12;year:in integer range 0 to 99;cento,houro,clk,key0,key1,key2,key3 :IN STD_LOGIC;dis:OUT STD_LOGIC_VECTOR(7 DOWNTO 0);centkeyadd,centkeysub,hourkeyadd,hourkeysub,daykeyadd,daykeysu b,monthkeyadd,monthkeysub: out std_logic;--加减控制输出yearkeyadd,yearkeysub: out std_logic;dis1en,dis2en,dis3en,dis4en,beep: out std_logic;--数码管使能,设置指示,蜂鸣器输出ledweekend:out std_logic_vector(6 downto 0));END display;ARCHITECTURE behav OF display IStype state_type is(s0,s1,s2,s3,s4);signal pre_s,next_s : state_type;type state is(c1,c2,c3,c4);signal pre_c,next_c : state;constant led0 : std_logic_vector(7 downto 0):="11000000";constant led1 : std_logic_vector(7 downto 0):="11111001";constant led2 : std_logic_vector(7 downto 0):="10100100";constant led3 : std_logic_vector(7 downto 0):="10110000";constant led4 : std_logic_vector(7 downto 0):="10011001";constant led5 : std_logic_vector(7 downto 0):="10010010";constant led6 : std_logic_vector(7 downto 0):="10000010";constant led7 : std_logic_vector(7 downto 0):="11111000";constant led8 : std_logic_vector(7 downto 0):="10000000";constant led9 : std_logic_vector(7 downto 0):="10010000";signal count1: integer range 0 to 99;signal count2: integer range 0 to 99;signal count3: integer range 0 to 99;signal count4: integer range 0 to 99;signal set:std_logic_vector(1 downto 0):="00";signal weekend: std_logic_vector(6 downto 0):="0000001";signal acentadd,acentsub,ahouradd,ahoursub :std_logic:='0';signal ahour,acent,centadd,centsub,houradd,hoursub: integer range 0 to 59;signal weekendset:std_logic:='1';signalcentl,centh,hourl,hourh,dayl,dayh,monthl,monthh,yearl,yearh:integer range 0 to 9;signal sec1,sec2,sec3,sec4,acentl,acenth,ahourl,ahourh:integer range 0 to 9;begin--界面转换状态机process(key0)beginif falling_edge(key0) thenpre_s<=next_s;end if;end process;--扫描状态机process(clk)beginif rising_edge(clk) thenpre_c<=next_c;end if;end process;process(key1)beginif falling_edge(key1) thenif set=2 thenset<="00";elseset<=set+1;end if;end if;end process;centl<=cent mod 10; centh<=cent/10;hourl<=hour mod 10; hourh<=hourh/10;dayl<=day mod 10; dayh<=day/10;monthl<=month mod 10; monthh<=month/10;yearl<=year mod 10; yearh<=year/10;acentl<=acent mod 10; acenth<=acent/10;ahourl<=ahour mod 10; ahourh<=ahourh/10;--显示切换状态机p1:process(pre_s,set,centl,centh,hourl,hourh,dayl,dayh,monthl,monthh,yearl, yearh,key2,key3,acentl,acenth,ahourl,ahourh)begincase pre_s iswhen s0 => count4<=centl; count3<=centh;--显示时钟count2<=hourl; count1<=hourh;next_s<=s1;weekendset<='1';daykeyadd<='1';daykeysub<='1';monthkeyadd<='1';monthkeysub<='1';yearkeyadd<='1';yearkeysub<='1';acentadd<='1';acentsub<='1';ahouradd<='1';ahoursub<='1';if set=1 then centkeyadd<=key2;centkeysub<=key3;hourkeyadd<='1';hourkeysub<='1' ;elsif set=2 then hourkeyadd<=key2;hourkeysub<=key3;centkeyadd<='1';centkeysub<='1' ;else centkeyadd<='1';centkeysub<='1'; hourkeyadd<='1';hourkeysub<='1';end if;when s1=> count4<=dayl; count3<=dayh;--显示日期count2<=monthl; count1<=monthh;next_s<=s2;weekendset<='1';centkeyadd<='1';centkeysub<='1';hourkeyadd<='1';hourkeysub<='1';yearkeyadd<='1';yearkeysub<='1';acentadd<='1';acentsub<='1';ahouradd<='1';ahoursub<='1';if set=1 then daykeyadd<=key2;daykeysub<=key3;monthkeyadd<='1';monthkeysub<= '1';elsif set=2 then monthkeyadd<=key2;monthkeysub<=key3;daykeyadd<='1';daykeysub<= '1';elsedaykeyadd<='1';daykeysub<='1';monthkeyadd<='1';monthkeysub<='1';end if;when s2 => count4<=yearl; count3<=yearh;--显示年份count2<=0; count1<=2;next_s<=s3; weekendset<='1';daykeyadd<='1';daykeysub<='1';monthkeyadd<='1';monthkeysub<='1';centkeyadd<='1';centkeysub<='1'; hourkeyadd<='1';hourkeysub<='1';acentadd<='1';acentsub<='1';ahouradd<='1';ahoursub<='1';if set=1 or set=2 then yearkeyadd<=key2;yearkeysub<=key3;else yearkeyadd<='1';yearkeysub<='1';end if;when s3 => count4<=1; count3<=1;--星期控制状态count2<=1; count1<=1;next_s<=s4;daykeyadd<='1';daykeysub<='1';monthkeyadd<='1';monthkeysub<='1';centkeyadd<='1';centkeysub<='1'; hourkeyadd<='1';hourkeysub<='1';acentadd<='1';acentsub<='1';ahouradd<='1';ahoursub<='1';yearkeyadd<='1';yearkeysub<='1';weekendset<='0';when s4 => count4<=acentl; count3<=acenth;--闹钟设置状态count2<=ahourl; count1<=ahourh;next_s<=s0;daykeyadd<='1';daykeysub<='1';monthkeyadd<='1';monthkeysub<='1';centkeyadd<='1';centkeysub<='1'; hourkeyadd<='1';hourkeysub<='1';yearkeyadd<='1';yearkeysub<='1';weekendset<='1';if set=1 then acentadd<=key2;acentsub<=key3; ahouradd<='1';ahoursub<='1';elsif set=2 then ahouradd<=key2;ahoursub<=key3;acentadd<='1';acentsub<='1';else acentadd<='1';acentsub<='1'; ahouradd<='1';ahoursub<='1';end if;end case;end process;--闹钟功能process(clk,acent,centadd,centsub)beginif rising_edge(clk) thenif acent=59 thenacent<=0;elseacent<=centadd-centsub;end if;end if;end process;process(acentadd)beginif falling_edge(acentadd)thenif acent<60 thencentadd<=centadd+1;else centadd<=0;end if;end if;end process;process(acentsub)beginif falling_edge(acentsub)thenif acent<60 thenif acent>0 thencentsub<=centsub+1;else null;end if;else centsub<=0;end if;end if;end process;process(clk,ahour,houradd,hoursub)beginif rising_edge(clk) thenif ahour=23 thenahour<=0;else ahour<=houradd-hoursub; end if;end if;end process;process(ahouradd)beginif falling_edge(ahouradd)thenif ahour<23 thenhouradd<=houradd+1;else houradd<=0;end if;end if;end process;process(ahoursub)beginif falling_edge(ahoursub)thenif ahour<23 thenif ahour>0 thenhoursub<=hoursub+1;else null;end if;else hoursub<=0;end if;end if;end process;--闹钟process(clk,cent,hour,acent,ahour)variable acount: integer range 0 to 30; beginif rising_edge(clk) thenif acent=cent and ahour=hour thenbeep<='0' ;elsif cento='1' thenbeep<='0';else beep<='1';end if;end if;end process;--星期显示和设置process(weekendset,clk,key2,key3)beginif rising_edge(clk) thenif weekend="0000000" thenweekend<="0000001";elsif houro='1' thenweekend<=weekend(5 downto 0)&'0';elsif weekendset='0' thenif key2='0' thenweekend<=weekend(5 downto 0)&'0';elsif key3='0' thenweekend<='0'&weekend(6 downto 1);end if;else null;end if;end if;end process;ledweekend<=weekend;p3: process(pre_c,count4,count3,count2,count1)begincase pre_c iswhen c1=>next_c<=c2;dis1en<='1';dis2en<='1';dis3en<='1';dis4en<='0';case count4 iswhen 0 => dis<=led0;when 1 => dis<=led1;when 2 => dis<=led2;when 3 => dis<=led3;when 4 => dis<=led4;when 5 => dis<=led5;when 6 => dis<=led6;when 7 => dis<=led7;when 8 => dis<=led8;when 9 => dis<=led9;when others => dis<=led0;end case;when c2 =>next_c<=c3;dis1en<='1';dis2en<='1';dis3en<='0';dis4en<='1';case count3 iswhen 0 => dis<=led0;when 1 => dis<=led1;when 2 => dis<=led2;when 3 => dis<=led3;when 4 => dis<=led4;when 5 => dis<=led5;when 6 => dis<=led6;when 7 => dis<=led7;when 8 => dis<=led8;when 9 => dis<=led9;when others => dis<=led0;end case;when c3 =>next_c<=c4;dis1en<='1';dis2en<='0';dis3en<='1';dis4en<='1';case count2 iswhen 0 => dis<=led0;when 1 => dis<=led1;when 2 => dis<=led2;when 3 => dis<=led3;when 4 => dis<=led4;when 5 => dis<=led5;when 6 => dis<=led6;when 7 => dis<=led7;when 8 => dis<=led8;when 9 => dis<=led9;when others => dis<=led0;end case;when c4 =>next_c<=c1;dis1en<='0';dis2en<='1';dis3en<='1';dis4en<='1';case count1 iswhen 0 => dis<=led0;when 1 => dis<=led1;when 2 => dis<=led2;when 3 => dis<=led3;when 4 => dis<=led4;when 5 => dis<=led5;when 6 => dis<=led6;when 7 => dis<=led7;when 8 => dis<=led8;when 9 => dis<=led9;when others => dis<=led0;end case;end case;end process;end behav;10.顶层文件LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY calendar ISPORT(clk,key0,key1,key2,key3:IN STD_LOGIC;dis1en,dis2en,dis3en,dis4en,setled,beep: out std_logic;dis:OUT STD_LOGIC_VECTOR(7 DOWNTO 0);ledweekend:out std_logic_vector(6 downto 0));END calendar;ARCHITECTURE behav OF calendar IScomponent keyPORT(CLK,kin:IN STD_LOGIC;kout:OUT STD_LOGIC);END component;component countPORT(clk :IN STD_LOGIC;co:OUT STD_LOGIC);END component;component secondPORT(clk :IN STD_LOGIC;sec :OUT integer range 0 to 59;miao:out std_logic;co:OUT STD_LOGIC);END component;component centPORT(clk,seco,centkeyadd,centkeysub:IN STD_LOGIC;cent: out integer range 0 to 59;co:OUT STD_LOGIC);END component;component hourPORT(clk,cento,hourkeyadd,hourkeysub:IN STD_LOGIC;hour: out integer range 0 to 23;co:OUT STD_LOGIC);END component;component dayPORT(clk,houro,daykeyadd,daykeysub:IN STD_LOGIC;yue:in integer range 1 to 31;day :OUT integer range 1 to 31;co:OUT STD_LOGIC);END component;component monthPORT(clk,dayo,monthkeyadd,monthkeysub,run:IN STD_LOGIC;month: out integer range 1 to 12;yue:out integer range 1 to 31;co:OUT STD_LOGIC);END component;component yearPORT(clk,montho,yearkeyadd,yearkeysub:IN STD_LOGIC;year :out integer range 0 to 99;run:OUT STD_LOGIC);END component;component displayPORT(sec,cent : in integer range 0 to 59;hour :in integer range 0 to 23;day: in integer range 1 to 31;month:in integer range 1 to 12;year:in integer range 0 to 99;cento,houro,clk,key0,key1,key2,key3 :IN STD_LOGIC;dis:OUT STD_LOGIC_VECTOR(7 DOWNTO 0);centkeyadd,centkeysub,hourkeyadd,hourkeysub,daykeyadd,daykeysu b,monthkeyadd,monthkeysub: out std_logic;--加减控制输出yearkeyadd,yearkeysub: out std_logic;dis1en,dis2en,dis3en,dis4en,beep: out std_logic;--数码管使能,设置指示,蜂鸣器输出ledweekend:out std_logic_vector(6 downto 0));END component;signal counto,seco,cento,houro,dayo,montho,runo,miaoo : std_logic; signal yueo: integer range 0 to 31;--up is componentsignal secout,centout :integer range 0 to 59;signal hourout:integer range 0 to 59;signal dayout:integer range 1 to 31;signal monthout:integer range 1 to 12;signal yearout: integer range 0 to 99;signalcentkeyaddo,centkeysubo,hourkeyaddo,hourkeysubo,daykeyaddo,daykey subo,monthkeyaddo,monthkeysubo: std_logic;signal yearkeyaddo,yearkeysubo,key0o,key1o,key2o,key3o: std_logic ; beginu0: count port map(clk,counto);u1: second port map(counto,secout,miaoo,seco);u2: cent port map(counto,seco,centkeyaddo,centkeysubo,centout,cento);u3: hour port map(counto,cento,hourkeyaddo,hourkeysubo,hourout,houro);u4: day port map(counto,houro,daykeyaddo,daykeysubo,yueo,dayout,dayo);u5: month port map(counto,dayo,monthkeyaddo,monthkeysubo,runo,monthout,yueo,mo ntho);u6: year port map(counto,montho,yearkeyaddo,yearkeysubo,yearout,runo);u7: display port map(secout,centout,hourout,dayout,monthout,yearout,cento,houro,counto ,key0o,key1o,key2o,key3o,dis,centkeyaddo,centkeysubo,hourkeyaddo,hourkeysubo,daykeyaddo,daykeysubo,monthkeyaddo,monthkeysubo,yearkeyaddo,yearkeysubo,dis1en,dis2en,dis3en,dis4en,beep,ledweekend); setled<=miaoo;u9: key port map(counto,key0,key0o);u10: key port map(counto,key1,key1o);u11: key port map(counto,key2,key2o);u12: key port map(counto,key3,key3o);end behav;。
基于fpga的LCD显示万年历..
接着我的上一篇博文,终于完善好了,前几天太忙了,没有及时上传,呵呵,今天晚上刚比较早刚好凌晨,及时上传一下,实现了从0000---9999年的时钟,其实万年历和十万年历,都是差不多,等到地球能转到9999年再改代码也不迟,哈哈!!我这里有顶层和底层文件,顶层主要是调用模块和做按键处理,具体按键防抖动原理,参见偶的以前的博文,我写完这个万年历的代码,还没来得及优化,占用了太多了逻辑门,可以进一步优化。
大致思路是:第一次按下KEY1 的时候,所有计时停止,再按KEY1,年就闪烁,按下KEY2和KEY3 进行加减。
再按KEY1,月就闪烁,按下KEY2和KEY3 进行加减........依次为调年-月-日-星期-时分秒,再次按一下KEY1,进入正常运行模式。
好了先上顶层模块module LCD(rst,clk,rw,rs,en,data,key1,key2,key3);input clk,rst;input key1,key2,key3;output rs,en,rw;output [7:0] data;reg key1_out,key2_out,key3_out;wire clk,rst;wire rs,en,rw;wire [7:0] data;disp U1(.clk(clk),.rst(rst),.rs(rs),.en(en),.rw(rw),.data(data),.key1(key1_out),.key2(key2_out),.key3(key3_out));//=============key1,key2,key3 按键防抖动================// reg key1_reg1,key1_reg2;reg key2_reg1,key2_reg2;reg key3_reg1,key3_reg2;reg [31:0] count;always @(posedge clk)begincount<=count+1;if(count==500000)begincount<=0;key1_reg1<=key1;key2_reg1<=key2;key3_reg1<=key3;endkey1_reg2<=key1_reg1;key2_reg2<=key2_reg1;key3_reg2<=key3_reg1;key1_out <= key1_reg2 & (!key1_reg1);key2_out <= key2_reg2 & (!key2_reg1);key3_out <= key3_reg2 & (!key3_reg1);endendmodule底层模块:module disp(rst,clk,rw,rs,en,data,key1,key2,key3);input clk,rst;input key1,key2,key3;output rs,en,rw;output [7:0] data;reg rs,en_sel;reg [7:0] data;reg [14:0] year;reg [7:0] shi,fen,miao,month,dat;reg [31:0]count,count1; //LCD CLK 分频计数器reg lcd_clk;//2行32个数据寄存器reg [7:0]one_1,one_2,one_3,one_4,one_5,one_6,one_7,one_8,one_9,one_10,one_11,one_12,on e_13,one_14,one_15,one_16;reg [7:0]two_1,two_2,two_3,two_4,two_5,two_6,two_7,two_8,two_9,two_10,two_11,two_12,two_ 13,two_14,two_15,two_16;reg [7:0] next;parameter state0 =8'h00, //设置8位格式,2行,5*7 8'h38;state1 =8'h01, //整体显示,关光标,不闪烁8'h0C 闪烁8'h0estate2 =8'h02, //设定输入方式,增量不移位8'h06state3 =8'h03, //清除显示8'h01state4 =8'h04, //显示第一行的指令80Hstate5 =8'h05, //显示第二行的指令80H+40Hscan =8'h06,nul =8'h07;parameter data0 =8'h10, //2行32个数据状态data1 =8'h11,data2 =8'h12,data3 =8'h13,data4 =8'h14,data5 =8'h15,data6 =8'h16,data7 =8'h17,data8 =8'h18,data9 =8'h19,data10 =8'h20,data11 =8'h21,data12 =8'h22,data13 =8'h23,data14 =8'h24,data15 =8'h25,data16 =8'h26,data17 =8'h27,data18 =8'h28,data19 =8'h29,data20 =8'h30,data21 =8'h31,data22 =8'h32,data23 =8'h33,data24 =8'h34,data25 =8'h35,data26 =8'h36,data27 =8'h37,data28 =8'h38,data29 =8'h39,data30 =8'h40,data31 =8'h41;initialbegin//第一行显示年-月-日星期//Mon Tue Wed Thur Fri Sat Sunone_1<=" "; one_2<=" "; one_3<=" "; one_4<=" "; one_5<="-"; one_6<=" "; one_7<=" "; one_8<="-";one_9<=" ";one_10<=" ";one_11<=" ";one_12<=" ";one_13<=" ";one_14<="";one_15<=" ";one_16<=" ";//第二行显示Clock:00-00-00two_1<="C"; two_2<="l"; two_3<="o"; two_4<="c"; two_5<="k"; two_6<=":"; two_7<=" "; two_8<=" ";two_9<="-";two_10<=" ";two_11<=" ";two_12<="-";two_13<=" ";two_14<="";two_15<=" ";two_16<=" ";shi<=8'd0;fen<=8'd0;miao<=8'd0;end//======================产生LCD 时序脉冲=========================== always @ (posedge clk ) //获得LCD时钟begincount<=count+1;if(count==32'd50000)begincount<=32'b0;lcd_clk<=~lcd_clk;endend//=====================产生闪烁扫描时钟===========================reg [31:0] count2;reg scan_flag;always @ (posedge clk or negedge rst) //获得校准时间选中闪烁状态beginif(!rst)beginscan_flag<=1'b0;endelsebegincount2<=count2+1;if(count2==32'd1*******)begincount2<=32'b0;scan_flag<=~scan_flag;endendend//====================产生按键标志位================================= reg [3:0] flag;always @ (posedge clk or negedge rst )beginif(!rst)beginflag<=4'b0;endelseif(key1)beginflag<=flag+1'b1;if(flag==4'b1000)flag<=4'b0000;endend//===================计时以及校准=======================================reg[3:0] week;reg[7:0] dat_flag;always @ (posedge clk or negedge rst ) //时钟计数器beginif(!rst)begin //初始化显示第一行2012-05-19 Sat 第二行:Clock:00-00-00 shi<=8'b0;fen<=8'b0;miao<=8'b0;month<=8'd5;dat<=8'd19;year<=16'd2012;week<=4'd5;count1<=1'b0;two_7<= (shi/8'd10)+8'b00110000;two_8<= (shi%8'd10)+8'b00110000;two_10<=(fen/8'd10)+8'b00110000;two_11<=(fen%8'd10)+8'b00110000;two_13<=(miao/8'd10)+8'b00110000;two_14<=(miao%8'd10)+8'b00110000;one_1<=(year/16'd1000)+8'b00110000;one_2<=((year%16'd1000)/16'd100)+8'b00110000;one_3<=((year%16'd100)/8'd10)+8'b00110000;one_4<=(year%8'd10)+8'b00110000;one_6<=(month/8'd10)+8'b00110000;one_7<=(month%8'd10)+8'b00110000;one_9<=(dat/8'd10)+8'b00110000;one_10<=(dat%8'd10)+8'b00110000;endelsebegintwo_7<= (shi/8'd10)+8'b00110000;two_8<= (shi%8'd10)+8'b00110000;two_10<=(fen/8'd10)+8'b00110000;two_11<=(fen%8'd10)+8'b00110000;two_13<=(miao/8'd10)+8'b00110000;two_14<=(miao%8'd10)+8'b00110000;one_1<=(year/16'd1000)+8'b00110000;one_2<=((year%16'd1000)/16'd100)+8'b00110000;one_3<=((year%16'd100)/8'd10)+8'b00110000;one_4<=(year%8'd10)+8'b00110000;one_6<=(month/8'd10)+8'b00110000;one_7<=(month%8'd10)+8'b00110000;one_9<=(dat/8'd10)+8'b00110000;one_10<=(dat%8'd10)+8'b00110000;// 判断是否为31天的月份if(month==8'd1||month==8'd3||month==8'd5||month==8'd7||month==8'd8||month==8'd10|| month==8'd12)dat_flag<=8'd31;// 判断是否为30天的月份else if(month==8'd4||month==8'd6||month==8'd9||month==8'd11)dat_flag<=8'd30;// 判断是否为闰年和平年else if(month==8'd2)beginif(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)dat_flag<=28;else dat_flag<=27;endcase (week)//星期//Mon Tue Wed Thu Fri Sat Sun4'b0000 : //1beginone_13<="M";one_14<="o";one_15<="n";end4'b0001 : //2beginone_13<="T";one_14<="u";one_15<="e";end4'b0010 : //3beginone_13<="W";one_14<="e";one_15<="d"; end4'b0011 : //4beginone_13<="T";one_14<="h";one_15<="u"; end4'b0100 : //5beginone_13<="F";one_14<="r";one_15<="i"; end4'b0101 : //6beginone_13<="S";one_14<="a";one_15<="t"; end4'b0110 : //7beginone_13<="S";one_14<="u";one_15<="n"; endendcasecase(flag)4'b0000 :beginen_sel<=1'b1;count1<=count1+1'b1;if(count1==32'd4*******)begincount1<=1'b0;miao<=miao+1'b1;if(miao==8'd59)beginmiao<=1'b0;fen<=fen+1'b1;if(fen==8'd59)beginfen<=1'b0;shi<=shi+1'b1;if(shi==8'd23)beginshi<=1'b0;dat<=dat+1'b1;week<=week+1'b1;if(week==4'b0110)week<=1'b1;if(dat==dat_flag)begindat<=8'd1;month<=month+1'b1;if(month==8'd12)beginmonth<=8'd1;year<=year+1'b1;if(year==16'd9999)year<=16'd0; //可以计1万年endendendendendendend4'b0001 :begincount1<=32'b0;//shi<=shi;fen<=fen;miao<=miao;year<=year;month<=month;dat<=dat;week<=week;end4'b0010 : //调年begincase(scan_flag)1'b0:begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;one_1<=8'd20;one_2<=8'd20;one_3<=8'd20;one_4<=8'd20;end1'b1:begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;endendcaseif(key2) //加数beginyear<=year+1'b1;if(year==16'd9999)year<=16'd0;endif(key3) //减数beginyear<=year-1'b1;if(year==16'd0)year<=16'd9999;endend4'b0011 : //调月begincase(scan_flag)1'b0:begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;one_6<=8'd20;one_7<=8'd20;end1'b1:begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;endcaseif(key2) //加数beginmonth<=month+1'b1;if(month==8'd12)month<=8'd0;endif(key3) //减数beginmonth<=month-1'b1;if(month==8'd0)month<=8'd12;endend4'b0100 : //调日begincase(scan_flag)1'b0:begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;one_9<=8'd20;one_10<=8'd20;end1'b1:begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;endendcaseif(key2) //加数begindat<=dat+1'b1;if(dat==dat_flag)dat<=8'd0;endif(key3) //减数dat<=dat-1'b1;if(dat==8'd0)dat<=dat_flag;endend4'b0101 : //调星期begincase(scan_flag)1'b0:begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;one_13<=8'd20;one_14<=8'd20;one_15<=8'd20;end1'b1:begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;endendcaseif(key2) //加数beginweek<=week+1'b1;if(week==4'd6)week<=4'd0;endif(key3) //减数beginweek<=week-1'b1;if(week==4'd0)week<=4'd7;endend4'b0110 : //调时begincase(scan_flag)begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;two_7<= 8'd20;two_8<= 8'd20;end1'b1:begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;endendcaseif(key2) //加数beginshi<=shi+8'b00000001;if(shi==8'd23)shi<=8'b0;endif(key3) //减数beginshi<=shi-8'b00000001;if(shi==8'b0)shi<=23;endend4'b0111 : //调分begincase(scan_flag)1'b0:begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;two_10<=8'd20;two_11<=8'd20;end1'b1:begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;endendcaseif(key2) //加数beginfen<=fen+8'b00000001;if(fen==8'd59)fen<=8'b0;endif(key3) //减数beginfen<=fen-8'b00000001;if(fen==8'b0)fen<=59;endend4'b1000 : //调秒begincase(scan_flag)1'b0:begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;two_13<=8'd20;two_14<=8'd20;end1'b1:begincount1<=32'b0; //shi<=shi;fen<=fen;miao<=miao;endendcaseif(key2) //加数beginmiao<=miao+8'b00000001;if(miao==8'd59)miao<=8'b0;endif(key3) //减数beginmiao<=miao-8'b00000001;if(miao==8'b0)miao<=59;endendendcaseendendalways @(posedge lcd_clk )begincase(next)state0 :begin rs<=1'b0; data<=8'h38; next<=state1; endstate1 :begin rs<=1'b0; data<=8'h0e; next<=state2; endstate2 :begin rs<=1'b0; data<=8'h06; next<=state3; endstate3 :begin rs<=1'b0; data<=8'h01; next<=state4; endstate4 :begin rs<=1'b0; data<=8'h80; next<=data0; end //显示第一行data0 :begin rs<=1'b1; data<=one_1; next<=data1 ; enddata1 :begin rs<=1'b1; data<=one_2; next<=data2 ; enddata2 :begin rs<=1'b1; data<=one_3; next<=data3 ; enddata3 :begin rs<=1'b1; data<=one_4; next<=data4 ; enddata4 :data5 :begin rs<=1'b1; data<=one_6; next<=data6 ; enddata6 :begin rs<=1'b1; data<=one_7; next<=data7 ; enddata7 :begin rs<=1'b1; data<=one_8; next<=data8 ; enddata8 :begin rs<=1'b1; data<=one_9; next<=data9 ; enddata9 :begin rs<=1'b1; data<=one_10; next<=data10 ; enddata10 :begin rs<=1'b1; data<=one_11; next<=data11 ; enddata11 :begin rs<=1'b1; data<=one_12; next<=data12 ; enddata12 :begin rs<=1'b1; data<=one_13; next<=data13 ; enddata13 :begin rs<=1'b1; data<=one_14; next<=data14 ; enddata14 :begin rs<=1'b1; data<=one_15; next<=data15 ; enddata15 :begin rs<=1'b1; data<=one_16; next<=state5 ; endstate5:begin rs<=1'b0;data<=8'hC0; next<=data16; end //显示第二行data16 :begin rs<=1'b1; data<=two_1; next<=data17 ; enddata17 :begin rs<=1'b1; data<=two_2; next<=data18 ; enddata18 :begin rs<=1'b1; data<=two_3; next<=data19 ; enddata19 :begin rs<=1'b1; data<=two_4; next<=data20 ; enddata20 :data21 :begin rs<=1'b1; data<=two_6; next<=data22 ; enddata22 :begin rs<=1'b1; data<=two_7; next<=data23 ; enddata23 :begin rs<=1'b1; data<=two_8; next<=data24 ; enddata24 :begin rs<=1'b1; data<=two_9; next<=data25 ; enddata25 :begin rs<=1'b1; data<=two_10; next<=data26 ; end data26 :begin rs<=1'b1; data<=two_11; next<=data27 ; end data27 :begin rs<=1'b1; data<=two_12; next<=data28 ; end data28 :begin rs<=1'b1; data<=two_13; next<=data29 ; end data29 :begin rs<=1'b1; data<=two_14; next<=data30 ; end data30 :begin rs<=1'b1; data<=two_15; next<=data31 ; end data31 :begin rs<=1'b1; data<=two_16; next<=scan ; endscan : //交替更新第一行和第二行数据beginnext<=state4;enddefault: next<=state0;endcaseendassign en=lcd_clk && en_sel;assign rw=1'b0;endmodule。
基于VHDL万年历的设计
EDA 课程设计报告书课题名称 基于VHDL 万年历的设计姓 名 学 号 院 系 专 业 指导教师※※※※※※※※※ ※※ ※※ ※※※※※※※※※※※EDA 课程设计基于VHDL 万年历的设计1设计目的1、 熟悉万年历的工作原理,工作过程和所需的相关器件。
2、 增加对EDA 编程方法,编程步骤,相应的操作流程和软件操作等的熟悉度。
3、 积累对数字电路简单系统的实际制作经验,为更加复杂的实际应用领域做准备。
4、 培养独立设计电路系统的专业素养,带动与其他相关课程之间的相互联系来解决电子信息方面常见的实际问题。
2设计的主要内容和要求1、 在Quartus 中编写VHDL 程序实现年、月、日、时、分、秒各模块的功能。
2、 将各模块在原理图中连接起来实现百年历计时功能。
3、 对原理图进行编译仿真,并观察仿真结果看是否能实现万年历的功能效果,如是否可以进位,是否能判断闰年等。
4、 对仿真后的原理图进行引脚锁定,并下载到相关器件中去。
3整体设计方案秒、分是60进制,时是24进制,日31天由月1.3.5.7.8.10.12控制,日28/29由2月和润年控制,日30由月4.6.9.11控制。
原理框图如图3.1所示:图3.1 原理框图整个万年历由五个部分组成。
分别为显示部分,秒、分、时部分,日部分,月部分,年部分和调整控制部分。
秒、分、时分别由两个进制的计数器和一个二十四进制的计数器组成。
当个计数器达到进位的条件时向下一计数器进位。
同样日、月、年也是由不同的计数器组成,当达到所需进位的条件时向下一计数器进位,各计数器在进位的同时分别把各自的结果输出给显示部分进行实时显示。
而调整控制部分通过对k设置高低电平对显示部分的显示进行选择。
例如当k=0时为选择秒分时部分的显示。
此时显示部分输出的结果为秒分时部分各计数器输出的结果;当k=1时选择的是年月日部分的显示,此时显示的结果为年月日个计数器的输出结果。
通过k1、k2对输出结果进行调整。
基于FPGA的多功能电子万年历毕业设计说明
毕业设计中期报告题目名称:基于FPGA的万年历设计院系名称:电气学院班级:应电学号:0832100589学生:梁启超指导教师:金凤2011年06月目录一、多功能电子万年历及FPGA简介 (1)1.1电子万年历的发展 (1)1.2 FPGA简介 (1)1.3 电子万年历的工作原理 (2)二、多功能电子万年历各功能模块实现 (4)2.1 时钟问题 (4)2.1.1 全局时钟 (4)2.1.2 门控时钟 (4)2.1.3 多级逻辑时钟 (5)2.1.4 波动式时钟 (5)2.2 电子万年历的控制系统 (6)2.3 主控制模块 maincontrol (7)2.4 时间及其设置模块 time_auto_and_set (8)2.2.1 时间模块 timepiece_main (8)2.2.2 时间设置模块 timeset (9)2.2.3 时间数据与时间设置数据多路选择模块 time_mux (11)2.3 时间显示动态位选模块 time_disp_select (13)2.4 显示模块 disp_data_mux (14)2.5 秒表模块 stopwatch (15)2.6 日期显示与设置模块 date_main (16)2.6.1 日期自动工作模块 autodate (17)2.6.2 日期设置模块 setdate (17)2.7 闹钟模块alarmclock (18)2.8 分频模块 fdiv (19)2.9 顶层模块图 (21)三、附录 (23)电子万年历系统的Verilog HDL语言程序设计部分代码 (23)3.1主控制模块 (23)3.2秒自动计时子模块 (25)3.3时间自动工作控制 (25)3.4时间数据与时间设置数据多路选择模块 (26)3.5时间及其设置模块 (27)3.6时间显示动态位选模块 (28)3.7秒表模块 (29)3.8分频模块 (29)参考文献 (31)1 引言1.1 选题意义钟表的数字化给人们生产生活带来了极大的方便,而且大扩展了钟表原先的报时功能,诸如定时自动报警、按时自动打铃、时间程序自动控制、定时广播、定时启闭路灯等。
vhdl万年历
FPGA——VHDL历万年LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY TIMER ISPORT(CLK,RES,XUAN,JIA_SEC1,JIA_SEC2,JIA_MIN1,JIA_MIN2,JIA_HOUR1,JIA_HOUR2:IN STD_LOGIC;HOUR2,HOUR1,MIN2,MIN1,SEC2,SEC1:OUT STD_LOGIC_VECTOR(3 DOWNTO 0);COUT:OUT STD_LOGIC);END;ARCHITECTURE ONE OF TIMER ISSIGNAL HOUR11,HOUR22,SEC11,SEC22,MIN11,MIN22:STD_LOGIC_VECTOR(3 DOWNTO 0);BEGINPROCESS(CLK,RES,XUAN,JIA_SEC1,JIA_SEC2,JIA_MIN1,JIA_MIN2,JIA_HOUR1,JIA_HOUR2)BEGINIF(XUAN='0')THEN----------------------自动计时IF(CLK'EVENT AND CLK='1')THENIF(RES='0')THENIF(HOUR22<"0010")THENIF(HOUR11<"1001")THEN ------<19 HOURSIF(MIN22<"0101")THENIF(MIN11<"1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<=MIN11+1;END IF;END IF;ELSIF(MIN11="1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<="0000";MIN22<=MIN22+1;END IF;END IF;ELSIF(MIN22="0101")THENIF(MIN11<"1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<=MIN11+1;END IF;END IF;ELSIF(MIN11="1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<="0000";MIN22<="0000";HOU R11<=HOUR11+1;END IF;END IF;END IF;END IF;ELSIF(HOUR11="1001")THENIF(MIN22<"0101")THENIF(MIN11<"1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<=MIN11+1;END IF;ELSIF(MIN11="1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<="0000";MIN22<=MIN22+1;END IF;END IF;END IF;ELSIF(MIN22="0101")THENIF(MIN11<"1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<=MIN11+1;END IF;END IF;ELSIF(MIN11="1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<="0000";MIN22<="0000";HOU R11<="0000";HOUR22<=HOUR22+1;END IF;END IF;END IF;END IF;END IF;ELSIF(HOUR22="0010")THEN -----20--23 hoursIF(MIN22<"0101")THENIF(MIN11<"1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<=MIN11+1;END IF;END IF;ELSIF(MIN11="1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<="0000";MIN22<=MIN22+1;END IF;END IF;END IF;ELSIF(MIN22="0101")THENIF(MIN11<"1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<=MIN11+1;END IF;END IF;ELSIF(MIN11="1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<="0000";MIN22<="0000";HOUR11<=HOUR11+1;END IF;END IF;END IF;END IF;ELSIF(HOUR11="0100")THEN------------------------------------20--23HOURSIF(MIN22<"0101")THENIF(MIN11<"1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<=MIN11+1;END IF;END IF;ELSIF(MIN11="1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<="0000";MIN22<=MIN22+1;END IF;END IF;END IF;ELSIF(MIN22="0101")THENIF(MIN11<"1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<=MIN11+1;END IF;END IF;ELSIF(MIN11="1001")THENIF(SEC22<"0101")THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<=SEC22+1;END IF;ELSIF(SEC22="0101") THENIF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";SEC22<="0000";MIN11<="0000";MIN22<="0000";HOUR11<="0000";HOUR22<="0000";END IF;END IF;END IF;END IF;END IF;END IF;ELSE SEC11<="0000";SEC22<="0000";MIN11<="0000";MIN22<="0000";HOUR11<="0000";HOUR22<="0000";END IF;END IF;ELSE------------------------------------------进行手动调整IF(RES='0')THENIF(JIA_SEC1'EVENT AND JIA_SEC1='1')THEN------------------调整秒1IF(SEC11<"1001")THENSEC11<=SEC11+1;ELSE SEC11<="0000";END IF;END IF;IF(JIA_SEC2'EVENT AND JIA_SEC2='1')THEN------------------调整秒2IF(SEC22<"0101")THENSEC22<=SEC22+1;ELSE SEC22<="0000";END IF;END IF;IF(JIA_MIN1'EVENT AND JIA_MIN1='1')THEN------------------调整分1IF(MIN11<"1001")THENMIN11<=MIN11+1;ELSE MIN11<="0000";END IF;END IF;IF(JIA_MIN2'EVENT AND JIA_MIN2='1')THEN------------------调整分2IF(MIN22<"0101")THENMIN22<=MIN22+1;ELSE MIN22<="0000";END IF;END IF;IF(JIA_HOUR1'EVENT AND JIA_HOUR1='1')THEN----------------调整时1IF(HOUR11<"1001")THENHOUR11<=HOUR11+1;ELSE HOUR11<="0000";END IF;END IF;IF(JIA_HOUR2'EVENT AND JIA_HOUR2='1')THEN----------------调整时2IF(HOUR22<"0010")THENHOUR22<=HOUR22+1;ELSE HOUR22<="0000";END IF;END IF;ELSE SEC11<="0000";SEC22<="0000";MIN11<="0000";MIN22<="0000";HOUR11<="0000";HOUR22<="0000";END IF;END IF;END PROCESS;PROCESS(SEC11,SEC22,MIN11,MIN22)BEGINIF(MIN11="0000" AND MIN22="0000")THENIF(SEC11<"1010" AND SEC22<"0011")THENCOUT<='1';ELSE COUT<='0';END IF;ELSIF(MIN11="0000" AND MIN22="0011")THENIF(SEC11<"1010" AND SEC22<"0011")THENCOUT<='1';ELSE COUT<='0';END IF;ELSE COUT<='0';END IF;END PROCESS;HOUR2<=HOUR22;HOUR1<=HOUR11;SEC1<=SEC11;SEC2<=SEC22;MIN1<=MIN11;MIN2<=MIN22;END;。
基 于VHDL的万年历设计
本设计为实现一个多功能的万年历,具有年、月、日、时、分、秒计时并显示的功能,顾名思义,其满量程计时为一万年;具有校对功能,能够对初始的时间进行人为的设定。
本设计采用EDA技术,以硬件描述语言VHDL为系统逻辑描述手段设计具有万年历功能的硬件电路,在QuartusII软件设计环境下,采用自顶向下的设计思路,分别对各个基础模块进行创建,通过各个基础模块的组合和连接来构建上层原理图,完成基于VHDL万年历设计。
系统目标芯片采用EP1K30TC144-3,由时钟模块、控制模块、计时模块、数据译码模块、显示模块组成。
经编译和仿真所设计的程序,在可编程逻辑器件上下载验证,将硬件编写程序下载到试验箱上,选择模式3进行功能验证。
本系统能够完成年、月、日和时、分、秒的分别显示,由按键输入进行万年历的校时功能。
1 实验概述 (4)1.1 EDA技术 (4)1.2 QuartusII的使用 (4)1.3 模块化设计 (4)1.4 分析、解决问题 (4)2 实验内容与要求 (5)2.1实验内容 (5)2.1实验说明 (5)2.3实验要求 (6)3 实验原理 (7)3.1设计思想 (7)3.2设计原理图 (8)3.3工作工程 (9)4 实验结果 (10)4.1VHDL程序与仿真 (10)4.1.1秒和分模块 (10)4.1.2小时模块 (11)4.1.3日(天)模块 (12)4.1.4月份模块 (15)4.1.5年模块 (17)4.1.6校时模块 (19)4.1.7显示模式切换模块 (21)4.2顶层设计与仿真 (23)4.3下载与验证 (25)4.3.1电路结构选择 (25)4.3.2端口配置 (26)4.3.3实际电路验证 (29)5 实验小结 (30)参考文献 (31)1 、实验概述1.1 EDA技术EDA(Electronic Design Automation),即电子设计自动化,是指利用计算机完成电子系统的设计。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
基于Verilog HDL 的万年历设计与总结报告题目名称:基于Verilog HDL 的万年历研究设计报告人:__________ __ ____________ __院系/年级/ 专业:___ _____指导教师:_ ___________________制作日期:_ __ _基于Verilog HDL 的万年历摘要基于Verilog HDL的万年历设计,主要完成的任务是使用Verilog语言,在Quartus2 上完成电路设计,程序开发模拟,基于功能是能够显示/ 修改年月日时分秒。
电路设计模块:分频、控制、时间显示调整、时分秒、年月日、显示控制、译码器。
各个模块完成不同的任务,合在一起就构成了万年历电路设计。
软件模拟直接在Quartus2 上进行。
随着科学技术的发展,时间观念越来越重,但是老式的钟表以及日历等时间显示工具已不合时宜。
对此,数字钟表的设计有了用武之地。
基于Verilog 的万年历设计,采用软件开发模拟,开发成本低,而且在功能设计上有了很大的灵活度。
同时,该设计的精度远远超过钟表,并且不需要维修。
综上所述,本设计具有设计方便、功能多样、电路简洁、成本低廉等优点。
符合社会发展趋势,前景广阔。
关键词:万年历,Verilog HDL ,Quartus2Based on the design of the calendar Verilog HDLcircuit AbstractThe calendar based on FPGA design, the main task is to use eVrilog language, in the Quartus2 complete circuit design module is divided into several modules: point frequency, control and time display adjustment, arc, date, display, when control, decoder. Each module complete different tasks, together they form a calendar system circuit design. Software simulation on directly in Quartus2.With the development of technology and science, the concept of time is more and more heavey, but old-fashioned clock and calendar etc time display tools are not very good.Key words : Calendar, Verilog HDL ,Quartus2目录摘要⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯..1 Abstract⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯.2 第一章万年历发展介绍及Verilog HDL 简介 (3)1.1万年历的发展⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯..3 1.2Verilog HDL 简介⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯ 4 第二章设计原理⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯..5 2.1组成模块⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯..62.2系统设计图⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯..7第三章各功能模块介绍⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯8 第四章模拟仿真⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯11 4.1年月日仿真⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯12 4.2时分秒仿真⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯13 总结结论⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯14 参考文献⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯15第一章万年历的发展介绍及Verilog HDL 简介1.1万年历的发展钟表、日历等的数字化大大方便了我们的日常生活,同时大大扩展了其功能,而这些功能的实现,均以钟表的数字化为基础的。
因此,研究数字化钟表以及扩大其应用,有现实意义。
此次设计与制作数字万年历就是为了了解数字钟的原理,从而学会制作。
通过它也可以进一步学习掌握各种逻辑电路与时序电路的原理与使用方法。
1.2Verilog HDL 简介Verilog HDL 是一种硬件描述语言( HDL:Hardware Discription Language),是一种以文本形式来描述数字系统硬件的结构和行为的语言,用它可以表示逻辑电路图、逻辑表达式,还可以表示数字逻辑系统所完成的逻辑功能。
Verilog HDL 和VHDL 是目前世界上最流行的两种硬件描述语言,都是在20 世纪80 年代中期开发出来的。
前者由Gateway Design Automation 公司(该公司于1989 年被Cadence 公司收购)开发。
两种HDL 均为IEEE 标准。
2.1组成模块根据一般EDA 实验设备的输入/输出接口的容限,本设计采用8 只七段数码管分时完成时、分、秒或年、月、日的显示。
设计电路的计时器模块用于完成一天中的24 小时计时;年月日模块接受计时器模块送来的“天”脉冲进行计数,得到日、月、年的显示结果;控制模块产生控制信号k,控制数码显示器显示年、月、日,还有显示时、分、秒,或是自动轮流显示;校时选择模块在k 信号的控制下,选择将j1 、j2 和j3 这 3 个校时按钮产生的信号是送到计时器模块的校秒、校分和校时的输入端,还是送到年月日模块的校天、校月和校年输入端;显示选择模块在k 信号的控制下,选择是将计时器模块的时、分、秒状态信号,还是将年月日模块的年、月、日信号送到数码显示器显示。
2.2系统设计图系统流程图功能设计图第三章各功能模块介绍1.年月日模块设计基于Verilong HDL 的年月日模块设计的源程序nyr2009.v 如下:module nyr2009(clrn,clk,qn,qy,qr);input clrn,clk;output[15:0] qn;output[7:0] qy,qr;reg [15:0] qn;reg[7:0qy,qr;]reg clkn,clky;reg[7:0] date;reg clkn1,clkn2,clkn3;//初始化年脉冲//initial begin clkn1=1;clkn2=1;clkn3=1;end//初始化年.月.日时间//initial begin qn=`h2000;qy=1;qr=1;end //日计数模块always @(posedge clk or negedge clrn) beginif(~clrn) qr=1;elsebeginif (qr==date) qr=1;else qr=qr+1;if(qr[3:0]==`ha)beginqr[3:0]=0; qr[7:4]=qr[7:4]+1;endif(qr==date) clky=1;else clky=0;endend//月计算模块always@(posedge clky or negedge clrn)beginif (~clrn) qy=1;else beginif (qy== 'h12) qy=1;else qy=qy+1;if (qy[3:0]== 'ha) beginqy[3:0]=0; qy[7:4]=qy[7:4]+1;endif (qy== 'h12) clkn=1;else clkn=1; endend//产生每月的天数alwaysbegincase(qy)'h01: date='h31;'h01: beginif((qn/4==0)&( qn/100!==0)|( qn/400==0)) date='h29; //整百的 年份被 400整除的,是闰年,其他如果不是整百的年份,直接被 4 整 除的是闰年。
else date='h28; end'h03: date='h31;'h04: date='h30;'h05: date='h31;'h06: date='h30; 'h07: date='h31; 'h08: date='h31;'h09: date='h30;'h10: date='h31;'h011: date='h3'h12: date='h31; defaul t: date='h3endcaseend//年计数模块always@(posedge clkn or negedge clrn)beginif (~clrn) qn[3:0]=0;else begin if (qn[3:0]==9) qn[3:0]=0;else qn[3:0]= qn[3:0]+1;if (qn[3:0]==9) clkn1=0;else clkn1=1; endendalways@(posedge clkn1 or negedge clrn)beginif (~clrn) qn[7:4]=0;else begin if (qn[7:4]==9) qn[7:4]=0; else qn[7:4]= qn[7:4]+1; if (qn[7:4]==9) clkn2=0;else clkn2=1; endendalways@(posedge clkn2 or negedge clrn)beginif (~clrn) qn[11:8]=0;else begin if (qn[11:8]==9) qn[11:8]=0;else qn[11:8]= qn[11:8]+1;if (qn[7:4]==9) clkn3=0;else clkn3=1; endendalways@(posedge clkn3 or negedge clrn)beginif (~clrn) qn[15:12]=2;else if (qn[15:12]==9) qn[15:12]=0;else qn[15:12]= qn[15:12]+1;endendmodule其中clrn 是异步清除端,低电平有效;clk 是时钟输入端,上升沿有效;qn[15..0]、qy[7..0]和qr[7..0]分别是年、月和日的状态输出端。