当前位置:文档之家› 西电EDA大作业多功能彩灯

西电EDA大作业多功能彩灯

EDA设计报告彩灯控制器(老师:宗汝)班级:学号:姓名:一.设计要求设计能让一排灯(8只)自动改变显示花样的控制系统。

可将实验板上的一排发光二极管作为彩灯用。

控制器应有两种控制方式:◆规则变化。

变化节拍有0.5秒和0.25秒两种,交替出现,每种节拍可有8种花样,各执行一或二个周期后轮换。

彩灯变化方向有单向移动,双向移动,跳跃移动等。

◆随机变化。

变化花样相同,但节拍及花样的转换都随机出现。

二.设计方案(1).分频模块。

要产生快慢两种节拍,则首先需要有分频器模块,0.5秒和0.25秒两种则可选择四分频和八分频。

通过按键进行选择切换。

则clk为输入时钟信号,需经分频器分频并输入到LED显示电路;clr为复位清零信号,高电平有效,有效时,电路无条件的回到初始状态;OPT为频率快慢选择信号,低电平节奏快,高电平节奏慢;(2)LED显示模块。

经过分频的时钟信号输入LED显示电路中,使电路有规律的输出按照设定的各种花样变化。

xuan为选择彩灯变化花样信号,便于改变彩灯花样。

而最后就是输出彩灯变化花样led。

三.系统程序设计分频器模块:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity FENPINQI isport(clk:in std_logic;clr:in std_logic;opt:in std_logic;clkout:out std_logic);end FENPINQI;architecture arc of FENPINQI issignal clk_tmp: std_logic;signal counter: std_logic_vector(1 downto 0);beginprocess(clk,clr,opt)beginif clr='1' then --清零clk_tmp<='0';counter<="00";elsif clk'event and clk='1' thenif opt='0' then --四分频if counter="01" thencounter<="00";clk_tmp<=not clk_tmp;elsecounter<=counter+'1';end if;else --八分频if counter="11" thencounter<="00";clk_tmp<=not clk_tmp;elsecounter<=counter+'1';end if;end if;end if;end process;clkout<=clk_tmp; --输出分频后的信号end arc;花样一:--用分频器分频后的时钟来显示花样实现library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity HY1 isport(clk1:in std_logic;clr:in std_logic;xuan:in std_logic_vector(1 downto 0);led1:out std_logic_vector(7 downto 0));end HY1;architecture arc of HY1 istype state is(s0,s1,s2,s3,s4,s5,s6);signal current_state:state;signal light:std_logic_vector(7 downto 0);beginprocess(clr,clk1,xuan)isconstant l1:std_logic_vector(7 downto 0):="10000001";constant l2:std_logic_vector(7 downto 0):="01000010";constant l3:std_logic_vector(7 downto 0):="00100100";constant l4:std_logic_vector(7 downto 0):="00011000";constant l5:std_logic_vector(7 downto 0):="00100100";constant l6:std_logic_vector(7 downto 0):="01000010";beginif xuan="01"thenif clr='1' thencurrent_state<=s0;elsif(clk1'event and clk1='1') thencase current_state iswhen s0=>light<="ZZZZZZZZ";current_state<=s1;when s1=>light<=l1;current_state<=s2;when s2=>light<=l2;current_state<=s3;when s3=>light<=l3;current_state<=s4;when s4=>light<=l4;current_state<=s5;when s5=>light<=l5;current_state<=s6;when s6=>light<=l6;current_state<=s1;end case;end if;end if;end process;led1<=light;end arc;花样二:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity HY2 isport(clk1:in std_logic;clr:in std_logic;xuan:in std_logic_vector(1 downto 0);led2:out std_logic_vector(7 downto 0));end HY2;architecture arc of HY2 istype state is(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,s 20,s21,s22,s23,s24,s25,s26,s27,s28,s29,s30);signal current_state:state;signal light:std_logic_vector(7 downto 0);beginprocess(clr,clk1,xuan)isconstant l1:std_logic_vector(7 downto 0):="00000000";constant l2:std_logic_vector(7 downto 0):="10000000";constant l3:std_logic_vector(7 downto 0):="11000000";constant l4:std_logic_vector(7 downto 0):="11100000";constant l5:std_logic_vector(7 downto 0):="11110000";constant l6:std_logic_vector(7 downto 0):="11111000"; constant l7:std_logic_vector(7 downto 0):="11111100"; constant l8:std_logic_vector(7 downto 0):="11111110"; constant l9:std_logic_vector(7 downto 0):="11111111"; constant l10:std_logic_vector(7 downto 0):="01111111"; constant l11:std_logic_vector(7 downto 0):="00111111"; constant l12:std_logic_vector(7 downto 0):="00011111"; constant l13:std_logic_vector(7 downto 0):="00001111"; constant l14:std_logic_vector(7 downto 0):="00000111"; constant l15:std_logic_vector(7 downto 0):="00000011"; constant l16:std_logic_vector(7 downto 0):="00000001"; constant l17:std_logic_vector(7 downto 0):="00000011"; constant l18:std_logic_vector(7 downto 0):="10000111"; constant l19:std_logic_vector(7 downto 0):="00001111"; constant l20:std_logic_vector(7 downto 0):="00011111"; constant l21:std_logic_vector(7 downto 0):="00111111"; constant l22:std_logic_vector(7 downto 0):="01111111"; constant l23:std_logic_vector(7 downto 0):="11111111"; constant l24:std_logic_vector(7 downto 0):="11111110"; constant l25:std_logic_vector(7 downto 0):="11111100"; constant l26:std_logic_vector(7 downto 0):="11111000"; constant l27:std_logic_vector(7 downto 0):="11110000"; constant l28:std_logic_vector(7 downto 0):="11100000"; constant l29:std_logic_vector(7 downto 0):="11000000"; constant l30:std_logic_vector(7 downto 0):="10000000"; beginif xuan="10" thenif clr='1' thencurrent_state<=s0;elsif(clk1'event and clk1='1') thencase current_state iswhen s0=>light<="ZZZZZZZZ";current_state<=s1;when s1=>light<=l1;current_state<=s2;when s2=>light<=l2;current_state<=s3;when s3=>light<=l3;current_state<=s4;when s4=>light<=l4;current_state<=s5;when s5=>light<=l5;current_state<=s6;when s6=>light<=l6;current_state<=s7;when s7=>light<=l7;current_state<=s8;when s8=>light<=l8;current_state<=s9;when s9=>light<=l9;current_state<=s10;when s10=>light<=l10;current_state<=s11;when s11=>light<=l11;current_state<=s12;when s12=>light<=l12;current_state<=s13;when s13=>light<=l13;current_state<=s14;when s14=>light<=l14;current_state<=s15;when s15=>light<=l15;current_state<=s16;when s16=>light<=l16;current_state<=s17;when s17=>light<=l17;current_state<=s18;when s18=>light<=l18;current_state<=s19;when s19=>light<=l19;current_state<=s20;when s20=>light<=l20;current_state<=s21;when s21=>light<=l21;current_state<=s22;when s22=>light<=l22;current_state<=s23;when s23=>light<=l23;current_state<=s24;when s24=>light<=l24;current_state<=s25;when s25=>light<=l25;current_state<=s26;when s26=>light<=l26;current_state<=s27;when s27=>light<=l27;current_state<=s28;when s28=>light<=l28;current_state<=s29;when s29=>light<=l29;current_state<=s30;when s30=>light<=l30;current_state<=s1;end case;end if;end if;end process;led2<=light;end art;花样三:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity HY3 isport(clk1:in std_logic;clr:in std_logic;xuan:in std_logic_vector(1 downto 0);led3:out std_logic_vector(7 downto 0));end HY3;architecture art of HY3 istype state is(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14); signal current_state:state;signal light:std_logic_vector(7 downto 0);beginprocess(clr,clk1,xuan)isconstant l1:std_logic_vector(7 downto 0):="10000000";constant l2:std_logic_vector(7 downto 0):="01000000"; constant l3:std_logic_vector(7 downto 0):="00100000"; constant l4:std_logic_vector(7 downto 0):="00010000"; constant l5:std_logic_vector(7 downto 0):="00001000"; constant l6:std_logic_vector(7 downto 0):="00000100"; constant l7:std_logic_vector(7 downto 0):="00000010"; constant l8:std_logic_vector(7 downto 0):="00000001"; constant l9:std_logic_vector(7 downto 0):="00000010"; constant l10:std_logic_vector(7 downto 0):="00000100"; constant l11:std_logic_vector(7 downto 0):="00001000"; constant l12:std_logic_vector(7 downto 0):="00010000"; constant l13:std_logic_vector(7 downto 0):="00100000"; constant l14:std_logic_vector(7 downto 0):="01000000"; beginif xuan="11" thenif clr='1'thencurrent_state<=s0;elsif(clk1'event and clk1='1')thencase current_state is --状态机转换when s0=>light<="ZZZZZZZZ";current_state<=s1;when s1=>light<=l1;current_state<=s2;when s2=>light<=l2;current_state<=s3;when s3=>light<=l3;current_state<=s4;when s4=>light<=l4;current_state<=s5;when s5=>light<=l5;current_state<=s6;when s6=>light<=l6;current_state<=s7;when s7=>light<=l7;current_state<=s8;when s8=>light<=l8;current_state<=s9;when s9=>light<=l9;current_state<=s10;when s10=>light<=l10;current_state<=s11;when s11=>light<=l11;current_state<=s12;when s12=>light<=l12;current_state<=s13;when s13=>light<=l13;current_state<=s14;when s14=>light<=l14;current_state<=s1;end case;end if;end if;end process;led3<=light;end art;花样四:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity HY4 isport(clk1:in std_logic;clr:in std_logic;xuan:in std_logic_vector(1 downto 0);led4:out std_logic_vector(7 downto 0));end HY4;architecture art of HY4 istype state is(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14); signal current_state:state;signal light:std_logic_vector(7 downto 0);beginprocess(clr,clk1,xuan)isconstant l1:std_logic_vector(7 downto 0):="10101010";constant l2:std_logic_vector(7 downto 0):="01010101";constant l3:std_logic_vector(7 downto 0):="10010010";constant l4:std_logic_vector(7 downto 0):="01001001";constant l5:std_logic_vector(7 downto 0):="10010100";constant l6:std_logic_vector(7 downto 0):="01001001";constant l7:std_logic_vector(7 downto 0):="00100100";constant l8:std_logic_vector(7 downto 0):="00011000";constant l9:std_logic_vector(7 downto 0):="00101010";constant l10:std_logic_vector(7 downto 0):="11000011";constant l11:std_logic_vector(7 downto 0):="01100000";constant l12:std_logic_vector(7 downto 0):="00111000";constant l13:std_logic_vector(7 downto 0):="10001100";constant l14:std_logic_vector(7 downto 0):="01001001";beginif xuan="00" thenif clr='1'thencurrent_state<=s0;elsif(clk1'event and clk1='1')thencase current_state iswhen s0=>light<="ZZZZZZZZ";current_state<=s1;when s1=>light<=l1;current_state<=s2;when s2=>light<=l2;current_state<=s3;when s3=>light<=l3;current_state<=s4;when s4=>light<=l4;current_state<=s5;when s5=>light<=l5;current_state<=s6;when s6=>light<=l6;current_state<=s7;when s7=>light<=l7;current_state<=s8;when s8=>light<=l8;current_state<=s9;when s9=>light<=l9;current_state<=s10;when s10=>light<=l10;current_state<=s11;when s11=>light<=l11;current_state<=s12;when s12=>light<=l12;current_state<=s13;when s13=>light<=l13;current_state<=s14;when s14=>light<=l14;current_state<=s1;end case;end if;end if;end process;led4<=light;end art;顶层设计:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity caideng8 isport(clk:in std_logic;clr:in std_logic;opt:in std_logic;xuan:in std_logic_vector(1 downto 0);led:out std_logic_vector(7 downto 0) --八路彩灯输出);end caideng8;architecture art of caideng8 iscomponent FENPINQI --对分频器模块进行定义port(clk:in std_logic;clr:in std_logic;opt:in std_logic;clkout:out std_logic);end component FENPINQI;component HY1 --对花样一模块进行定义port(clk1:in std_logic;clr:in std_logic;xuan:in std_logic_vector(1 downto 0);led1:out std_logic_vector(7 downto 0));end component HY1;component HY2 --对花样二模块进行定义port(clk1:in std_logic;clr:in std_logic;xuan:in std_logic_vector(1 downto 0);led2:out std_logic_vector(7 downto 0));end component HY2;component HY3 --对花样三模块进行定义port(clk1:in std_logic;clr:in std_logic;xuan:in std_logic_vector(1 downto 0);led3:out std_logic_vector(7 downto 0));end component HY3;component HY4port(clk1:in std_logic;clr:in std_logic;xuan:in std_logic_vector(1 downto 0);led4:out std_logic_vector(7 downto 0));end component HY4;signal s:std_logic; --定义中间变量signal l1:std_logic_vector(7 downto 0);signal l2:std_logic_vector(7 downto 0);signal l3:std_logic_vector(7 downto 0);signal l4:std_logic_vector(7 downto 0);beginu1:FENPINQI port map(clk,clr,opt,s);u2:HY1 port map(s,clr,xuan,l1);u3:HY2 port map(s,clr,xuan,l2);u4:HY3 port map(s,clr,xuan,l3);u5:HY4 port map(s,clr,xuan,l4);led<=l1 when xuan="01" elsel2 when xuan="10" elsel3 when xuan="11" elsel4;end art;四.仿真花样一仿真波形:clr为输入,是异步复位端,当为高电平时有效。

相关主题