码迷,mamicode.com
首页 > 其他好文 > 详细

花样流水灯的verilog实现

时间:2015-08-11 21:02:10      阅读:455      评论:0      收藏:0      [点我收藏+]

标签:

LED(Light emitting diode)发光二极管将电能转化为可见光,正向电压导通,反向电压截止。对于该板子,二极管用低电压导通,其实验原理图为:

技术分享

所谓流水灯,即让LED像水一样的点亮,从左向右依次点亮,最右位点亮后,再从左向右移动。以下是以移位方式实现的verilog代码:

module led(
            clk,  //50M时钟输入
            reset,    //复位信号,高电平复位
            led      //led输出
);

input clk;
input reset;
output[7:0] led;

wire clk,reset;

reg [7:0]led,led_temp; 
reg [40:0] count;    //分频计数器,系统时钟频率过高,需要计数的方式来产生延时,使led保持状态一段时间

always @ (posedge clk or negedge reset)
    begin
     if(!reset)//复位
       begin
           led_temp<=8h80;
           count<=41h0;
       end
      else
        begin
          count<=count+1;
          if(count==41hff_ff_ff)    //判别counter数值,做输出处理
            begin
             led_temp<=led_temp>>1;
             led<=~led_temp;
             count<=0;
             if(led_temp==8h01)
               led_temp<=8h80;
            end  
        end
    end
endmodule

花样流水灯根据循坏赋值方式实现:

module led_water(clk,led,reset);
input clk;
input reset;
output [7:0] led;

reg [7:0] led;
reg [23:0] counter;
reg [4:0] led_state;
reg clk_div;

always @(posedge clk)
  begin 
     if(counter==24h500000)
      begin
        clk_div<=~clk_div;
        counter<=24h000000;
      end
     else 
        counter<=counter+1b1;
  end 


always @(posedge clk_div or negedge reset)
  begin 
    if(!reset)
      begin
       led<=8hff;
       led_state<=4b0000;
      end 
    else
     begin
      case (led_state)
        5b00000: led<=8b1111_1110;
        5b00001: led<=8b1111_1101;
        5b00010: led<=8b1111_1011;
        5b00011: led<=8b1111_0111;
        5b00100: led<=8b1110_1111;
        5b00101: led<=8b1101_1111;
        5b00110: led<=8b1011_1111;
        5b00111: led<=8b0111_1111;
        
        5b01000: led<=8b1011_1111;
        5b01001: led<=8b1101_1111;
        5b01010: led<=8b1110_1111;
        5b01011: led<=8b1111_0111;
        5b01100: led<=8b1111_1011; 
        5b01101: led<=8b1111_1101; 
        5b01110: led<=8b1111_1110;
        
        5b01111: led<=8b1110_0111;
        5b10000: led<=8b1101_1011;
        5b10001: led<=8b1011_1101;
        5b10010: led<=8b0111_1110;
        
        5b10011: led<=8b1011_1101;
        5b10100: led<=8b1101_1011;
        5b10101: led<=8b1110_0111;
        
        5b10110: led<=8b1010_1010;
        5b10111: led<=8b0101_0101;
               
        5b11000: led<=8b1000_0000;
        5b11001: led<=8b0100_0000;
        5b11010: led<=8b0010_0000;
        5b11011: led<=8b0001_0000;
        5b11100: led<=8b0000_1000;
        5b11101: led<=8b0000_0100;
        5b11110: led<=8b0000_0010;
        5b11111: led<=8b0000_0001;
        default:led<=8b1111_1111;
      endcase
     led_state<=led_state+1b1;
    end 
  end
endmodule

综合优化后,板子呈现花样流水灯样式。

技术分享

花样流水灯的verilog实现

标签:

原文地址:http://www.cnblogs.com/Fun-with-FPGA/p/4722109.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!