fpga实现数码管时钟与蜂鸣器报时

六位数码管整点报时

数码管为时钟模块,当秒数为60s时,蜂鸣器响1s。
fpga源代码(程序仅供参考):

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
use IEEE.numeric_std.all;

entity segmentTest is

    Port ( 
			  rst:out std_logic;
			  sel:inout std_logic_vector(5 downto 0);
			  buzzer:out std_logic;
			  selSegmet2:out std_logic_vector(5 downto 0);
			  clk:in std_logic;
			  seg_dataSegment2: out STD_LOGIC_vector(7 downto 0);
           seg_data: out STD_LOGIC_vector(6 downto 0));
end segmentTest;

architecture Behavioral of segmentTest is
signal count:std_logic_vector(16 downto 0);
signal countDemo:std_logic_vector(3 downto 0);
signal count1Demo:std_logic_vector(3 downto 0);  --秒的个位
signal count2Demo:std_logic_vector(3 downto 0);	 --秒的十位
signal count3Demo:std_logic_vector(3 downto 0);	 --分的个位
signal count4Demo:std_logic_vector(3 downto 0);	 --分的十位
signal count5Demo:std_logic_vector(3 downto 0);	 --时的个位
signal count6Demo:std_logic_vector(3 downto 0);	 --时的十位

signal count1:std_logic_vector(25 downto 0);
signal count2:std_logic_vector(28 downto 0);
signal count3:std_logic_vector(31 downto 0);
signal count4:std_logic_vector(34 downto 0);
signal count5:std_logic_vector(37 downto 0);
signal count6:std_logic_vector(40 downto 0);
signal countSecond1,countSecond2:std_logic_vector(6 downto 0);--秒的数码管对应二进制数
signal countMinute1,countMinute2:std_logic_vector(6 downto 0);--分的数码管对应二进制数
signal countHour1,countHour2:std_logic_vector(6 downto 0);	  --时的数码管对应二进制数
signal selDemo:std_logic_vector(5 downto 0);  --充当sel的中间变量



signal countsegment1,countsegment2,countsegment3,countsegment4,countsegment5,countsegment6:std_logic_vector(3 downto 0);

begin

timeCount:process(clk)
	begin

----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
	if (clk' event and clk = '1') then   --晶振频率为50MHZ,一个周期就增加一次,以此来计数,一共有50 000 000次。
		count<=count+'1';  --用于数码管快速切换
		count1<=count1+'1';  --segment1,秒的个位
		count2<=count2+'1';	--segment2,秒的十位
		count3<=count3+'1';	--segment3,分的个位
		count4<=count4+'1';	--segment4,分的十位
		count5<=count5+'1';	--segment5,时的个位
		count6<=count6+'1';	--segment6,时的十位
----------------------------------------------------------------------------------------------
--------------------------------------显示秒的个位---------------------------------------------
----------------------------------------------------------------------------------------------
	if(count1 = "10111110101111000010000000") then  --秒的个位,1秒计数一次,变化一次
		count1Demo <= count1Demo + "0001";
		if(count1Demo = "1001") then
			count1Demo <=  "0000";
			count2Demo <= count2Demo + "0001";
			if(count2Demo = "0101") then    --如果秒的十位数为6,跳回0。
				count2Demo <=  "0000";
				count3Demo <= count3Demo + "0001";
					if(count3Demo = "1001") then    --如果分的个位数为10,跳回0。
					count3Demo <=  "0000";
					count4Demo <= count4Demo + "0001";
					if(count4Demo = "0101") then    --如果分的十位数为6,跳回0。
				count4Demo <=  "0000";   --没做完,还需要把时的两位放进来,但是估计到不了那里,只做了到分钟的。
			end if;
		end if;
			end if;
		end if;
	end if;
	
	
	if(count1Demo = "0000")  then  countSecond1 <= "1000000";				buzzer <='1';   --不响
			elsif (count1Demo = "0001") then  countSecond1 <= "1111001";	buzzer <='1';   --不响
			elsif (count1Demo = "0010") then  countSecond1 <= "0100100";	buzzer <='1';   --不响
			elsif (count1Demo = "0011") then  countSecond1 <= "0110000";	buzzer <='1';   --不响
			elsif (count1Demo = "0100") then  countSecond1 <= "0011001" ;	buzzer <='1';   --不响
			elsif (count1Demo = "0101") then  countSecond1 <= "0010010";	buzzer <='1';   --不响
			elsif (count1Demo = "0110") then  countSecond1 <= "0000010";	buzzer <='1';   --不响
			elsif (count1Demo = "0111") then  countSecond1 <= "1111000";	buzzer <='1';   --不响
			elsif (count1Demo = "1000") then  countSecond1 <= "0000000" ;	buzzer <='1';   --不响
			elsif (count1Demo = "1001") then  countSecond1 <= "0010000";   buzzer <='0';   --响
	end if;
----------------------------------------------------------------------------------------------
--------------------------------------显示秒的十位---------------------------------------------
----------------------------------------------------------------------------------------------
	--if(count2 = "11101110011010110010100000000") then  --秒的个位,10秒计数一次,变化一次
		--count2Demo <= "0011";
		--count2Demo <= count2Demo + "0001";
		--if(count2Demo = "0101") then    --如果秒的十位数为6,跳回0--count2Demo <=  "0000";
		--end if;
	--end if;
	
	if(count2Demo = "0000")  then  countSecond2 <= "1000000";      	   
			elsif (count2Demo = "0001") then  countSecond2 <= "1111001";	
			elsif (count2Demo = "0010") then  countSecond2 <= "0100100";
			elsif (count2Demo = "0011") then  countSecond2 <= "0110000";	
			elsif (count2Demo = "0100") then  countSecond2 <= "0011001" ;  
			elsif (count2Demo = "0101") then  countSecond2 <= "0010010";   
	end if;
----------------------------------------------------------------------------------------------
--------------------------------------显示分的个位---------------------------------------------
----------------------------------------------------------------------------------------------
	--if(count2Demo = "0110") then  --秒的个位,60秒计数一次,变化一次
		--count3Demo <= count3Demo + "0001";
		--if(count3Demo = "1001") then    --如果分的个位数为10,跳回0--count3Demo <=  "0000";
			--count4Demo <= count4Demo + "0001";
			--if(count4Demo = "0101") then    --如果分的十位数为6,跳回0--count4Demo <=  "0000";
			--end if;
		--end if;
	--end if;
	
	if(count3Demo = "0000")  then  countMinute1 <= "1000000";  			--为了让实验效果更明显,1分钟buzzer一次
			elsif (count3Demo = "0001") then  countMinute1 <= "1111001";	
			elsif (count3Demo = "0010") then  countMinute1 <= "0100100";
			elsif (count3Demo = "0011") then  countMinute1 <= "0110000";
			elsif (count3Demo = "0100") then  countMinute1 <= "0011001";
			elsif (count3Demo = "0101") then  countMinute1 <= "0010010";
			elsif (count3Demo = "0110") then  countMinute1 <= "0000010";
			elsif (count3Demo = "0111") then  countMinute1 <= "1111000";
			elsif (count3Demo = "1000") then  countMinute1 <= "0000000";
			elsif (count3Demo = "1001") then  countMinute1 <= "0010000";
	end if;
----------------------------------------------------------------------------------------------
--------------------------------------显示分的十位---------------------------------------------
----------------------------------------------------------------------------------------------
	--if(count4 = "11011111100001000111010110000000000") then  --分的十位,10分钟计数一次
		--count4Demo <="0010";
		--count4Demo <= count4Demo + "0001";
		--if(count4Demo = "0101") then    --如果分的十位数为6,跳回0--count4Demo <=  "0000";
		--end if;
	--end if;
	
	if(count4Demo = "0000")  then  countMinute2 <= "1000000";   
			elsif (count4Demo = "0001") then  countMinute2 <= "1111001";
			elsif (count4Demo = "0010") then  countMinute2 <= "0100100";
			elsif (count4Demo = "0011") then  countMinute2 <= "0110000";
			elsif (count4Demo = "0100") then  countMinute2 <= "0011001";
			elsif (count4Demo = "0101") then  countMinute2 <= "0010010";
	end if;
----------------------------------------------------------------------------------------------
--------------------------------------显示时的个位---------------------------------------------
----------------------------------------------------------------------------------------------
	if(count4Demo = "0110") then  --时的个位,60分钟计数一次
		count5Demo <= count5Demo + "0001";
		if(count5Demo = "1001") then    --如果时的十位数为6,跳回0。
			count5Demo <=  "0000";
			count6Demo <= count6Demo + "0001";
			if((count5Demo = "0100")and(count6Demo = "0010")) then    --如果时的十位数为6,跳回0。
				count6Demo <=  "0000";
				count5Demo <=  "0000";   --24点归零。
			end if;
		end if;
	end if;
	
	if(count5Demo = "0000")  then  countHour1 <= "0010000";
			elsif (count5Demo = "0001") then  countHour1 <= "1111001";
			elsif (count5Demo = "0010") then  countHour1 <= "0100100";
			elsif (count5Demo = "0011") then  countHour1 <= "0110000";
			elsif (count5Demo = "0100") then  countHour1 <= "0011001";
			elsif (count5Demo = "0110") then  countHour1 <= "0000010";
			elsif (count5Demo = "0111") then  countHour1 <= "1111000";
			elsif (count5Demo = "1000") then  countHour1 <= "0000000";
			elsif (count5Demo = "1001") then  countHour1 <= "0010000";
	end if;
----------------------------------------------------------------------------------------------
--------------------------------------显示时的十位---------------------------------------------
----------------------------------------------------------------------------------------------
	--if(count6 = "10100111101000110101100000100000000000") then  --时的十位,10小时计数一次
		--count6Demo <= count6Demo + "0001";
		--if(count6Demo = "0010") then    --如果分的十位数为6,跳回0--count6Demo <=  "0000";
		--end if;
	--end if;
	
	if(count6Demo = "0000")  then  countHour2 <= "1000000";
			elsif (count6Demo = "0001") then  countHour2 <= "1111001";
			elsif (count6Demo = "0010") then  countHour2 <= "0100100";
	end if;
----------------------------------------------------------------------------------------------
	if(count = "11000011010100000") then  --2 000 000计数一次,用于6个数码管快速切换
		count<=count - "11000011010100000"; 
		
			case countDemo is
				when "0000"  => sel<=  "111110";			
				when "0001"  => sel<=  "111101";
				when "0010"  => sel<=  "111011";
				when "0011"  => sel<=  "110111";
				when "0100"  => sel<=  "101111";
				when "0101"  => sel<=  "011111";
				when others =>sel<= "111111";
			end case;
		
		case sel is
				when "111110"  => seg_data<=  countSecond2;--显示秒的十位。  
				when "111101"  => seg_data<=  countMinute1;--显示分的个位。
				when "111011"  => seg_data<=  countMinute2;--显示分的十位。
				when "110111"  => seg_data<=  countHour1;--显示时的个位。
				when "101111"  => seg_data<=  countHour2;	 --显示时的十位。
				when "011111"  => seg_data<= countHour2 ;	 
				when others =>seg_data<= countSecond1;   --显示秒的个位。
		end case;
		
	countDemo<=countDemo + '1';  --每秒计数一次,用于显示数字。
	if(countDemo = "0110") then
		countDemo<="0000";
	end if;
		
	end if;
----------------------------------------------------------------------------------------------	
----------------------------------------------------------------------------------------------
end if;
end process;	
end Behavioral;

效果图:
在这里插入图片描述
FPGA型号:ALTERA ALINX FPGA黑金开发板 CYCLONE IV EP4CE6
使用的软件为quartus

  • 1
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值