|
`timescale 1ns / 1ps
module Rec_commond(
i_clk, //20M
i_clk100m, //100M
i_rstn,
o_TxD,
ready //
);
input i_clk,
i_clk100m;
input i_rstn;
output o_TxD;
output ready;
reg [10:0] RegData =11'b010_1010_1010 ;
reg pos_ready;
reg pos_Sclk;
reg start;
reg sent;
reg o_TxD;
reg cnt_start;
reg [3:0] cnt_sent;
reg [3:0] state;
reg Lclk;
wire i_clk;
wire i_rstn;
wire [7:0] k_Sclk = 8'd20;
wire [10:0] k_ready = 11'd1000;
wire Sclk; // 1M
wire ready;//20K
/////////// ready上升沿识别
always@(posedge i_clk)
begin
if (~i_rstn) begin
start<=0;
pos_ready<=0;
end
else begin
pos_ready <= ready;
start <= {(~pos_ready) & ready};
end
end
///////////Sclk 上升沿识别
always@(posedge i_clk)
begin
if (~i_rstn) begin
sent<=0;
pos_Sclk<=0;
end
else begin
pos_Sclk <= Sclk;
sent <= {(~pos_Sclk) & Sclk};
end
end
always @(posedge i_clk)begin
if (~i_rstn) begin
state <= 4'b0000;
o_TxD<=1;
end
else begin
case(state)
4'b0000: if(start)begin
state<=4'b0001;
// o_TxD <= RegData[0];
end
4'b0001: if(sent)begin
state<=4'b0010;
o_TxD <= RegData[0];
end
4'b0010: if(sent)begin
state<=4'b0011;
o_TxD <= RegData[1];
end
4'b0011: if(sent)begin
state<=4'b0100;
o_TxD <= RegData[2];
end
4'b0100: if(sent)begin
state<=4'b0101;
o_TxD <= RegData[3];
end
4'b0101: if(sent)begin
state<=4'b0110;
o_TxD <= RegData[4];
end
4'b0110: if(sent)begin
state<=4'b0111;
o_TxD <= RegData[5];
end
4'b0111: if(sent)begin
state<=4'b1000;
o_TxD <= RegData[6];
end
4'b1000: if(sent)begin
state<=4'b1001;
o_TxD <= RegData[7];
end
4'b1001: if(sent)begin
state<=4'b1010;
o_TxD <= RegData[8];
end
4'b1010: if(sent)begin
state<=4'b1011;
o_TxD <= RegData[9];
end
4'b1011: if(sent)begin
state<=4'b0000;
o_TxD <= RegData[10];
end
default:state<=4'b0000;
endcase
end
end
////////////////分频得到1M Sclk
Sclk U_Sclk(
.i_clk(i_clk),
.i_rstn(i_rstn),
.k(k_Sclk),
.clkk(Sclk) //1M
);
//////////////////分频得到ready 20k
ready U_ready(
.i_clk(i_clk),
.i_rstn(i_rstn),
.k(k_ready),
.clkk(ready) //ready 20k
);
endmodule |
|