1.消抖电路:2.分频器:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fpq isport (clk: in std_logic;f50k:buffer std_logic:='0';f1k:buffer std_logic;f5k:buffer std_logic;f2k:buffer std_logic;f100hz:buffer std_logic;f2hz:buffer std_logic;f1s:buffer std_logic;f6s:buffer std_logic:='1');end fpq;architecture one of fpq issignal count_6s,count_100: std_logic_vector(3 downto 0);signalcount_1m,count_1s,count_05s,count_1k,cou nt_2k,count_5k: std_logic_vector(8 downto 0); signal count_hec:std_logic_vector(9 downto 0);signal fpq_hec:std_logic_vector(9 downto 0); Begin--50khzprocess(clk)beginif(clk'event and clk='1')thenif(count_1m="011111001")then--500分频(系统时钟25MHz)count_1m<="000000000";f50k<=not f50k;elsecount_1m<=count_1m+1;end if;end if;end process;--5Khzprocess(f50k)beginif(f50k'event and f50k='1')thenif(count_5k="00000100")then--10分频count_5k<="000000000";f5k<=not f5k;elsecount_5k<=count_5k+1;end if;end if;end process;--1khzprocess(f50k)beginif(f50k'event and f50k='1')thenif(count_1k="00011000")then--50分频count_1k<="000000000";f1k<=not f1k;elsecount_1k<=count_1k+1;end if;end if;end process;--2.5khzprocess(f50k)beginif(f50k'event and f50k='1')thenif(count_2k="00001001")then--20分频count_2k<="000000000";f2k<=not f2k;elsecount_2k<=count_2k+1;end if;end if;end process;--100hzprocess(f1k)beginif(f1k'event and f1k='1')thenif(count_100="0100")then--10分频count_100<="0000";f100hz<=not f100hz;elsecount_100<=count_100+1;end if;end if;end process;--2hz process(f1k)beginif(f1k'event and f1k='1')thenif(count_05s="011111001")then--500分频count_05s<="000000000";f2hz<=not f2hz;elsecount_05s<=count_05s+1;end if;end if;end process;--1hzprocess(f1k)beginif(f1k'event and f1k='1')thenif(count_1s="111110100")then--1000分频count_1s<="000000000";f1s<=not f1s;elsecount_1s<=count_1s+1;end if;end if;end process;--6sprocess(f1s)beginif(f1s'event and f1s='1')thenif(count_6s="0101")thenf6s<='0';count_6s<=count_6s+1;elsif(count_6s="0110")thenf6s<='1';count_6s<="0000";elsecount_6s<=count_6s+1;f6s<='1';end if;end if;end process;end one;3.计数器:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity jsq isPort(jsq_clk,jsq_clr: in std_logic;jsq_h_loc: buffer std_logic_vector (3 downto 0); --高位jsq_l_loc: buffer std_logic_vector (3 downto 0); --低位jsq_situ: buffer std_logic_vector (1 downto 0)); --状态end jsq;architecture one of jsq issignal jsq_h,jsq_l: std_logic_vector(3 downto 0);signal jsqet_h,jsqet_l: std_logic_vector(3 downto 0);beginprocess(jsq_clk,jsq_clr)beginif(jsq_clr='0')then --计数,同步复位jsq_h<="0000"; jsq_l<="0000";elsif(jsq_clk'event and jsq_clk='1')thenif(jsq_l="0000"and jsq_h="0010" ) thenjsq_l<="0000";jsq_h<="0010";elsif(jsq_l="1001" and jsq_h<"0010")thenjsq_l<="0000";jsq_h<=jsq_h+1;elsejsq_l<=jsq_l+1;end if;end if;--比较状态if(jsq_h_loc>"0001") then --心率过速jsq_situ<="11";elsif(jsq_h_loc="0000" and jsq_l_loc<"0110") then --心率过缓jsq_situ<="01";elsif(jsq_h_loc="0000" and jsq_l_loc="0000") then --心跳停止jsq_situ<="00";elsejsq_situ<="10"; --正常心率end if;end process;process(jsq_clr,jsq_l,jsq_h)beginif(jsq_clr'event and jsq_clr='0')thenjsq_h_loc<=jsq_h;jsq_l_loc<=jsq_l;end if;end process;end one;4.蜂鸣器:library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity fmq isPort (fmq_situ:in std_logic_vector (1 downto 0);fmq_1k,fmq_05s,fmq_2k,fmq_5k,fmq_100,fmq_heart: in std_logic; fmq_show,fmq_bee:buffer std_logic);end fmq;architecture one of fmq isbeginprocess(fmq_1k,fmq_2k,fmq_5k,fmq_show,fmq_bee)beginif(fmq_situ="00")then --心跳停止,连续报警,闪动显示if(fmq_100='1'and fmq_heart='0')thenfmq_bee<='0';elsefmq_bee<='1';end if;if(fmq_05s='1')thenfmq_show<='0';elsefmq_show<='1';end if;elsif(fmq_situ="10")thenif(fmq_heart='1'and fmq_2k='1')then --正常心率,非闪动显示,同步声响fmq_bee<='0';elsefmq_bee<='1';end if;fmq_show<='0';elsif(fmq_situ="01")thenif(fmq_05s='1'and fmq_1k='1')then --心率过缓,闪动显示,间隔报警fmq_bee<='0';elsefmq_bee<='1';end if;if(fmq_05s='1')thenfmq_show<='0';else fmq_show<='1';end if;elsif(fmq_situ="11")thenif(fmq_05s='1'and fmq_5k='1')then --心率过速,闪动显示,间隔报警fmq_bee<='0';elsefmq_bee<='1';end if;if(fmq_05s='1')thenfmq_show<='0';elsefmq_show<='1';end if;end if;end process;end one;5.寄存器:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity jcq isPort (h: in std_logic_vector (3 downto 0);l: in std_logic_vector (3 downto 0);jcq_situ:in std_logic_vector (1 downto 0);jcq_clk: in std_logic;el: buffer std_logic_vector (3 downto 0);eh: buffer std_logic_vector (3 downto 0);th: buffer std_logic_vector (3 downto 0);tl: buffer std_logic_vector (3 downto 0));end jcq;architecture one of jcq issignal hertet_h,hertet_l: std_logic_vector(3 downto 0);beginprocess(jcq_situ,h,l,el,eh)beginif(jcq_clk'event and jcq_clk='1')thenif(jcq_situ/="10")then --不正常心率eh<=h;el<=l;hertet_l<="0110";hertet_h<="0000";end if;end if;end process;process(jcq_clk,hertet_l,hertet_h ) --不正常心率时间beginif(jcq_clk'event and jcq_clk='1')thenth<=hertet_h; tl<=hertet_l;end if;end process;end one;6.查询器:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cxq isPort (nowh,nowl,eh,el,th,tl:in std_logic_vector (3 downto 0);oh,om,ol:out std_logic_vector (3 downto 0);chaxun,clk:in std_logic);end cxq;architecture one of cxq issignal disply: std_logic_vector(1 downto 0);signal count:std_logic_vector(3 downto 0):="1000";signal flg:std_logic;beginprocess(chaxun,clk)beginif(chaxun='0')thencount<="0000";elsif(clk'event and clk='1')thenif(count="1111")thencount<=count;elsecount<=count+1;end if;end if;end process;process(nowh,nowl,eh,el,th,tl,disply)beginif(count>"0110")then --6s之后恢复检测功能oh<=nowh;om<=nowl;ol<="0000";elsif(count<"0011")then --显示不正常心率3soh<=eh;om<=el;ol<="0000";else --显示不正常心率时间3soh<="0000";om<=th;ol<=tl;end if;end process;end one;7.显示器:library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity xsq isPORT (clk ,flag,show : IN std_logic;high_bit :in std_logic_vector(3 downto 0);middle_bit :in std_logic_vector(3 downto 0);low_bit :in std_logic_vector(3 downto 0);en : out std_logic_vector(2 DOWNTO 0);dataout : out std_logic_vector(7 DOWNTO 0));end xsq;architecture arch of xsq issignal dataout8 : std_logic_vector(7 downto 0);signal en3 : std_logic_vector(2 downto 0):="001"; signal data4 : std_logic_vector(3 downto 0);begindataout<=dataout8;en<=en3;process(clk)beginif(show='1')thenen3<="000";elsif( flag = '1' and flag'event) then --片(段)选if(en3="001")thenen3<="010";elsif(en3="010")thenen3<="100";elsif(en3="100")thenen3<="001";elsif(en3="000")thenen3<="001";end if;end if;end process;process(clk)beginif( clk = '1' and clk'event) then --位选(数码管) if(en3="100") thendata4<=low_bit;elsif(en3="010") thendata4<=middle_bit;elsif(en3="001")thendata4<=high_bit;end if;end if;end process;process(data4)begincase data4 isWHEN "0000" =>dataout8 <= "00000011";WHEN "0001" =>dataout8 <= "10011111";WHEN "0010" =>dataout8 <= "00100101";WHEN "0011" =>dataout8 <= "00001101";WHEN "0100" =>dataout8 <= "10011001";WHEN "0101" =>dataout8 <= "01001001";WHEN "0110" =>dataout8 <= "11000001";WHEN "0111" =>dataout8 <= "00011111";WHEN "1000" =>dataout8 <= "00000001";WHEN "1001" =>dataout8 <= "00011001";WHEN "1010" =>dataout8 <= "00100000";WHEN "1011" =>dataout8 <= "01100010";WHEN "1100" =>dataout8 <= "10000010";WHEN "1101" =>dataout8 <= "10000010";WHEN "1110" =>dataout8 <= "00100001";WHEN "1111" =>dataout8 <= "01110000";WHEN OTHERS =>dataout8 <= "11111111";END CASE;END PROCESS;end arch;。