`timescale 1ns/1ns

// module JC_counter(
//    input                clk ,
//    input                rst_n,
 
//    output reg [3:0]     Q  
// );
//     reg [7:0] cnt;
//     always@(posedge clk or negedge rst_n) begin
//         if(!rst_n) begin
//             cnt <= 8'b11110000;
//         end
//         else begin
//             cnt <= {cnt[0],cnt[7:1]};
//         end
//     end
//     always@(*) begin
//         Q = cnt[3:0];
//     end
// endmodule

//更好的写法
module JC_counter(
   input                clk ,
   input                rst_n,
 
   output reg [3:0]     Q  
);
    always@(posedge clk or negedge rst_n) begin
        if(!rst_n) begin
            Q <= 'd0;
        end
        else begin
            Q <= {~Q[0],Q[3:1]};
        end
    end
endmodule