library ieee;
use ieee.std_logic_1164.all;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
entity washer is
PORT ( power: inout std_logic; --电源标记
clk: IN std_logic; --时钟标志
start: IN std_logic; --启动按纽
mode: IN std_logic; --模式改变按纽
water: in std_logic; --水位按纽
second_time: OUT std_logic_vector(3 downto 0); --时间显示器1
first_time: OUT std_logic_vector(3 downto 0); --时间显示器2
sound: out std_logic; --发声
water_pos: OUT std_logic_vector(3 downto 0); --水位显示
power_light: OUT std_logic; --电源指示灯,1为有电,0为掉电
start_light: OUT std_logic; --启动指示灯,1为启动,0为暂停
washing_light: OUT std_logic; --洗
potching_light: OUT std_logic; --漂
drying_light: OUT std_logic); --脱
end;
architecture washer of washer is
type states is (s0,s1,s2,s3,s4,s5); --声明枚举类型
signal current_state:states; --当前模式
signal time :integer range 0 to 27;
signal last_time: integer range 0 to 27;
signal stop: std_logic; --控制最终掉电
signal count: integer range 0 to 30;
signal convert: std_logic; --convert为1时为选择模式,0时不可选择
signal complete: std_logic; --标志小过程是否完成
begin
P0: process(power,stop)
begin
power_light <= power;
if power = '1' then
if stop = '1' then
power_light <= '0';
end if;
end if;
end process P0;
P1: process(power,water) --调节水位
begin
if (power_light = '1') then
if (start_light = '0' and water'event and water = '1') then
if (water_pos = "0000") then
water_pos <= "0110";
elsif water_pos < "1000" then
water_pos <= water_pos+1;
else
water_pos <= "0100";
end if;
end if;
else
water_pos <= "0000";
end if;
end process P1;
p2: process(power,start) --控制启动暂停显示
begin
if (power_light = '1') then
if (start'EVENT and start = '1') then
start_light <= not start_light;
end if;
if (time = 0 and last_time = 1 and start_light = '1') then
start_light <= '0';
end if;
else
start_light <= '0';
end if;
end process p2;
p3: process(clk) --给模式选择后时间赋初值,并计算时间(一秒)
variable clk1:integer range 0 to 255:=0;
begin
if (power_light = '1') then
if (start_light = '1') then
if (clk'EVENT and clk = '1') then
if (time > 0) then
clk1:=clk1+1;
if(clk1=60) then
last_time <= time;
time <= time-1;
clk1:=0;
end if;
end if;
end if;
else
if convert = '1' then
case current_state is
when s0=> time <= 27;
when s1=> time <= 12;
when s2=> time <= 24;
when s3=> time <= 12;
when s4=> time <= 15;
when s5=> time <= 3;
when others=> null;
end case;
end if;
end if;
else
time <= 27; --给时间赋初值
end if;
end process p3;
p4: process(time) --控制时间显示
variable ptime: integer range 0 to 15;
begin
if (power_light = '1') then
if (start_light = '0') then --处于暂停状态
if (convert = '1' or time = 27) then --convert为1时为选择模式
case current_state is
when s0=> second_time <= "0010";
first_time <= "0111";
when s1=> second_time <= "0001";
first_time <= "0010";
when s2=> second_time <= "0010";
first_time <= "0100";
when s3=> second_time <= "0001";
first_time <= "0010";
when s4=> second_time <= "0001";
first_time <= "0101";
when s5=> second_time <= "0000";
first_time <= "0011";
when others=> null;
end case;
end if;
else --处于工作状态
case current_state is
when s0=> if time > 15 then
ptime := time-15;
elsif time > 3 then
ptime := time-3;
else ptime := time;
end if;
when s1=> ptime := time;
when s2=> if time > 12 then
ptime := time-12;
else ptime := time;
end if;
when s3=> ptime := time;
when s4=> if time > 3 then
ptime := time-3;
else ptime := time;
end if;
when s5=> ptime := time;
when others=> null;
end case;
if ptime >9 then
second_time <= "0001";
ptime := ptime-10;
else second_time <= "0000";
end if;
case ptime is
when 9=> first_time <= "1001";
when 8=> first_time <= "1000";
when 7=> first_time <= "0111";
when 6=> first_time <= "0110";
when 5=> first_time <= "0101";
when 4=> first_time <= "0100";
when 3=> first_time <= "0011";
when 2=> first_time <= "0010";
when 1=> first_time <= "0001";
when 0=> first_time <= "0000";
when others=> null;
end case;
end if;
if (start_light = '0') then
if (convert = '1') then
case current_state is
when s0=> washing_light <= '1'; potching_light <= '1'; drying_light <= '1';
when s1=> washing_light <= '1'; potching_light <= '0'; drying_light <= '0';
when s2=> washing_light <= '1'; potching_light <= '1'; drying_light <= '0';
when s3=> washing_light <= '0'; potching_light <= '1'; drying_light <= '0';
when s4=> washing_light <= '0'; potching_light <= '1'; drying_light <= '1';
when s5=> washing_light <= '0'; potching_light <= '0'; drying_light <= '1';
when others=> null;
end case;
else
case current_state is
when s0=> if (time > 15) then --暂停时将闪的灯变亮
vhdl.rar_洗衣机
版权申诉
92 浏览量
2022-09-24
03:23:48
上传
评论
收藏 2KB RAR 举报
alvarocfc
- 粉丝: 109
- 资源: 1万+
最新资源
- Code for the complete guide to tkinter tutorial
- 关于百货中心供应链管理系统.zip
- SimpleFolderIcon-master 修改Unity的Project下的文件夹图标
- A python Tkinter widget to display tile based maps
- A pure Python library for adding tables to a Tkinter application
- Vector资源文件.zip
- MobaXterm-Installer
- MicroMsg.xlsx
- 88-520告白(520气球).zip
- HTML+CSS+JS精品网页模板H126.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈