|
module uart_rx(uart_clk, rst_n, rxd, rx_data, wrreq);
input uart_clk; //时钟:153600HZ
input rst_n;
input rxd; //接收信号线
output reg [7:0] rx_data; //接收到的8bit数据
output reg wrreq; //接收完成后写fifo请求
/******LSM_1S******/
reg [7:0] cnt; //节拍计数器
reg [1:0] state; //状态变量
parameter s0 = 2'b01;
parameter s1 = 2'b10;
always @ (posedge uart_clk, negedge rst_n) begin
if(rst_n == 1'b0)
begin
cnt <= 8'd0;
state <= s0;
end
else
case(state)
s0 : if(rxd == 1'b0)
state <= s1;
else
state <= s0;
s1 : if(cnt < 8'd153)
cnt <= cnt + 1'd1;
else
begin
cnt <= 8'd0;
state <= s0;
end
endcase
end
/******LSM_2S******/
always @ (posedge uart_clk, negedge rst_n) begin
if(rst_n == 1'b0)
begin
rx_data <= 8'h0;
wrreq <= 1'b0;
end
else
begin
case(cnt)
7 + 1 * 16 : rx_data[0] <= rxd; //接收第一位数据
7 + 2 * 16 : rx_data[1] <= rxd; //接收第二位数据
7 + 3 * 16 : rx_data[2] <= rxd; //接收第三位数据
7 + 4 * 16 : rx_data[3] <= rxd; //接收第四位数据
7 + 5 * 16 : rx_data[4] <= rxd; //接收第五位数据
7 + 6 * 16 : rx_data[5] <= rxd; //接收第六位数据
7 + 7 * 16 : rx_data[6] <= rxd; //接收第七位数据
7 + 8 * 16 : rx_data[7] <= rxd; //接收第八位数据
7 + 9 * 16 + 1 : wrreq <= 1'b1; //拉高写请求
7 + 9 * 16 + 2 : wrreq <= 1'b0; //拉低写请求
default : ;
endcase
end
end
endmodule
|
|