2022年进制同步计数器设计报告.docx
精选学习资料 - - - - - - - - - 浙江万里学院试验报告课程名称:可编程规律器件应用成果:试验名称: 100进制同步计数器设计老师: 施 炯专业班级:电子103 姓名:徐强学号: 2022014092 试验日期: 2022.5.10 一、试验目的:1、把握计数器的原理及设计方法;2、设计一个 0100的计数器;3、利用试验二的七段数码管电路进行显示;二、试验要求:1、用 VHDL 语言进行描写;2、有计数显示输出;3、有清零端和计数使能端;三、试验结果:1. VHDL 程序 LIBRARY IEEE ;USE IEEE.STD_LOGIC_1164.ALL ;PACKAGE my_pkg IS Component nd2 - 或门 PORT a,b: IN STD_LOGIC; c: OUT STD_LOGIC> ; END Component; Component led_decoder PORT din:in std_logic_vector3 downto 0 >; -四位二进制码输入 seg:out std_logic_vector6 downto 0> >; -输出 LED 七段码 END Component;名师归纳总结 - - - - - - -第 1 页,共 8 页精选学习资料 - - - - - - - - - Component CNT60 -2位 BCD 码 60 进制计数器 PORT CR:IN STD_LOGIC ; EN:IN STD_LOGIC ;CLK:IN STD_LOGIC ;OUTLOW:BUFFER STD_LOGIC_VECTOR3 DOWNTO 0> ;OUTHIGH:BUFFER STD_LOGIC_VECTOR3 DOWNTO 0> >;END Component;Component CNT100 -带使能和清零信号的 100 进制计数器 PORT CLK:IN STD_LOGIC ;EN:IN STD_LOGIC ;CLR:IN STD_LOGIC ;OUTLOW:BUFFER STD_LOGIC_VECTOR3 DOWNTO 0> ;OUTHIGH:BUFFER STD_LOGIC_VECTOR3 DOWNTO 0> >;END Component;Component freq_div -50MHZ 时钟分频出 1Hz PORT clkinput : IN STD_LOGIC ;output : OUT STD_LOGIC >;END Component;2 / 8 名师归纳总结 - - - - - - -第 2 页,共 8 页精选学习资料 - - - - - - - - - Component jtd -交通灯掌握器 PORT CLKIN:IN STD_LOGIC ; -50MHZ R1,G1,R2,G2,R3,G3,R4,G4:OUT STD_LOGIC; -红绿灯信号输出 GAO,DI:BUFFER STD_LOGIC_VECTOR3 DOWNTO 0> - 倒计时输出 >;END Component;END my_pkg;LIBRARY IEEE ;USE IEEE.STD_LOGIC_1164.ALL ;USE work.my_pkg.ALL ;-打开程序包ENTITY Demo3 IS PORT CRl:IN STD_LOGIC ; ENl:IN STD_LOGIC ; CLKIN: IN STD_LOGIC ; LEDLOW,LEDHIGH: OUT STD_LOGIC_VECTOR6 downto 0>>;END Demo3;ARCHITECTURE behv OF Demo3 IS SIGNAL CLKTEMP: STD_LOGIC ; -定义中转信号 SIGNAL LEDLOWTEMP,LEDHIGHTEMP:STD_LOGIC_VECTOR3 downto 0>;BEGIN u1:freq_div PORT MAPCLKIN,CLKTEMP> ;u2:CNT60 PORT -位置关联方式MAPCR=>CRl,EN=>ENl,CLK=>CLKTEMP,OUTLOW=>LEDLOWTEMP,OUTHIGH=>LEDHIGHTE MP>;-名字关联方式3 / 8 名师归纳总结 - - - - - - -第 3 页,共 8 页精选学习资料 - - - - - - - - - u3:led_decoder PORT MAPLEDLOWTEMP,LEDLOW> ;-低位数码管输 出u4:led_decoder PORT MAPLEDHIGHTEMP,LEDHIGH> ;-高位数码管输 出 END behv;LIBRARY ieee ;USE ieee.std_logic_1164.all;ENTITY freq_div IS PORT clkinput : IN STD_LOGIC ;output : OUT STD_LOGIC >;END freq_div;ARCHITECTURE rt OF freq_div IS SIGNAL count_signal : INTEGERRANGE 0 TO 25000000 ;signal mid1 : STD_LOGIC ;BEGIN PROCESS clkinput> BEGIN IF clkinput'EVENT AND clkinput = '1'> THEN if count_signal=24999999 then -50MHz division to 1Hz count_signal <= 0;mid1<= not mid1;else count_signal <= count_signal + 1;4 / 8 名师归纳总结 - - - - - - -第 4 页,共 8 页精选学习资料 - - - - - - - - - end if;output <= mid1;end if;END PROCESS;end rt;-文件名: decoder.vhd library IEEE ;use IEEE.STD_LOGIC_1164.ALL ;entity led_decoder is Port din:in std_logic_vector3 downto 0 >; -四位二进制码输入 seg:out std_logic_vector6 downto 0> >; -输出 LED 七段码 end led_decoder;architecture Behavioral of led_decoder is begin processdin> begin case din is when "0000" => seg<="1000000";-0 when "0001" => seg<="1111001";-1 when "0010" => seg<="0100100";-2 when "0011" => seg<="0110000";-3 when "0100" => seg<="0011001";-4 when "0101" => seg<="0010010";-5 when "0110" => seg<="0000010";-6 when "0111" => seg<="1011000";-7 when "1000" => seg<="0000000";-8 5 / 8 名师归纳总结 - - - - - - -第 5 页,共 8 页精选学习资料 - - - - - - - - - when "1001" => seg<="0010000";-9 when others => seg<="0000110";-E end case;end process;end Behavioral;LIBRARY IEEE ;USE IEEE.STD_LOGIC_1164.ALL ;USE IEEE.STD_LOGIC_UNSIGNED.ALL ;ENTITY CNT60 IS PORT CR:IN STD_LOGIC ; EN:IN STD_LOGIC ; CLK:IN STD_LOGIC ; OUTLOW:BUFFER STD_LOGIC_VECTOR3 DOWNTO 0> ; OUTHIGH:BUFFER STD_LOGIC_VECTOR3 DOWNTO 0> >;END CNT60;ARCHITECTURE behav OF CNT60 IS BEGIN PROCESSCLK,CR,EN> BEGIN if CR='1' then OUTHIGH<="0000" ;OUTLOW<="0000" ;elsif EN ='1'then IF CLK'EVENT AND CLK='1' THEN 6 / 8 名师归纳总结 - - - - - - -第 6 页,共 8 页精选学习资料 - - - - - - - - - IF OUTHIGH="1001" AND OUTLOW="1001" THEN OUTHIGH<="0000" ;OUTLOW<="0000" ;ELSIF OUTLOW="1001" THEN OUTHIGH<=OUTHIGH+1 ;OUTLOW<="0000" ;ELSE OUTLOW<=OUTLOW+1 ;END IF;END IF;END IF;END PROCESS;END behav;2. 仿真结果以及说明3. 程序下载及运行情形说明7 / 8 名师归纳总结 - - - - - - -第 7 页,共 8 页精选学习资料 - - - - - - - - - 四、试验总结:8 / 8 名师归纳总结 - - - - - - -第 8 页,共 8 页