-- ****************************************************************************** -- 温度采集与显示 -- ******************************************************************************* library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity temperature is port( clk:in std_logic; --50M时钟输入 rst_n:in std_logic; --复位信号输入 key_in:in std_logic; --按键信号输入 d:inout std_logic; --温度输入 en:out std_logic_vector(4 downto 0); --数码管片选 dataout:out std_logic_vector(7 downto 0);--数码管段选 bell_out:out std_logic --蜂鸣器输出 ); end entity; architecture one of temperature is signal tmp_data:std_logic_vector(9 downto 0); signal tmp:std_logic_vector(9 downto 0); signal tmp_final_ge:std_logic_vector(5 downto 0); signal tmp_final_xiaoshu:std_logic_vector(3 downto 0); signal cnt:integer range 0 to 75; signal num:integer range 0 to 90; signal d_reg,link_d,clk200k,clk1m,link_data,ab:std_logic; signal seg7_tmp:integer range 0 to 9; signal count2,count3,count4,count5:integer range 0 to 9; signal count1 :integer range 0 to 9; signal count :integer range 0 to 4; signal temp3:integer range 0 to 9999; signal temp4:integer range 0 to 999; signal temp5:integer range 0 to 99; signal temp1:integer range 0 to 99; signal scan_reg:std_logic_vector(4 downto 0); ---------------存储温度数据------------------------------------------- signal temperture_data1:std_logic_vector(9 downto 0); signal temperture_data2:std_logic_vector(9 downto 0); signal temperture_data3:std_logic_vector(9 downto 0); signal temperture_data4:std_logic_vector(9 downto 0); signal temperture_data5:std_logic_vector(9 downto 0); signal temperture_data6:std_logic_vector(9 downto 0); signal temperture_data7:std_logic_vector(9 downto 0); signal temperture_data8:std_logic_vector(9 downto 0); signal temperture_data9:std_logic_vector(9 downto 0); signal temperture_data10:std_logic_vector(9 downto 0); signal temperture_out:std_logic_vector(9 downto 0);--按键选择输出的存储的温度数据 component bell is port( clk:in std_logic; --50M时钟输入 reset_n:in std_logic; --复位信号输入 temperature:in std_logic_vector(3 downto 0); --最后一分钟信号输出 pwm_out:out std_logic --蜂鸣器驱动脉冲 ); end component; component key is port( clk:in std_logic; --50M时钟输入 reset_n:in std_logic; --复位信号输入 key:in std_logic; --按键信号输入 temperture_data1:in std_logic_vector(9 downto 0); --存储的10个温度信号输入 temperture_data2:in std_logic_vector(9 downto 0); temperture_data3:in std_logic_vector(9 downto 0); temperture_data4:in std_logic_vector(9 downto 0); temperture_data5:in std_logic_vector(9 downto 0); temperture_data6:in std_logic_vector(9 downto 0); temperture_data7:in std_logic_vector(9 downto 0); temperture_data8:in std_logic_vector(9 downto 0); temperture_data9:in std_logic_vector(9 downto 0); temperture_data10:in std_logic_vector(9 downto 0); temperture_out:out std_logic_vector(9 downto 0) ----经按键选择的温度数据输出,按住按键一秒输出一个 ); end component; begin tmp_final_ge<= tmp_data(9)&tmp_data(8)&tmp_data(7)&tmp_data(6)&tmp_data(5)&tmp_data(4) when key_in = '1' --当按键没有按下时,输出当前的温度 else temperture_out(9)&temperture_out(8)&temperture_out(7)&temperture_out(6)&temperture_out(5)&temperture_out(4); ----当按键按下时,输出存储的之前的温度,1秒输出一个温度 tmp_final_xiaoshu<= tmp_data(3)&tmp_data(2)&tmp_data(1)&tmp_data(0) when key_in = '1'--当按键没有按下时,输出当前的温度 else temperture_out(3)&temperture_out(2)&temperture_out(1)&temperture_out(0); --当按键按下时,输出存储的之前的温度,1秒输出一个温度 d<=d_reg when link_d='1' else 'Z'; tmp_data<=tmp when link_data<='1' else tmp_data; en<=scan_reg; -- //**************************************************************************************************** -- // 模块名称:分频模块,产生1M的时钟信号 -- // 功能描述: -- //**************************************************************************************************** process(clk) variable a:integer range 0 to 24; begin if clk'event and clk='1' then if a=24 then a:=0;clk1m<=not clk1m; else a:=a+1; end if; end if; end process; -- //**************************************************************************************************** -- // 模块名称:温度传感器数据采集模块 -- // 功能描述: -- //**************************************************************************************************** process(clk1m,num,cnt,d,tmp,temperture_data1,temperture_data2,temperture_data3,temperture_data4, temperture_data5,temperture_data6,temperture_data7, temperture_data8,temperture_data9,temperture_data10) begin if clk1m'event and clk1m='1' then -- if(key_in = '1')then--按键没有按下的情况下才进行采集温度数据,按下则输出之前10个温度数据,不进行采集 if num=90 then num<=0; if cnt=75 then cnt<=0; else cnt<=cnt+1; end if; else num<=num+1; end if; ---------------------rst脉冲-------------------------7 if (cnt>=0 and cnt<=6) then d_reg<='0';link_d<='1'; ---------------------present pulse-------------------等待应答 7 elsif (cnt>=7 and cnt<=13) then link_d<='0'; ---------------------skip rom------------------------8 elsif (cnt=14 or cnt=15 or cnt=18 or cnt=19) then -----写0 if (num>=0 and num<66) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; elsif (cnt=16 or cnt=17 or cnt=20 or cnt=21) then -----写1 if (num>=0 and num<10) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; ---------------------convert t-----------------------8 elsif (cnt=22 or cnt=23 or cnt=25 or cnt=26 or cnt=27 or cnt=29) then --------写0 if (num>=0 and num<66) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; elsif (cnt=24 or cnt=28) then --------写1 if (num>=0 and num<10) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; ---------------------reset pulse---------------------7 elsif (cnt>=30 and cnt<=36) then d_reg<='0';link_d<='1'; ----------------------presence-----------------------7 elsif (cnt>=37 and cnt<=43) then link_d<='0'; ----------------------skip rom-----------------------8 elsif (cnt=44 or cnt=45 or cnt=48 or cnt=49) then if (num>=0 and num<66) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; elsif (cnt=46 or cnt=47 or cnt=50 or cnt=51) then if (num>=0 and num<10) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; ----------------------read scratchpad-----------------8 elsif (cnt=52 or cnt=58) then if (num>=0 and num<66) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; elsif (cnt=53 or cnt=54 or cnt=55 or cnt=56 or cnt=57 or cnt=59) then if (num>=0 and num<10) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; -----------------------读取温度数据----------------------10 elsif cnt=60 then if (num>=0 and num<5) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; if num=13 then tmp(0)<=d; ----------0 end if; elsif cnt=61 then if (num>=0 and num<5) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; if num=13 then tmp(1)<=d; ---------1 end if; elsif cnt=62 then if (num>=0 and num<5) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; if num=13 then tmp(2)<=d; ----------2 end if; elsif cnt=63 then if (num>=0 and num<5) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; if num=13 then tmp(3)<=d; ---------3 end if; elsif cnt=64 then if (num>=0 and num<5) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; if num=13 then tmp(4)<=d; ---------4 end if; elsif cnt=65 then if (num>=0 and num<5) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; if num=13 then tmp(5)<=d; ------------5 end if; elsif cnt=66 then if (num>=0 and num<5) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; if num=13 then tmp(6)<=d; -----------6 end if; elsif cnt=67 then if (num>=0 and num<5) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; if num=13 then tmp(7)<=d; ------------7 end if; elsif cnt=68 then if (num>=0 and num<5) then d_reg<='0';link_d<='1'; else link_d<='0'; end if; if num=13 then tmp(8)<=d; --------------8 end if; elsif cnt=69 then if (num>=0 and num<5) then d_reg<='0';link_d<='1'; elsif num=15 then link_data<='1'; else link_d<='0';link_data<='0'; end if; if num=13 then tmp(9)<=d; ------------9 temperture_data1 <= tmp;-------------依次存储10个温度数据 temperture_data2 <= temperture_data1; temperture_data3 <= temperture_data2; temperture_data4 <= temperture_data3; temperture_data5 <= temperture_data4; temperture_data6 <= temperture_data5; temperture_data7 <= temperture_data6; temperture_data8 <= temperture_data7; temperture_data9 <= temperture_data8; temperture_data10 <= temperture_data9; end if; else link_d<='0';link_data<='0'; end if; end if; -- end if; end process; -- //**************************************************************************************************** -- // 模块名称:分频模块,产生10K的时钟信号 -- // 功能描述:用于数码管的位扫描信号clk200k,实为10K -- //**************************************************************************************************** --------------------数码管扫描CLK3 process(clk) variable a : integer range 0 to 2499; begin if clk'event and clk='1' then if a=2499 then a:=0;clk200k<=not clk200k; else a:=a+1; end if; end if; end process;
链接:https://pan.baidu.com/s/1V7q_UGv2gJ9rbNJY00Iqfw
提取码:1234
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)