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

📄 dig_scan.vhd

📁 将AD采样的八位比特转化为十进制数值大小
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all; 
use ieee.std_logic_unsigned.all;

entity dig_scan is 
	port(clk :in std_logic;
		dat_input :in std_logic_vector(7 downto 0);	--数据输入
		cat_choice : out std_logic_vector(5 downto 0);		--数码管选择
		segout : out std_logic_vector(6 downto 0);	--7段BCD
		decimal :out std_logic				--小数点
		);
	end dig_scan;
	
architecture behave of dig_scan is
	signal clk_scan:std_logic;
	signal dat: std_logic_vector(7 downto 0);		--数据输入
	signal cat : std_logic_vector(5 downto 0);  --选择6个数码管
	signal t_segout : std_logic_vector(6 downto 0);  --7段数码管
	signal t_decimal: std_logic;
	signal count1:integer range 0 to 9999;
	signal count2:integer range 0 to 5;
	--signal conv_num: std_logic_vector(5 downto 0);
	--signal number:integer;
	signal num,num1,num2,num3:integer range 0 to 9;	----修改
	
	
begin 
		--分频--
	process(clk)
	begin 
	if clk'event and clk='1' then 
		if count1=9999 then
			count1<=0;
			clk_scan<=not clk_scan;
		else count1<=count1+1;
		end if;
	end if;
	--------------------
	end process;
	dat<=dat_input;
	process(clk_scan)
		variable x,y,z:integer;	
	
	begin
		
		--算法--修改
	x:=conv_integer(dat(7))*8+conv_integer(dat(6))*4+conv_integer(dat(5))*2+conv_integer(dat(4))*6
			+conv_integer(dat(3))*8+conv_integer(dat(2))*4+conv_integer(dat(1))*2+conv_integer(dat(0));
	num1<=x-x/10*10;
	y:=conv_integer(dat(7))*2+conv_integer(dat(6))*6+conv_integer(dat(5))*3+conv_integer(dat(4))*1
			+x/10;
	num2<=y-y/10;
	z:=conv_integer(dat(7))+y/10;
	num3<=z+z/10;
	-------------------------------------------------------------------------------------------------------------------------
	
	if(clk_scan'event and clk_scan='1')then
			if count2=5 then 
				count2<=0;
			else count2<=count2+1;
			end if;
		----------------模板----------修改-----------小数点还没有处理好!
			case count2 is			
				when 0 =>cat<="011111";num<=4;			--第一位disp5数码管显示---最高位---cat0---pin63
		        when 1 =>cat<="101111";num<=5;			--第二位disp4数码管显示 		---cat5---pin70
	            when 2 =>cat<="110111";num<=6;			--第三位disp5数码管显示---		---cat4---pin69
	            when 3 =>cat<="111011";num<=num3;
	            when 4 =>cat<="111101";num<=num2;t_decimal<='1';
		        when 5 =>cat<="111110";num<=num1;		--最低位				-----------cat1---pin66
			    when others  =>cat<="111111";
			end case;
		--------------------------------------------------------------
			case num is
				when 0 =>t_segout<="0111111";		--gfedcba
				when 1 =>t_segout<="0000110";
				when 2 =>t_segout<="1011011";
				when 3 =>t_segout<="1001111";
				when 4 =>t_segout<="1100110";
				when 5 =>t_segout<="1101101";
				when 6 =>t_segout<="1111101";
				when 7 =>t_segout<="0000111";
				when 8 =>t_segout<="1111111";
				when 9 =>t_segout<="1101111";
				when others=>t_segout<="0000000";
			end case;
	end if;
	segout<=t_segout;
	cat_choice<=cat;
	decimal<=t_decimal;
	end process;
end;

⌨️ 快捷键说明

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