院(系):电子工程学院 课程名称:EDA技术与VHDL 日期: 班级 专业 实验名称 所用软件 实 验 目 的 或 要 求 实 验 步 骤 、 心 得 体 会 数字时钟 Quartus Ⅱ7.0 学号 姓名 实验室 计算机号 成绩评价 教师签名 设计一个可以计时的数字时钟,其显示时间范 围是00:00:00~23:59:59,且该时钟具有暂停计时、 清零等功能。 1、 启动 Quartus Ⅱ建立一个空白工程并命名。 2、 新建VHDL源程序文件,输入程序代码并保存,进行综合编译,若在编译过程中发现错误,则找出并更正错误,直至编译成功为止。 3、 选择目标器件rst、set接拨挡开关,时钟输入引脚接系统时钟(48M),显示码输出XQ0~XQ7接seg0~seg7,数码管选通信号DIG0~DIG5接实验箱上dig0~dig5,并对相应的引脚进行锁定,引脚对应关系查实验指导书附录。将未使用的管脚设置为三态输入(一定要设置,否则可能会损坏芯片)。 4、 对该工程进行全程编译处理,若在编译过程中发现错误,则找出并更正错误,直至编译成功为止。 5、 设计下载 1) 使用下载线,连接计算机USB口和实验箱JTAG下载口(注意插口方向),打开实验箱电源。 2) 启动下载界面,确认已选中下载线。 3) 完成下载界面的设置,启动下载。 4) 按动按键开关KET1来输入脉冲信号,波动拨挡开关SW2、SW1来控制输入信号,观察数码管的变化规律并记录实验结果,看是否与预期设计一致。 程序: library IEEE; use IEEE.STD_LOGIC_11.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY LED_0000_9999 IS PORT ( clk : IN std_logic; --系统时钟50M rst : IN std_logic; --系统REST键,KEY1 s : IN std_logic; --stop led_out : OUT std_logic_vector(7 DOWNTO 0); --各段数据输出 led_bit : OUT std_logic_vector(5 DOWNTO 0)); --数码管的位选择口。一共8位 END LED_0000_9999 ; ARCHITECTURE arch OF LED_0000_9999 IS signal div_cnt : std_logic_vector(26 downto 0 ); signal data4 : std_logic_vector(3 downto 0); signal dataout_xhdl1 : std_logic_vector(7 downto 0); signal en_xhdl : std_logic_vector(5 downto 0); signal cntfirst :std_logic_vector(3 downto 0); signal cntsecond : std_logic_vector(3 downto 0); signal cntthird : std_logic_vector(3 downto 0); signal cntfour : std_logic_vector(3 downto 0); signal cntfive : std_logic_vector(3 downto 0); signal cntlast : std_logic_vector(3 downto 0); signal first_over: std_logic; signal second_over: std_logic; signal third_over : std_Logic; signal four_over : std_logic; signal five_over : std_Logic; signal last_over : std_logic; begin led_out<=dataout_xhdl1; led_bit<=en_xhdl; process(clk,rst) begin if(rst='0')then div_cnt<=\"001001100000000000000000000\"; elsif(clk'event and clk='1')then div_cnt<=div_cnt+1; --利用计数器分频 end if; end process; process(div_cnt(26),rst,last_over) begin if(s='1')then if(rst='0')then cntfirst<=\"0000\"; first_over<='0'; elsif(div_cnt(26)'event and div_cnt(26)='1')then if(cntfirst=\"1001\" or last_over='1')then cntfirst<=\"0000\"; first_over<='1'; else first_over<='0'; cntfirst<=cntfirst+1; end if; end if; end if; end process; process(first_over,rst) --first 10 counter begin if(rst='0')then cntsecond<=\"0000\"; second_over<='0'; elsif(first_over'event and first_over='1')then if(cntsecond=\"0101\")then cntsecond<=\"0000\"; second_over<='1'; else second_over<='0'; cntsecond<=cntsecond+1; end if; end if; end process; process(second_over,rst) --second 10 counter begin if(rst='0')then cntthird<=\"0000\"; third_over<='0'; elsif(second_over'event and second_over='1')then if( cntthird=\"1001\")then cntthird<=\"0000\"; third_over<='1'; else third_over<='0'; cntthird<= cntthird+1; end if; end if; end process; process(third_over,rst) --third 10 counter begin if(rst='0')then cntfour<=\"0000\"; four_over<='0'; elsif(third_over'event and third_over='1')then if( cntfour=\"0101\")then cntfour<=\"0000\"; four_over<='1'; else four_over<='0'; cntfour<= cntfour+1; end if; end if; end process; process(four_over,rst) --four 10 counter begin if(rst='0')then cntfive<=\"0000\"; five_over<='0'; elsif(four_over'event and four_over='1')then if( cntfive=\"1001\" or cntlast>\"0010\")then cntfive<=\"0000\"; five_over<='1'; else five_over<='0'; cntfive<= cntfive+1; end if; end if; if(cntlast=\"0010\" and cntfive=\"0100\")then cntfive<=\"0000\" ; end if; end process; process(five_over,rst) --five 10 counter begin if(rst='0')then cntlast<=\"0000\"; last_over<='0'; elsif(five_over'event and five_over='1')then if( cntlast=\"0010\")then cntlast<=\"0000\"; last_over<='1'; else last_over<='0'; cntlast<= cntlast+1; end if; end if; if(cntlast=\"0010\" and cntfive=\"0100\")then cntlast<=\"0000\" ; end if; end process; ---****************显示部分***************-- process(rst,clk,div_cnt(16 downto 14)) begin if(rst='0')then en_xhdl<=\"111111\"; elsif(clk'event and clk='1')then case div_cnt(16 downto 14) is --利用计数器分频 when\"000\"=> en_xhdl<=\"111110\"; when\"001\"=> en_xhdl<=\"111101\"; when\"010\"=> en_xhdl<=\"111011\"; when\"011\"=> en_xhdl<=\"110111\"; when\"100\"=> en_xhdl<=\"101111\"; when\"101\"=> en_xhdl<=\"011111\"; when others => en_xhdl<=\"111111\"; end case; end if; end process; process (en_xhdl,cntfirst,cntsecond,cntthird,cntfour,cntfive,cntlast) begin case en_xhdl is when \"111110\"=> data4<=cntfirst; when \"111101\"=> data4<=cntsecond; when \"111011\"=> data4<=cntthird; when \"110111\"=> data4<=cntfour; when \"101111\"=> data4<=cntfive; when \"011111\"=> data4<=cntlast; when others => data4<=\"1111\"; end case; end process; process(data4) begin case data4 is WHEN \"0000\" => dataout_xhdl1 <= \"11000000\"; --数码管的段码 WHEN \"0001\" =>dataout_xhdl1 <= \"11111001\"; WHEN \"0010\" => dataout_xhdl1 <= \"10100100\"; WHEN \"0011\" => dataout_xhdl1 <= \"10110000\"; WHEN \"0100\" => dataout_xhdl1 <= \"10011001\"; WHEN \"0101\" => dataout_xhdl1 <= \"10010010\"; WHEN \"0110\" => dataout_xhdl1 <= \"10000010\" WHEN \"0111\" => dataout_xhdl1 <= \"11111000 WHEN \"1000\" => dataout_xhdl1 <= \"10000000 WHEN \"1001\" =>dataout_xhdl1 <= \"10010000\"; WHEN \"1010\" => dataout_xhdl1 <= \"10000000\" WHEN \"1011\" => dataout_xhdl1 <= \"10010000\"; WHEN \"1100\" => dataout_xhdl1 <= \"01100011 WHEN \"1101\" => dataout_xhdl1 <= \"10000101\"; WHEN \"1110\" => dataout_xhdl1 <= \"01100001\"; WHEN \"1111\" => dataout_xhdl1 <= \"01110001\"; WHEN OTHERS => dataout_xhdl1 <= \"00000011\"; END CASE; END PROCESS; end arch