VHDL实现智能药盒

Posted hhh江月

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VHDL实现智能药盒相关的知识,希望对你有一定的参考价值。

VHDL实现智能药盒

一、简介

我们这篇文章接着上一篇文章:
https://hyxmoon.blog.csdn.net/article/details/121726857

来继续实现智能药盒,这里只不过是换了一个板子,换了一种语言而已。

二、代码

LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;

ENTITY yaohe_jichu IS
PORT(BTN0,BTN1,BTN2:IN STD_LOGIC;
BTN3:IN STD_LOGIC;
CLK:IN STD_LOGIC;
ROW_OUT : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
RED_OUT : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
GRN_OUT : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
LED_OUT : OUT STD_LOGIC_VECTOR(5 DOWNTO 0);
FMQ : OUT STD_LOGIC;
btn_row:out std_logic_vector(3 downto 0);
row0:in std_logic_vector(3 downto 0);
disp_seg:out std_logic_vector(6 downto 0);
disp_cat:out std_logic_vector(7 downto 0);
switch1:in std_logic
);

END yaohe_jichu;

ARCHITECTURE ACT OF yaohe_jichu IS
SIGNAL CONT,CONT_1:INTEGER RANGE 0 TO 3;
signal BTN1_I,BTN0_I,BTN2_I,BTN3_I,resetmp3,resetmp4,resetmp5,resetmp6,resetmp7,resetmp8,resetmp9,resetmp10,CLK_10,CLK_60,CLK_5:STD_LOGIC;
SIGNAL NUM_2 : INTEGER RANGE 0 TO 59;SIGNAL NUM_3 : INTEGER RANGE 0 TO 7;
SIGNAL NUM_4,OC,COD,COC,change : INTEGER RANGE 0 TO 1;
SIGNAL TMP_1:INTEGER RANGE 0 TO 49999;
SIGNAL TMP_2:INTEGER RANGE 0 TO 24999999;
SIGNAL TMP_3:INTEGER RANGE 0 TO 12499999;
signal scan: std_logic_vector(1 downto 0);
signal tmp: integer range 0 to 49999;
signal deshake1: integer range 0 to 99;
signal deshake2: integer range 0 to 99;
signal deshake3: integer range 0 to 99;
signal clktmp,OP: std_logic;
signal clk_out: std_logic;
signal number: std_logic_vector(3 downto 0);
signal number1: std_logic_vector(3 downto 0);
signal number1_IN_1: std_logic_vector(3 downto 0);
signal number1_IN_2: std_logic_vector(3 downto 0);
signal number2: std_logic_vector(3 downto 0);
signal number2_IN_1: std_logic_vector(3 downto 0);
signal number2_IN_2: std_logic_vector(3 downto 0);
signal number3: std_logic_vector(3 downto 0);
signal number3_IN_1: std_logic_vector(3 downto 0);
signal number3_IN_2: std_logic_vector(3 downto 0);
signal number1_OUT: std_logic_vector(3 downto 0);
signal number2_OUT: std_logic_vector(3 downto 0);
signal number1_OUT_O: std_logic_vector(3 downto 0);
signal number2_OUT_O: std_logic_vector(3 downto 0);
signal number4: std_logic_vector(3 downto 0);
signal number5: std_logic_vector(3 downto 0);
signal number6: std_logic_vector(3 downto 0);
signal COMB_1: std_logic_vector(3 downto 0);
signal COMB_2: std_logic_vector(3 downto 0);
signal col0: std_logic_vector(3 downto 0);

--button3--

signal feeding_medicine: STD_LOGIC:='0';
signal feeding_medicine0: STD_LOGIC:='0';
signal position:INTEGER RANGE 0 TO 3;--position.

--判断是否吃药了--
--initial is 0
--if needed to take medicine, then set the number to 1
--if taken the medicine, then set the number to 0 again.


BEGIN

PROCESS(CLK) 
BEGIN
IF CLK'EVENT AND CLK = '1'THEN
  IF TMP_2 = 24999999 THEN TMP_2 <= 0;
     CLK_60 <= NOT CLK_60;
  ELSE TMP_2 <= TMP_2 + 1;
  END IF;
END IF;
END PROCESS;

PROCESS(CLK) --button0--
BEGIN
IF BTN0_I'EVENT AND BTN0_I='1'THEN
OP<=NOT OP;
END IF;
END PROCESS;

PROCESS(CLK_5) --数码管输出值总设定--
BEGIN
IF OP ='1'THEN
IF CONT = 0 THEN number1_OUT_O<=number1_OUT;number2_OUT_O<=number2_OUT;
ELSE
IF CLK_5='1'THEN
number1_OUT_O<=number1_OUT;number2_OUT_O<=number2_OUT;
ELSE number1_OUT_O<="1111";number2_OUT_O<="1111";
END IF;
END IF;
IF OC=1 THEN
number1_OUT_O<=COMB_2;
number2_OUT_O<=COMB_1;
ELSE NULL;
END IF;
ELSE number1_OUT_O<="0000";number2_OUT_O<="0000";
END IF;
END PROCESS;

PROCESS(CLK_10) --button1设定时数码管显示--
BEGIN
IF OP = '1'THEN
IF CONT = 0 THEN number1_OUT<="1111";number2_OUT<="1111";
ELSIF CONT = 1 THEN number1_OUT<=number1_IN_1;number2_OUT<=number1_IN_2;
ELSIF CONT = 2 THEN number1_OUT<=number2_IN_1;number2_OUT<=number2_IN_2;
ELSIF CONT = 3 THEN number1_OUT<=number3_IN_1;number2_OUT<=number3_IN_2;
END IF;
ELSE number1_OUT<="0000";number2_OUT<="0000";
END IF;
END PROCESS;

PROCESS(CLK_10) --3*2个数码管输出值赋值--
BEGIN
IF OP ='1'THEN
IF CONT = 1 THEN
number1_IN_1<=number1;number1_IN_2<=number2;
END IF;
ELSE number1_IN_1<="0000";number1_IN_2<="0000";
END IF;
END PROCESS;
PROCESS(CLK_10)
BEGIN
IF OP ='1'THEN
IF CONT = 2 THEN
number2_IN_1<=number3;number2_IN_2<=number4;
END IF;
ELSE number2_IN_1<="0000";number2_IN_2<="0000";
END IF;
END PROCESS;
PROCESS(CLK_10)
BEGIN
IF OP ='1'THEN
IF CONT = 3 THEN
number3_IN_1<=number5;number3_IN_2<=number6;
END IF;
ELSE number3_IN_1<="0000";number3_IN_2<="0000";
END IF;
END PROCESS;

p1: PROCESS(CLK)--三个分频器--
BEGIN
IF CLK'EVENT AND CLK = '1'THEN
  IF TMP_3 = 12499999 THEN TMP_3 <= 0;
     CLK_5 <= NOT CLK_5;
  ELSE TMP_3 <= TMP_3 + 1;
  END IF;
END IF;
END PROCESS p1;

p2:process(clk)
	begin
		if clk'event and clk='1'then
			if tmp=24999 then
				tmp<=0;clktmp<=not clktmp;
			else
				tmp<=tmp + 1;
			end if;
		else 
			null;
		end if;
	end process p2;
clk_out<=clktmp;

p3: PROCESS(CLK_10)
BEGIN
IF CLK_10'event and CLK_10 = '1' THEN
  IF NUM_3 = 7 THEN 
    NUM_3 <= 0;
  ELSE NUM_3 <= NUM_3 + 1;
  END IF;
END IF;
END PROCESS p3;

PROCESS(CLK_10) --2个数码管的显示扫描--
BEGIN
IF CLK_10'event and CLK_10 = '1' THEN
  IF NUM_4 = 1 THEN 
    NUM_4 <= 0;
  ELSE NUM_4 <= NUM_4 + 1;
  END IF;
END IF;
END PROCESS;

PROCESS(CLK)
BEGIN
IF CLK'EVENT AND CLK = '1'THEN
  IF TMP_1 = 49999 THEN TMP_1 <= 0;
     CLK_10 <= NOT CLK_10;
  ELSE TMP_1 <= TMP_1 + 1;
  END IF;
END IF;
END PROCESS;

p00:process(CLK_10)--4个button的消抖--
    begin
       if(CLK_10'event and CLK_10 = '0') then
           resetmp10 <= resetmp9;
           resetmp9 <= BTN0;
       end if;
   end process p00;
BTN0_I <= CLK_10 AND resetmp9 AND (NOT resetmp10);

p01: process(CLK_10)
    begin
       if(CLK_10'event and CLK_10 = '0') then
           resetmp8 <= resetmp7;
           resetmp7 <= BTN1;
       end if;
   end process p01;
BTN1_I <= CLK_10 AND resetmp7 AND (NOT resetmp8);

p02:process(CLK_10)
    begin
       if(CLK_10'event and CLK_10 = '0') then
           resetmp6 <= resetmp5;
           resetmp5 <= BTN2;
       end if;
   end process p02;
BTN2_I <= CLK_10 AND resetmp5 AND (NOT resetmp6);

p03:process(CLK_10)
    begin
       if(CLK_10'event and CLK_10 = '0') then
           resetmp4 <= resetmp3;
           resetmp3 <= BTN3;
       end if;
   end process p03;
BTN3_I <= CLK_10 AND resetmp3 AND (NOT resetmp4);

process(clk) --设定键button1--
begin
IF OP = '1'THEN
IF BTN1_I'EVENT AND BTN1_I='1'THEN
  IF CONT= 3 THEN CONT<=0;
  ELSE CONT<=CONT+1;
  END IF;
END IF;
ELSIF OP = '0'THEN CONT<=0;
END IF;
END PROCESS;

-- button3 --
process(clk)
begin
	if OC=1 and feeding_medicine='1' then
		IF BTN3_I'EVENT AND BTN3_I='1'THEN	
				feeding_medicine0<='1';
		END IF;
	else
		feeding_medicine0<='0';
	end if;
end process;

PROCESS(clk) --工作时时间判断--
BEGIN


--IF OP ='1'THEN
IF COC = 1 THEN
CONT_1<=0;
ELSE
IF OC=0 THEN
CONT_1<=CONT;
ELSE
if OC=1 then
  if number1_IN_1=comb_2 and number1_IN_2=comb_1  then
  FMQ<=clk_10;
  cont_1<=1;
  position<=1;
  feeding_medicine<='1';
  elsif number2_IN_1=comb_2 and number2_IN_2=comb_1 then
  FMQ<=clk_10;
  cont_1<=2;
  position<=2;
  feeding_medicine<='1';
  elsif number3_IN_1=comb_2 and number3_IN_2=comb_1 then
  FMQ<=clk_10;
  cont_1<=3;
  position<=3;
  feeding_medicine<='1';
--  else  null;
else
  --position<=position;
  IF BTN3_I'EVENT AND BTN3_I='1'THEN	
			feeding_medicine<='0';	
		END IF;
  
  if feeding_medicine='1'  then
	if position=1 then
		cont_1<=1;
		FMQ<=clk_10;		
	elsif position=2 then
		cont_1<=2;
		FMQ<=clk_10;		
	elsif position=3 then
		cont_1<=3;
		FMQ<=clk_10;
	else cont_1<=0;
	end if;
else
	cont_1<=0;
end if;
  
  end if;
  
  ELSE NULL;
end if;
END IF;
END IF;
--ELSE CONT_1<=0;
--END IF;
end process;

process(clk)
begin
IF OP = '1'THEN
IF BTN2_I'EVENT AND BTN2_I='1'THEN
IF OC=1 THEN OC<=0;
ELSE OC<=OC+1;
END IF;
END IF;
ELSE OC<=0;
END IF;
end process;


PROCESS(CLK_10) --点阵闪烁--
BEGIN
IF OP = '1'THEN
CASE CONT_1 IS
  WHEN 0 =>
    CASE NUM_3 IS
      WHEN 0 => ROW_OUT <= "01111111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 1 => ROW_OUT <= "10111111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 2 => ROW_OUT <= "11011111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 3 => ROW_OUT <= "11101111";RED_OUT <= "11000011";GRN_OUT<="00011011";
      WHEN 4 => ROW_OUT <= "11110111";RED_OUT <= "11000011";GRN_OUT<="00011011";
      WHEN 5 => ROW_OUT <= "11111011";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 6 => ROW_OUT <= "11111101";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 7 => ROW_OUT <= "11111110";RED_OUT <= "00000000";GRN_OUT<="00000000";
    END CASE;
    
  WHEN 1 =>
  IF CLK_5='1'THEN
    CASE NUM_3 IS
      WHEN 0 => ROW_OUT <= "01111111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 1 => ROW_OUT <= "10111111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 2 => ROW_OUT <= "11011111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 3 => ROW_OUT <= "11101111";RED_OUT <= "11000011";GRN_OUT<="00011011";
      WHEN 4 => ROW_OUT <= "11110111";RED_OUT <= "11000011";GRN_OUT<="00011011";
      WHEN 5 => ROW_OUT <= "11111011";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 6 => ROW_OUT <= "11111101";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 7 => ROW_OUT <= "11111110";RED_OUT <= "00000000";GRN_OUT<="00000000";
    END CASE;
   ELSE 
      CASE NUM_3 IS
      WHEN 0 => ROW_OUT <= "01111111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 1 => ROW_OUT <= "10111111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 2 => ROW_OUT <= "11011111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 3 => ROW_OUT <= "11101111";RED_OUT <= "00000011";GRN_OUT<="00011011";
      WHEN 4 => ROW_OUT <= "11110111";RED_OUT <= "00000011";GRN_OUT<="00011011";
      WHEN 5 => ROW_OUT <= "11111011";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 6 => ROW_OUT <= "11111101";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 7 => ROW_OUT <= "11111110";RED_OUT <= "00000000";GRN_OUT<="00000000";
    END CASE;
    END IF;
  WHEN 2 =>
  IF CLK_5='1'THEN
    CASE NUM_3 IS
      WHEN 0 => ROW_OUT <= "01111111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 1 => ROW_OUT <= "10111111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 2 => ROW_OUT <= "11011111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 3 => ROW_OUT <= "11101111";RED_OUT <= "11000011";GRN_OUT<="00011011";
      WHEN 4 => ROW_OUT <= "11110111";RED_OUT <= "11000011";GRN_OUT<="00011011";
      WHEN 5 => ROW_OUT <= "11111011";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 6 => ROW_OUT <= "11111101";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 7 => ROW_OUT <= "11111110";RED_OUT <= "00000000";GRN_OUT<="00000000";
    END CASE;
   ELSE 
      CASE NUM_3 IS
      WHEN 0 => ROW_OUT <= "01111111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 1 => ROW_OUT <= "10111111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 2 => ROW_OUT <= "11011111";RED_OUT <= "00000000";GRN_OUT<="00000000";
      WHEN 3 => ROW_OUT <= "11101111";RED_OUT <= "11000011";GRN_OUT<="00000011";
      WHEN 4 => ROW_OUT <= "11110111";RED_OUT <= "11000011";GRN_OUT<="00000011";
      WHEN 5 => ROW_OUT <= "11111011"Verilog HDL实现智能药盒

Verilog HDL实现智能药盒

11基于STM32的智能药盒

STM32单片机智能蓝牙APP定时开关插座喂食器药盒

电梯控制系统基于VHDL语言和状态机实现的电梯控制系统的设计,使用了状态机

vhdl中怎么实现多行注释掉,就是暂时不用那一块