基于BASYS2的VHDL程序——数字钟
2024-09-29 14:28:51
在编电子表时发现FPGA求余,取模只能针对2的次方。毕竟是数字的嘛!
时钟用到了动态刷新数码管。以一个大于50Hz的速度刷新每一个数码管。
因为数码管只有四个,只写了分针和秒针。
代码如下:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL; entity clock is
Port ( clk : in STD_LOGIC;
seg : out STD_LOGIC_VECTOR ( downto );
an : out STD_LOGIC_VECTOR ( downto ));
end clock; architecture Behavioral of clock is
signal num:STD_LOGIC_VECTOR ( downto );
signal min_h:STD_LOGIC_VECTOR ( downto );
signal min_l:STD_LOGIC_VECTOR ( downto );
signal second_h:STD_LOGIC_VECTOR ( downto );
signal second_l:STD_LOGIC_VECTOR ( downto );
signal an_sel:STD_LOGIC_VECTOR ( downto );
signal cnt: INTEGER;
signal cnt2: INTEGER;
signal sclk: STD_LOGIC;
constant a:integer :=;
begin
process(clk)
begin
if(clk'event and clk='') then
if(cnt=) then
cnt<=;
sclk<=not sclk;
else
cnt<=cnt+;
end if;
end if;
end process; process(clk)
begin
if(clk'event and clk='') then
if(cnt2=) then
cnt2<=;
if(an_sel="") then
an_sel<="";
else
an_sel<=an_sel+'';
end if;
else
cnt2<=cnt2+;
end if;
end if;
end process; process(sclk)
begin
if(sclk'event and sclk='') then
if(second_h="" and second_l="") then
second_h<="";
second_l<="";
min_l<=min_l+'';
if(min_h="" and min_l="") then
min_h<="";
min_l<="";
elsif(min_l="") then
min_h<=min_h+'';
min_l<="";
end if;
elsif(second_l="") then
second_h<=second_h+'';
second_l<="";
else
second_l<=second_l+'';
end if;
end if;
end process; process(an_sel,second_l,second_h,min_l,min_h)
begin
case an_sel is
when ""=>an<="";num<=second_l;
when ""=>an<="";num<=second_h;
when ""=>an<="";num<=min_l;
when ""=>an<="";num<=min_h;
when others=>null;
end case; case num is
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when x""=>seg<=b"";
when others=>null;
end case;
end process;
end Behavioral;
约束文件如下:
NET "clk" LOC = "B8";
NET "an<0>" LOC="K14";
NET "an<1>" LOC="M13";
NET "an<2>" LOC="J12";
NET "an<3>" LOC="F12";
NET "seg<6>" LOC="L14";
NET "seg<5>" LOC="H12";
NET "seg<4>" LOC="N14";
NET "seg<3>" LOC="N11";
NET "seg<2>" LOC="P12";
NET "seg<1>" LOC="L13";
NET "seg<0>" LOC="M12";
最新文章
- CSV文件的规范
- 【摘选引用】在安全的SQL 密码也不过如此
- 【你吐吧c#每日学习】11.10 C# Data Type conversion
- PS4 的下载速度问题
- CentOS6编译装载nbd模块
- DWZ (JUI) 教程 table 排序
- 使用struts的模型驱动注意的问题
- BestCoder Round #14 B 称号 Harry And Dig Machine 【TSP】
- 【剑指offer】q34:丑数
- OpenGL学习日记-2015.3.13——多实例渲染
- [大数据]-Logstash-5.3.1的安装导入数据到Elasticsearch5.3.1并配置同义词过滤
- ajax请求原理
- Node.js 调试器
- perl选项、特殊变量、一些函数参考手册
- linq 将datatable分组求和在转datatable
- python任意进制转换
- Redis:C#使用Redis(1)
- Axure 万年历(日期选择下拉文本框)
- thinkCMF----导航高亮显示
- UVA-1252 Twenty Questions (状压DP)
热门文章
- gradle_____最后到齐的构建工具
- Engine中如何进行七参数投影转换?
- DICOM医学图像处理:Orthanc Plugin SDK实现WADO服务
- Testing Is the Engineering Rigor of Software Development
- angular - 编辑html文件-4
- JavaScript插件编写指南
- Git bare repo with multiple branches
- bvlc_reference_caffenet.caffemodel
- WWDC2014苹果的“软件”发布会
- smartUpload注意过程