静态数码管

一.数码管

1.数码管介绍

  • 数码管分为7段数码管和8段数码管,其区别在于是否有小数点位。其本质是led点亮,则该段点亮。

2.数码管原理图

在这里插入图片描述

3.连接方式

3.1共阴极

  • 值为1则亮,值为0则灭。

3.2共阳极

  • 值为0则亮,值为1则灭。EP4CE6F17C8使用的就是共阳极

3.3共阳极真值表

字形赋值
011000000
111111001
210100100
310110000
410011001
510010010
610000010
711111000
810000000
910010000
A10001000
B10000011
C11000110
D10100001
E10000110
F10001110

二.实验

1.实验任务

  • 6个数码管每隔1s同时循环显示从0-F

2.模块图

在这里插入图片描述

3.代码

  • time_count
/**************************************功能介绍***********************************
Date	: 2023年7月29日15:34:16
Author	: Alegg xy.
Version	: 2.0
Description: 计时1s模块
*********************************************************************************/
    
//---------<模块及端口声名>------------------------------------------------------
module time_count( 
    input				clk		,
    input				rst_n	,

    output	reg	    	flag	 //计满1s标志
);								 
//---------<参数定义>--------------------------------------------------------- 
    parameter MAX_TIME = 26'd50_000_000;
//---------<内部信号定义>-----------------------------------------------------
    reg			[25:0]	cnt	   	;
    wire				add_cnt	;
    wire				end_cnt	;
    
    //1s计数器
    always @(posedge clk or negedge rst_n)begin 
       if(!rst_n)begin
            cnt <= 25'd0;
        end 
        else if(add_cnt)begin 
            if(end_cnt)begin 
                cnt <= 25'd0;
            end
            else begin 
                cnt <= cnt + 1'b1;
            end 
        end
    end 
    
    assign add_cnt = 1'b1;
    assign end_cnt = add_cnt && cnt == MAX_TIME - 1'd1;
    
    //flag信号定义,1为计满
    always @(posedge clk or negedge rst_n)begin 
        if(!rst_n)begin
            flag <= 1'b0;
        end 
        else if(end_cnt)begin 
            flag <= 1'b1;
        end 
        else begin 
            flag <= 1'b0;
        end 
    end
    
    
endmodule
  • static_seg
/**************************************功能介绍***********************************
Date	:2023年7月29日15:36:20 
Author	: Alegg xy.
Version	: 2.0
Description: 数码管控制模块
*********************************************************************************/
    
//---------<模块及端口声名>------------------------------------------------------
module static_seg( 
    input				clk		,
    input				rst_n	,
    input				flag	,

    output	reg	[5:0]	sel	    ,//位选
    output	reg	[7:0]	seg	     //段选
);								 
//---------<参数定义>--------------------------------------------------------- 
    reg [3:0] num;//数码管显示十六进制1-f
//---------<内部信号定义>-----------------------------------------------------
    
    //sel定义,数码管0亮,1灭
    always @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            sel <= 6'b111111;//复位时数码管全灭
        end
        else begin
            sel <= 6'b000000;//其余情况数码管亮
        end
    end
    
    //每记满0.5s,num+1
    always @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            num <= 4'h0;
        end
        else if(flag) begin
            num <= num + 1'h1;
        end
        else begin
            num <= num;
        end
    end
    
    //段选信号定义
    always @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            seg <= 8'b0000_0000;
        end
        else begin
            case (num)
                4'h0:seg <= 8'b1100_0000;
                4'h1:seg <= 8'b1111_1001;
                4'h2:seg <= 8'b1010_0100;
                4'h3:seg <= 8'b1011_0000;
                4'h4:seg <= 8'b1001_1001;
                4'h5:seg <= 8'b1001_0010;
                4'h6:seg <= 8'b1000_0010;
                4'h7:seg <= 8'b1111_1000;
                4'h8:seg <= 8'b1000_0000;
                4'h9:seg <= 8'b1001_0000;
                4'hA:seg <= 8'b1000_1000; 
                4'hB:seg <= 8'b1000_0011;
                4'hC:seg <= 8'b1100_0110;
                4'hD:seg <= 8'b1010_0001;
                4'hE:seg <= 8'b1000_0110;
                4'hF:seg <= 8'b1000_1110;
                default: seg <= 8'b1100_0000;
            endcase
        end
    end
endmodule
  • top_static_seg
/**************************************功能介绍***********************************
Date	:2023年7月29日16:02:57 
Author	: Alegg xy.
Version	: 2.0
Description: 静态数码管顶层模块
*********************************************************************************/
    
//---------<模块及端口声名>------------------------------------------------------
module top_static_seg( 
    input				clk		,
    input				rst_n	,

    output		[5:0]	sel	    ,
    output		[7:0]	seg	    
);								 
//---------<参数定义>--------------------------------------------------------- 
    parameter MAX_TIME = 26'd50_000_000;
    wire flag_link;
//---------<内部信号定义>-----------------------------------------------------
    time_count #(.MAX_TIME(MAX_TIME)) u_time_count(
        .clk		(clk),
        .rst_n	    (rst_n),
        .flag	    (flag_link)
    );

    static_seg u_static_seg(
        .clk		(clk),
        .rst_n	    (rst_n),
        .flag	    (flag_link),
        .sel	    (sel),
        .seg	    (seg)  
    );
    
endmodule

4.仿真

`timescale 1ns/1ns
    
module tb_static_seg();

//激励信号定义 
    reg				tb_clk  	;
    reg				tb_rst_n	;

//输出信号定义	 
    wire	[5:0]		tb_sel	;
    wire	[7:0]		tb_seg  ;

//时钟周期参数定义	
    parameter		CLOCK_CYCLE = 20;   

//修改max值
    defparam    u_top_static_seg.MAX_TIME = 10;
//模块例化
    top_static_seg u_top_static_seg(	
    .clk		(tb_clk			),
    .rst_n		(tb_rst_n		),
    .sel        (tb_sel         ),
    .seg        (tb_seg         )
    );

//产生时钟
    initial 		tb_clk = 1'b0;
    always #(CLOCK_CYCLE/2) tb_clk = ~tb_clk;

//产生激励
    initial  begin 
        tb_rst_n = 1'b1;
        #(CLOCK_CYCLE*2);
        tb_rst_n = 1'b0;
        #(CLOCK_CYCLE*20);
        tb_rst_n = 1'b1;
        #(16*CLOCK_CYCLE*10);
        $stop;



    end

endmodule 

5.仿真效果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值