entity micro_controller is Port (clk_mc,m_ua,cmrom_cs:instd_logic; ir:instd_logic_vector(7downto2); arr:outstd_logic_vector(7downto0); next_arr:outstd_logic_vector(7downto0); cm:outstd_logic_vector(47downto8) ); end micro_controller;
architecture Behavioral of micro_controller is component cmrom is Port (m_rom,nrom_en:instd_logic; addr:instd_logic_vector(7downto0); data:outstd_logic_vector(47downto0) ); endcomponent;
signal uar:std_logic_vector(7downto0) := (others => '0'); signal uir:std_logic_vector(47downto0); signal clkk:std_logic;
begin cm1:cmrom portmap(m_rom=>cmrom_cs, nrom_en=>'0', addr=>uar, data=>uir); cm <= uir(47downto8); -- 控制字段 next_arr <= uir(7downto0); -- 下条地址字段 arr <= uar; -- 当前地址 -- clkk 50000000 process(clk_mc) variable count: integerrange0to60000000; begin if clk_mc'eventand clk_mc='1'then count:=count+1; if count=50000000then clkk<=not clkk; count:=0; endif; endif; endprocess;
process(m_ua,clkk) begin if rising_edge(clkk) then if cmrom_cs = '1'then if m_ua = '1'then uar(5downto0) <= ir; uar(7downto6) <= "00"; elsif m_ua='0'then uar<=uir(7downto0); endif; endif; endif; endprocess;
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.std_logic_unsigned.all;
entity state is Port (clk, rst : instd_logic; key_in : instd_logic_vector(15downto0); seg_sel : outstd_logic_vector(15downto0); seg_data : outstd_logic_vector(7downto0); show:instd_logic_vector(63downto0) ); end state;
architecture Behavioral of state is type states is (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15); signal state,next_state:states; signal show1: std_logic_vector(3downto0); signal rsts,clks: std_logic; signal cc: std_logic; signal showw:std_logic_vector(63downto0);
component data2seg is Port (data_in:instd_logic_vector(3downto0); seg_data:outstd_logic_vector(7downto0)); endcomponent;
begin u: data2seg portmap(data_in=>show1, seg_data=>seg_data);
process(clk) variable count: integerrange0to30000; begin if clk'eventand clk='1'then count:=count+1; if count=20000then cc<=not cc; count:=0; endif; endif; endprocess; process(cc,clk,rst) --复位和状态转移 begin if rst='1'then state<=s0; showw<=x"0000000000000000"; elsif cc'eventand cc='1'then showw<=show; state<=next_state; endif; endprocess; process(state) begin case state is--数码管输出 when s0=>if key_in(0)='1'then seg_sel<=x"fffe"; show1<=showw(3downto0); else seg_sel<=x"ffff"; endif; next_state<=s1; when s1=>if key_in(1)='1'then seg_sel<=x"fffd"; show1<=showw(7downto4); else seg_sel<=x"ffff"; endif; next_state<=s2; when s2=>if key_in(2)='1'then seg_sel<=x"fffb"; show1<=showw(11downto8); else seg_sel<=x"ffff"; endif; next_state<=s3; when s3=>if key_in(3)='1'then seg_sel<=x"fff7"; show1<=showw(15downto12); else seg_sel<=x"ffff"; endif; next_state<=s4; when s4=>if key_in(4)='1'then seg_sel<=x"ffef"; show1<=showw(19downto16); else seg_sel<=x"ffff"; endif; next_state<=s5; when s5=>if key_in(5)='1'then seg_sel<=x"ffdf"; show1<=showw(23downto20); else seg_sel<=x"ffff"; endif; next_state<=s6; when s6=>if key_in(6)='1'then seg_sel<=x"ffbf"; show1<=showw(27downto24); else seg_sel<=x"ffff"; endif; next_state<=s7; when s7=>if key_in(7)='1'then seg_sel<=x"ff7f"; show1<=showw(31downto28); else seg_sel<=x"ffff"; endif; next_state<=s8; when s8=>if key_in(8)='1'then seg_sel<=x"feff"; show1<=showw(35downto32); else seg_sel<=x"ffff"; endif; next_state<=s9; when s9=>if key_in(9)='1'then seg_sel<=x"fdff"; show1<=showw(39downto36); else seg_sel<=x"ffff"; endif; next_state<=s10; when s10=>if key_in(10)='1'then seg_sel<=x"fbff"; show1<=showw(43downto40); else seg_sel<=x"ffff"; endif; next_state<=s11; when s11=>if key_in(11)='1'then seg_sel<=x"f7ff"; show1<=showw(47downto44); else seg_sel<=x"ffff"; endif; next_state<=s12; when s12=>if key_in(12)='1'then seg_sel<=x"efff"; show1<=showw(51downto48); else seg_sel<=x"ffff"; endif; next_state<=s13; when s13=>if key_in(13)='1'then seg_sel<=x"dfff"; show1<=showw(55downto52); else seg_sel<=x"ffff"; endif; next_state<=s14; when s14=>if key_in(14)='1'then seg_sel<=x"bfff"; show1<=showw(59downto56); else seg_sel<=x"ffff"; endif; next_state<=s15; when s15=>if key_in(15)='1'then seg_sel<=x"7fff"; show1<=showw(63downto60); else seg_sel<=x"ffff"; endif; next_state<=s0; endcase; endprocess;
entity data2seg is Port (data_in:instd_logic_vector(3downto0); seg_data:outstd_logic_vector(7downto0)); end data2seg;
architecture Behavioral of data2seg is
begin process(data_in) begin case data_in is when x"0"=>seg_data<=x"c0"; when x"1"=>seg_data<=x"f9"; when x"2"=>seg_data<=x"a4"; when x"3"=>seg_data<=x"b0"; when x"4"=>seg_data<=x"99"; when x"5"=>seg_data<=x"92"; when x"6"=>seg_data<=x"82"; when x"7"=>seg_data<=x"f8"; when x"8"=>seg_data<=x"80"; when x"9"=>seg_data<=x"90"; when x"a"=>seg_data<=x"88"; when x"b"=>seg_data<=x"83"; when x"c"=>seg_data<=x"c6"; when x"d"=>seg_data<=x"a1"; when x"e"=>seg_data<=x"86"; when x"f"=>seg_data<=x"8e"; endcase; endprocess;