⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wash-machine.txt

📁 VHDL。改程序为洗衣机的源代码 VHDL。改程序为洗衣机的源代码
💻 TXT
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_signed.all;
use ieee.std_logic_unsigned.all;
entity washer is
port(keyboard,clk,pause:in bit;
     ring:out bit;
     light:out std_logic_vector(2 downto 0);
     ah,al:out std_logic_vector(6 downto 0));
end washer;
architecture course of washer is
  signal clkout1:bit:='0';--分频中间信号
  signal clkout2:bit:='0';--分频中间信号
  signal clkout3:bit:='0';--分频中间信号
  signal midclk1:bit:='0';--分频中间信号
  signal midclk2:bit:='0';--分频中间信号
  signal rin1:integer range 0 to 4;--震铃驱动中间信号
  signal rin2:integer range 0 to 4;--震铃驱动中间信号
  signal i1:integer range 0 to 4;--分频中间信号
  signal i2:integer range 0 to 4;--分频中间信号
  signal i3:integer range 0 to 4;--分频中间信号
  signal clkrin:bit:='0';--震铃驱动信号
  signal finish:bit:='0';--响铃时间控制信号
  signal change:integer range 0 to 40;--转换标志信号
  signal ss:integer range 0 to 11;--转换标志信号
  signal pp:integer range 0 to 11;--转换标志信号
  signal clkout:bit:='0';--中间时钟信号
  signal mid:bit:='1';--暂停标志信号
  signal che :integer range 0 to 5;--状态标志信号
  signal d:bit:='0';--中间状态标志信号
  signal e:integer range 0 to 2;--中间状态标志信号
  signal count :integer range 0 to 20;--计时信号
  signal count1 :integer range 0 to 20;--计时信号
  signal count2 :integer range 0 to 15;--计时信号
  signal count3 :integer range 0 to 10;--计时信号
  signal i4:integer range 0 to 4;--分频中间信号
  signal aa:bit:='0';--初始化标志
  constant dis0:std_logic_vector(6 downto 0):="0111111";--数字编码
  constant dis1:std_logic_vector(6 downto 0):="0000110";--数字编码
  constant dis2:std_logic_vector(6 downto 0):="1011011";--数字编码
  constant dis3:std_logic_vector(6 downto 0):="1001111";--数字编码
  constant dis4:std_logic_vector(6 downto 0):="1100110";--数字编码
  constant dis5:std_logic_vector(6 downto 0):="1101101";--数字编码
  constant dis6:std_logic_vector(6 downto 0):="1111101";--数字编码
  constant dis7:std_logic_vector(6 downto 0):="0000111";--数字编码
  constant dis8:std_logic_vector(6 downto 0):="1111111";--数字编码
  constant dis9:std_logic_vector(6 downto 0):="1101111";--数字编码
  begin
    sd1:process(clk)
      begin
        if(clk'event and clk='1')then
          if(rin1<4)then
            rin1<=rin1+1;
          else
            rin1<=0;
            midclk1<=midclk1 xor '1';
          end if;
        end if;
      end process sd1;--十倍分频
    sd2:process(midclk1)
      begin
        if(midclk1'event and midclk1='1')then
          if(rin2<4)then
            rin2<=rin2+1;
          else
            rin2<=0;
            midclk2<=midclk2 xor'1';
          end if;
        end if;
      end process sd2;--十倍分频
    sd3:process(midclk2)
      begin
        if(midclk2'event and midclk2='1')then
          if(i1<4)then
            i1<=i1+1;
          else
            i1<=0;
            clkout1<=clkout1 xor'1';
          end if;
          if(change<40)then
            clkrin<=clkrin xor '1';
            change<=change+1;
          else
            change<=0;
          end if;
        end if;
      end process sd3;--十倍分频并传递给响铃驱动
    sd4:process(clkout1)
      begin
        if(clkout1'event and clkout1='1')then
          if(i2<4)then
            i2<=i2+1;
          else
            i2<=0;
            clkout2<=clkout2 xor'1';
          end if;
        end if;
      end process sd4;--十倍分频
    sd5:process(clkout2)
      begin
        if(clkout2'event and clkout2='1')then
          if(i3<4)then
            i3<=i3+1;
          else
            i3<=0;
            clkout3<=clkout3 xor'1';
          end if;
        end if;
      end process sd5;--十倍分频
    sd6:process(clkout3)
      begin
        if(clkout3'event and clkout3='1')then
          if(i4<4)then
            i4<=i4+1;
          else
            i4<=0;
            clkout<=clkout xor'1';
          end if;
        end if;
      end process sd6;--1s驱动信号产生
    sd7:process(clk)
      begin
        if(clk'event and clk='1')then
          if(finish='1')then
            pp<=ss;
          end if;
          if(finish='1'and pp<11)then
            ring<=clkrin;
          end if;
          if(finish='1'and pp<11 and change=40)then
            pp<=pp+1;
          end if;
        end if;
      end process sd7;--控制报警信号
    sd8:process(clkout)
      begin
        if(clkout'event and clkout='1')then--1s时钟信号上升沿触发
          if(pause='0')then
            mid<=mid xor '1';--暂停控制信号
          end if;
          if(mid='1')then     --开始状态
            if(keyboard='0')then--按键检测
              if(aa='0')then--初始化使能标志
                che<=0;--状态选择
                d<='0';--转化标志
                e<=0;--转化标志
                count1<=20;--倒计时信号
                count2<=15;--倒计时信号
                count3<=10;--倒计时信号
                aa<='1';--初始化使能标志恢复
              end if;
              if(che<5)then
                che<=che+1;
              else
                che<=0;
              end if;--状态转化
            end if;
            if(count1=0 or count2=0 or count3=0)then
              finish<='1';
            else
              finish<='0';
              ss<=0;
            end if;--报警使能标志
            if(keyboard='1')then--无按键状态
              case che is--状态检测
                when 1=>light<="100";
                        if(count1>=0)then
                          count1<=count1 - 1;
                          count<=count1;
                        end if;
                        if(count1=0)then
                          aa<='0';
                        end if;
                when 2=>light<="010";
                        if(count2>=0)then
                          count2<=count2 - 1;
                          count<=count2;
                        end if;
                        if(count2=0)then
                          aa<='0';
                        end if;
                when 3=>light<="001";
                        if(count3>=0)then
                          count3<=count3 - 1;
                          count<=count3;
                        end if;
                        if(count3=0)then
                          aa<='0';
                        end if;
                when 4=>if(d='0')then
                          light<="010";
                          if(count2>=0)then
                            count2<=count2 - 1;
                            count<=count2;
                          end if;
                          if(count2=0)then
                            d<='1';
                          end if;
                        else
                          light<="001";
                          if(count3>=0)then
                            count3<=count3 - 1;
                            count<=count3;
                          end if;
                          if(count3=0)then
                            aa<='0';
                          end if;
                        end if;
                  when 5=>if(e=0)then
                            light<="100";
                            if(count1>=0)then
                              count1<=count1 - 1;
                              count<=count1;
                            end if;
                            if(count1=0)then
                              e<=1;
                            end if;
                          elsif(e=1)then
                            light<="010";
                            if(count2>=0)then
                              count2<=count2 - 1;
                              count<=count2;
                            end if;
                            if(count2=0)then
                              e<=2;
                            end if;
                          else
                            light<="001";
                            if(count3>=0)then
                              count3<=count3 - 1;
                              count<=count3;
                            end if;
                            if(count3=0)then
                              aa<='0';
                            end if;
                          end if;
                    when others=>null;
              end case;
            end if;
          end if;--倒计时信号递减
          case count is
            when 20=>ah<=dis2;
                     al<=dis0;
            when 19=>ah<=dis1;
                     al<=dis9;
            when 18=>ah<=dis1;
                     al<=dis8;
            when 17=>ah<=dis1;
                     al<=dis7;
            when 16=>ah<=dis1;
                     al<=dis6;
            when 15=>ah<=dis1;
                     al<=dis5;
            when 14=>ah<=dis1;
                     al<=dis4;
            when 13=>ah<=dis1;
                     al<=dis3;
            when 12=>ah<=dis1;
                     al<=dis2;
            when 11=>ah<=dis1;
                     al<=dis1;
            when 10=>ah<=dis1;
                     al<=dis0;
            when 9=>ah<=dis0;
                    al<=dis9;
            when 8=>ah<=dis0;
                    al<=dis8;
            when 7=>ah<=dis0;
                    al<=dis7;
            when 6=>ah<=dis0;
                    al<=dis6;
            when 5=>ah<=dis0;
                    al<=dis5;
            when 4=>ah<=dis0;
                    al<=dis4;
            when 3=>ah<=dis0;
                    al<=dis3;
            when 2=>ah<=dis0;
                    al<=dis2;
            when 1=>ah<=dis0;
                    al<=dis1;
            when 0=>ah<=dis0;
                    al<=dis0;
          end case;--根据倒计时信号返回相应编码,送输出显示
        end if;
      end process sd8;
  end course;--程序结束

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -