集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1026|回复: 0

两位数码管之计数器

[复制链接]
创客 发表于 2013-8-1 18:32:09 | 显示全部楼层 |阅读模式
module digital1 (clk,res,sm_cs1,sm_cs2,out);

input clk,res;

output sm_cs1,sm_cs2;
output [6:0] out;

wire [6:0] out;

reg [24:0] cnt;

always @ (posedge clk or negedge res)
   if(!res) cnt <= 25'b0;
         else cnt <= cnt + 1'b1;       

reg [3:0] shi,ge;
                       
always @ (posedge clk or negedge res)
    if(!res)
      begin
             shi <= 4'd1;
                  ge <= 4'd0;
                 end
                else  if(cnt == 25'h1ffffff)
                         begin
                                          //shi <= shi + 1'b1;
                                           ge <= ge + 1'b1;
                                                if(ge == 4'h9)
                                                 begin
                                                 ge <= 4'd0;
                                                 shi <= shi + 1'b1;
                                                  if(shi == 4'h9)
                                                    begin
                                                         shi <= 4'd0;
                                                         end
                                                 end
                                        end
parameter result0 = 7'h3f,
          result1 = 7'h06,
                    result2 = 7'h5b,
                    result3 = 7'h4f,
          result4 = 7'h66,
                    result5 = 7'h6d,
                    result6 = 7'h7d,
                         result7 = 7'h07,
          result8 = 7'h7f,
                    result9 = 7'h6f;
//          result10 = 7'hf7,
//          result11 = 7'hfc,
//                    result12 = 7'h39,
//                    result13 = 7'h5e,
//                         result14 = 7'h79,
//                    result15 = 7'h71;
reg [3:0] num;
reg [6:0] outr;

always @ (num)
                                 case(num)
                                4'h0utr<=result0;
                                4'h1utr<=result1;
                                4'h2utr<=result2;
                                4'h3utr<=result3;
                                4'h4utr<=result4;
                                4'h5utr<=result5;
                                4'h6utr<=result6;
                                4'h7utr<=result7;
                                4'h8utr<=result8;
                                4'h9utr<=result9;
//                                4'hA:outr<=result10;
//                                4'hB:outr<=result11;
//                                4'hC:outr<=result12;
//                                4'hD:outr<=result13;
//                                4'hE:outr<=result14;
//                                4'hF:outr<=result15;
                                default: outr <= result0;
         endcase
assign out = outr;
                         
reg sm_cs2_r,sm_cs1_r;
//----------------------------两个数码管之间的扫描
always @(clk or shi or ge)
        begin
                if(cnt[19])
                begin
                        sm_cs2_r = 0;
                        sm_cs1_r = 1;
                        num = shi;
                end
                else
                begin
                        sm_cs2_r = 1;
                        sm_cs1_r = 0;
                                                                num = ge;
                  end
        end
                       
assign sm_cs2 = sm_cs2_r;
assign sm_cs1 = sm_cs1_r;

         
         
endmodule
           
               
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-5-8 04:27 , Processed in 0.056121 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表