alarm_state_machine.vhd
来自「design compile synthesis user guide」· VHDL 代码 · 共 52 行
VHD
52 行
entity ALARM_STATE_MACHINE is port (ALARM_BUTTON, HOURS_BUTTON, MINUTES_BUTTON, CLK: in BIT; HOURS, MINS: out BIT);end;architecture BEHAVIOR of ALARM_STATE_MACHINE is type STATE_TYPE is (IDLE,SET_HOURS,SET_MINUTES); signal CURRENT_STATE, NEXT_STATE: STATE_TYPE;begin COMBIN: process(CURRENT_STATE, ALARM_BUTTON, HOURS_BUTTON, MINUTES_BUTTON) begin NEXT_STATE <= CURRENT_STATE; HOURS <= '0'; MINS <= '0'; case CURRENT_STATE is when IDLE => if (ALARM_BUTTON = '1' and HOURS_BUTTON = '1' and MINUTES_BUTTON = '0') then NEXT_STATE <= SET_HOURS; HOURS <= '1'; elsif (ALARM_BUTTON = '1' and MINUTES_BUTTON = '1' and HOURS_BUTTON = '0') then NEXT_STATE <= SET_MINUTES; MINS <= '1'; else NEXT_STATE <= IDLE; end if; when SET_HOURS => if (ALARM_BUTTON = '1' and HOURS_BUTTON = '1' and MINUTES_BUTTON = '0')then NEXT_STATE <= SET_HOURS; HOURS <= '0'; else NEXT_STATE <= IDLE; end if; when SET_MINUTES => if (ALARM_BUTTON = '1' and MINUTES_BUTTON = '1' and HOURS_BUTTON = '0') then NEXT_STATE <= SET_MINUTES; MINS <= '0'; else NEXT_STATE <= IDLE; end if; end case; end process; SYNCH: process begin wait until CLK'event and CLK = '1'; CURRENT_STATE <= NEXT_STATE; end process;end BEHAVIOR;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?