请问一下verilog怎样写数码管显示?
3个回答
深圳市容大彩晶科技有限公司
2024-11-14 广告
2024-11-14 广告
广告机代理优选容大彩晶,深圳市容大彩晶科技有限公司自2007年成立伊始,一直专注于液晶商用显示产品的技术研发及产品服务。公司依托具有自主研发能力、创新高效的技术团队,打造出行业优质商用液晶显示设备。容大彩晶产品涵盖商用液晶显示、多媒体广告机...
点击进入详情页
本回答由深圳市容大彩晶科技有限公司提供
展开全部
分出两个输出端口,一个控制段码一个是位码控制,下面是个完整程序
//数码管恒定显示0到7
module seg2(clk,rst,dataout,en);
input clk,rst;
output wire [7:0] dataout;
output wire [7:0] en;
reg [15:0] cnt_scan;
reg [3:0] data4;
reg [7:0] dataout_xhdl1;
reg [7:0] en_xhdl;
assign dataout=dataout_xhdl1;
assign en=en_xhdl;
always@(posedge clk or negedge rst)
begin
if(rst==0)
cnt_scan<=16'b0; //清零
else
cnt_scan<=cnt_scan+1;
case(cnt_scan[15:13]) //数码管使能端
0:en_xhdl<=8'b11111110;
1:en_xhdl<=8'b11111101;
2:en_xhdl<=8'b11111011;
3:en_xhdl<=8'b11110111;
4:en_xhdl<=8'b11101111;
5:en_xhdl<=8'b11011111;
6:en_xhdl<=8'b10111111;
7:en_xhdl<=8'b01111111;
default:en_xhdl<=8'b11111110;
endcase
case(en_xhdl) //数码管对应到数字
8'b11111110:data4<=4'b0000;
8'b11111101:data4<=4'b0001;
8'b11111011:data4<=4'b0010;
8'b11110111:data4<=4'b0011;
8'b11101111:data4<=4'b0100;
8'b11011111:data4<=4'b0101;
8'b10111111:data4<=4'b0110;
8'b01111111:data4<=4'b0111;
default:data4<=4'b1000;
endcase
case(data4) //数码管显示数字
4'b0000:dataout_xhdl1<=8'b11000000;
4'b0001:dataout_xhdl1<=8'b11111001;
4'b0010:dataout_xhdl1<=8'b10100100;
4'b0011:dataout_xhdl1<=8'b10110000;
4'b0100:dataout_xhdl1<=8'b10011001;
4'b0101:dataout_xhdl1<=8'b10010010;
4'b0110:dataout_xhdl1<=8'b10000010;
4'b0111:dataout_xhdl1<=8'b11111000;
4'b1000:dataout_xhdl1<=8'b10000000;
4'b1001:dataout_xhdl1<=8'b00011001;
4'b1010:dataout_xhdl1<=8'b00010001;
4'b1011:dataout_xhdl1<=8'b11000001;
4'b1100:dataout_xhdl1<=8'b01100011;
4'b1101:dataout_xhdl1<=8'b10000101;
4'b1110:dataout_xhdl1<=8'b01100001;
4'b1111:dataout_xhdl1<=8'b01110001;
default:dataout_xhdl1<=8'b00000011;
endcase
end
endmodule
//数码管恒定显示0到7
module seg2(clk,rst,dataout,en);
input clk,rst;
output wire [7:0] dataout;
output wire [7:0] en;
reg [15:0] cnt_scan;
reg [3:0] data4;
reg [7:0] dataout_xhdl1;
reg [7:0] en_xhdl;
assign dataout=dataout_xhdl1;
assign en=en_xhdl;
always@(posedge clk or negedge rst)
begin
if(rst==0)
cnt_scan<=16'b0; //清零
else
cnt_scan<=cnt_scan+1;
case(cnt_scan[15:13]) //数码管使能端
0:en_xhdl<=8'b11111110;
1:en_xhdl<=8'b11111101;
2:en_xhdl<=8'b11111011;
3:en_xhdl<=8'b11110111;
4:en_xhdl<=8'b11101111;
5:en_xhdl<=8'b11011111;
6:en_xhdl<=8'b10111111;
7:en_xhdl<=8'b01111111;
default:en_xhdl<=8'b11111110;
endcase
case(en_xhdl) //数码管对应到数字
8'b11111110:data4<=4'b0000;
8'b11111101:data4<=4'b0001;
8'b11111011:data4<=4'b0010;
8'b11110111:data4<=4'b0011;
8'b11101111:data4<=4'b0100;
8'b11011111:data4<=4'b0101;
8'b10111111:data4<=4'b0110;
8'b01111111:data4<=4'b0111;
default:data4<=4'b1000;
endcase
case(data4) //数码管显示数字
4'b0000:dataout_xhdl1<=8'b11000000;
4'b0001:dataout_xhdl1<=8'b11111001;
4'b0010:dataout_xhdl1<=8'b10100100;
4'b0011:dataout_xhdl1<=8'b10110000;
4'b0100:dataout_xhdl1<=8'b10011001;
4'b0101:dataout_xhdl1<=8'b10010010;
4'b0110:dataout_xhdl1<=8'b10000010;
4'b0111:dataout_xhdl1<=8'b11111000;
4'b1000:dataout_xhdl1<=8'b10000000;
4'b1001:dataout_xhdl1<=8'b00011001;
4'b1010:dataout_xhdl1<=8'b00010001;
4'b1011:dataout_xhdl1<=8'b11000001;
4'b1100:dataout_xhdl1<=8'b01100011;
4'b1101:dataout_xhdl1<=8'b10000101;
4'b1110:dataout_xhdl1<=8'b01100001;
4'b1111:dataout_xhdl1<=8'b01110001;
default:dataout_xhdl1<=8'b00000011;
endcase
end
endmodule
追问
能不能把那几个寄存器解释一下呀
追答
en_xhdl控制那个数码管工作,dataout_xhdl是相应数码管的abcdefgp的控制,data4是显示0/1/2/3/4/5/6/7/8的控制
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
和单片机是相同的
这个是实现0~f的显示的,间隔为1s。共阳,晕,verilog的还没有写,目前只有vhdl的,思想是一样的。凑合一下吧。。。。
顶层文件
library ieee;
use ieee.std_logic_1164.all;
entity led_dis is
port(
clk : in std_logic;
rstN : in std_logic;
led_en : out std_logic;--位选
q : out std_logic_vector(7 downto 0)
);
end entity;
architecture behav of led_dis is
signal s1 : std_logic_vector(3 downto 0);
component M10
port(
clk : in std_logic;
rstN : in std_logic;
data : out std_logic_vector(3 downto 0)
);
end component;
component decoder
port(
datain : in std_logic_vector(3 downto 0);
dataout : out std_logic_vector(7 downto 0)
);
end component;
begin
led_en <= '1';
u1 : M10 port map(clk => clk, rstN => rstN, data => s1);
u2 : decoder port map(datain => s1, dataout => q);
end;
调用的,译码
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity decoder is
port(
datain : in std_logic_vector(3 downto 0);
dataout : out std_logic_vector(7 downto 0)
);
end decoder;
architecture behav of decoder is begin
process(datain) begin
case datain is
--CA
when "0000" => dataout <= x"c0";
when "0001" => dataout <= x"f9";
when "0010" => dataout <= x"a4";
when "0011" => dataout <= x"b0";
when "0100" => dataout <= x"99";
when "0101" => dataout <= x"92";
when "0110" => dataout <= x"82";
when "0111" => dataout <= x"f8";
when "1000" => dataout <= x"80";
when "1001" => dataout <= x"90";
when "1010" => dataout <= x"88";
when "1011" => dataout <= x"83";
when "1100" => dataout <= x"c6";
when "1101" => dataout <= x"11";
when "1110" => dataout <= x"86";
when "1111" => dataout <= x"8e";
when others => null;
--CC
--when "0000" => dataout <= x"3f";
--when "0001" => dataout <= x"06";
--when "0010" => dataout <= x"5b";
--when "0011" => dataout <= x"4f";
--when "0100" => dataout <= x"66";
--when "0101" => dataout <= x"6d";
--when "0110" => dataout <= x"7d";
--when "0111" => dataout <= x"07";
--when "1000" => dataout <= x"7f";
--when "1001" => dataout <= x"6f";
--when "1010" => dataout <= x"77";
--when "1011" => dataout <= x"7c";
--when "1100" => dataout <= x"39";
--when "1101" => dataout <= x"5e";
--when "1110" => dataout <= x"79";
--when "1111" => dataout <= x"71";
end case;
end process;
end architecture;
实现1s的计数的(就是单片机的延迟),间隔1s,加1
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity M10 is
port(
clk : in std_logic;
rstN : in std_logic;
data : out std_logic_vector(3 downto 0)
);
end entity;
architecture behav of M10 is
signal clk1 : std_logic;
begin
process(clk, rstN)
variable cnt500ms : std_logic_vector(24 downto 0);
begin
if rstN = '0' then
cnt500ms := "0000000000000000000000000";
clk1 <= '1';
else if rising_edge(clk) then
if(cnt500ms = "1011111010111100001000000") then
cnt500ms := "0000000000000000000000000";
clk1 <= not clk1;
else
cnt500ms := cnt500ms + 1;
end if;
end if;
end if;
end process;
process(clk1, rstN, clk)
variable reg : std_logic_vector(3 downto 0);
begin
if rstN = '0' then
reg := "0000";
else if rising_edge(clk1) then
if(reg = "1111") then
reg := "0000";
else
reg := reg + 1;
end if;
end if;
end if;
data <= reg;
end process;
end behav;
这个是实现0~f的显示的,间隔为1s。共阳,晕,verilog的还没有写,目前只有vhdl的,思想是一样的。凑合一下吧。。。。
顶层文件
library ieee;
use ieee.std_logic_1164.all;
entity led_dis is
port(
clk : in std_logic;
rstN : in std_logic;
led_en : out std_logic;--位选
q : out std_logic_vector(7 downto 0)
);
end entity;
architecture behav of led_dis is
signal s1 : std_logic_vector(3 downto 0);
component M10
port(
clk : in std_logic;
rstN : in std_logic;
data : out std_logic_vector(3 downto 0)
);
end component;
component decoder
port(
datain : in std_logic_vector(3 downto 0);
dataout : out std_logic_vector(7 downto 0)
);
end component;
begin
led_en <= '1';
u1 : M10 port map(clk => clk, rstN => rstN, data => s1);
u2 : decoder port map(datain => s1, dataout => q);
end;
调用的,译码
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity decoder is
port(
datain : in std_logic_vector(3 downto 0);
dataout : out std_logic_vector(7 downto 0)
);
end decoder;
architecture behav of decoder is begin
process(datain) begin
case datain is
--CA
when "0000" => dataout <= x"c0";
when "0001" => dataout <= x"f9";
when "0010" => dataout <= x"a4";
when "0011" => dataout <= x"b0";
when "0100" => dataout <= x"99";
when "0101" => dataout <= x"92";
when "0110" => dataout <= x"82";
when "0111" => dataout <= x"f8";
when "1000" => dataout <= x"80";
when "1001" => dataout <= x"90";
when "1010" => dataout <= x"88";
when "1011" => dataout <= x"83";
when "1100" => dataout <= x"c6";
when "1101" => dataout <= x"11";
when "1110" => dataout <= x"86";
when "1111" => dataout <= x"8e";
when others => null;
--CC
--when "0000" => dataout <= x"3f";
--when "0001" => dataout <= x"06";
--when "0010" => dataout <= x"5b";
--when "0011" => dataout <= x"4f";
--when "0100" => dataout <= x"66";
--when "0101" => dataout <= x"6d";
--when "0110" => dataout <= x"7d";
--when "0111" => dataout <= x"07";
--when "1000" => dataout <= x"7f";
--when "1001" => dataout <= x"6f";
--when "1010" => dataout <= x"77";
--when "1011" => dataout <= x"7c";
--when "1100" => dataout <= x"39";
--when "1101" => dataout <= x"5e";
--when "1110" => dataout <= x"79";
--when "1111" => dataout <= x"71";
end case;
end process;
end architecture;
实现1s的计数的(就是单片机的延迟),间隔1s,加1
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity M10 is
port(
clk : in std_logic;
rstN : in std_logic;
data : out std_logic_vector(3 downto 0)
);
end entity;
architecture behav of M10 is
signal clk1 : std_logic;
begin
process(clk, rstN)
variable cnt500ms : std_logic_vector(24 downto 0);
begin
if rstN = '0' then
cnt500ms := "0000000000000000000000000";
clk1 <= '1';
else if rising_edge(clk) then
if(cnt500ms = "1011111010111100001000000") then
cnt500ms := "0000000000000000000000000";
clk1 <= not clk1;
else
cnt500ms := cnt500ms + 1;
end if;
end if;
end if;
end process;
process(clk1, rstN, clk)
variable reg : std_logic_vector(3 downto 0);
begin
if rstN = '0' then
reg := "0000";
else if rising_edge(clk1) then
if(reg = "1111") then
reg := "0000";
else
reg := reg + 1;
end if;
end if;
end if;
data <= reg;
end process;
end behav;
追问
用verilog怎样写呀?
追答
直接一个output 的pin 使能一个数码管
然后写一个段码译码器,4输入8输出,例如(共阳),输入4'b0000(即“0”),输出8'hc0,这个值直接送到数码管就行了。。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询