这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » hanx3832的进程贴

共12条 2/2 1 2 跳转至
工程师
2012-12-12 22:34:48     打赏
11楼
4.开关控制数码管显示
波动开关,数码管显示相应数字



用case语句实现。

5.数码管模60计数器

为了减少视频时间,把计数改为0.125s记一次,



部分代码如下:
always @(posedge clk or negedge rst_n)
    begin
     if(!rst_n)
      begin
          uni<=1'd0;
       ten<=1'd0;
   end
  else
      begin
       if(de_cnt==26'd6259999)  
              begin   
         if(uni==4'd9 && ten<3'd5)
          begin
              uni<=1'd0;
           ten<=ten+1'd1;
       end
            else if(uni==4'd9 && ten==3'd5)
          begin
                    uni<=1'd0;
                       ten<=1'd0;
       end  
      else
       uni<=uni+1'd1; 
     end
      end     
 end
always @(dis_dat)
    begin
        case(dis_dat)
            3'b000: sm_bit=8'b11111110;
         3'b001: sm_bit=8'b11111101;
         default sm_bit=8'b11111111;
        endcase
    end
always @(sm_bit)
    begin
     case(sm_bit)
         8'b11111110: datout_buf<=uni;
         8'b11111101: datout_buf<=ten;
         default datout_buf=0;
     endcase
 end
always @(datout_buf)
    begin
     case(datout_buf)
         4'd0: sm_seg=8'hc0;
         4'd1: sm_seg=8'hf9;
         4'd2: sm_seg=8'ha4;
         4'd3: sm_seg=8'hb0;
         4'd4: sm_seg=8'h99;
         4'd5: sm_seg=8'h92;
         4'd6: sm_seg=8'h82;
         4'd7: sm_seg=8'hd8;
         4'd8: sm_seg=8'h80;
         4'd9: sm_seg=8'h90;
            default sm_seg=8'hc0;
     endcase
 end
endmodule

工程师
2012-12-12 22:44:32     打赏
12楼
6.按键控制数码管循环显示0~9


先做了按键没经过消抖的实验,点亮LED时发现灯的状态基本是随机的,数码管显示也是随机的数字,还以为是代码写的有问题,加上消抖后,显示就很正常了,按键的抖动非常厉害。

主要代码:
初始状态:灯亮,数码管显示0
always @(posedge clk or negedge rst_n)
    begin
      if(!rst_n)
       data<=1'd0;
    else
        if(key_low)
      begin
            led_out<=~led_out;
            if(data==4'd9)
                   data<=1'd0;
        else
               data<=data+1'd1; 
    end
 end
always @(data)
    begin
   case(data)
      4'd0: sm_seg=8'hc0;
      4'd1: sm_seg=8'hf9;
      4'd2: sm_seg=8'ha4;
      4'd3: sm_seg=8'hb0;
      4'd4: sm_seg=8'h99;
      4'd5: sm_seg=8'h92;
      4'd6: sm_seg=8'h82;
      4'd7: sm_seg=8'hd8;
      4'd8: sm_seg=8'h80;
      4'd9: sm_seg=8'h90;
       default sm_seg=8'hc0;
   endcase
 end
assign sm_bit=8'b11111110;
endmodule

共12条 2/2 1 2 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]