2014年6月7日 星期六

Verilog 8bit 跑馬燈




  module LED ( 
            //input 
            sys_clk        ,
            sys_rst_n      ,
            //output 
              LED
              );

//input ports

input                    sys_clk             ;    //system clock;
input                    sys_rst_n           ;    //system reset, low is active;

//output ports
output [WIDTH-1:0]       LED                 ;

//reg define 
reg    [SIZE-1:0]        counter             ;
reg    [WIDTH2-1:0]      count               ;

reg    [WIDTH-1:0]       LED                 ;

//wire define 


//parameter define 
parameter WIDTH = 8;
parameter SIZE  = 8;

parameter WIDTH2 = 18;

parameter Para = 100000;

/*****************************************************
                          Main Program    
*****************************************************/

always @(posedge sys_clk or negedge sys_rst_n) begin 
        if (sys_rst_n ==1'b0) begin 
            count <= 'b0;
        end
        else  
            count  <= count + 1'b1;
end

always @(posedge sys_clk or negedge sys_rst_n) begin 
        if (sys_rst_n ==1'b0) begin 
            counter <= 8'b0;
        end
        else if ( count == Para
            counter  <= counter + 1'b1;
end

always @(posedge sys_clk or negedge sys_rst_n) begin 
        if (sys_rst_n ==1'b0) begin 
            LED <= 8'b0;
        end
        else begin
            case (counter) 
                 10     : LED = 8'b10000000   ;
                 20     : LED = 8'b01000000   ;
                 30     : LED = 8'b00100000   ;
                 40     : LED = 8'b00010000   ;
                 50     : LED = 8'b00001000   ;
                 60     : LED = 8'b00000100   ;
                 70     : LED = 8'b00000010   ;
                 80     : LED = 8'b00000001   ;   
                 default: LED = 8'b00000000   ;   
            endcase
        end          
end


endmodule


沒有留言:

張貼留言

2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2

 2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2 AngularJS 實例 <!DOCTYPE html> <html> <head> &...