module uart_communication_module (
// 输入端口
input wire clk,
input wire rst,
input wire tx_data,
input wire tx_ready,
// 输出端口
output reg rx_data,
output reg rx_ready
);
// 状态机
reg [2:0] state;
// 状态定义
parameter IDLE = 3'b000;
parameter START = 3'b001;
parameter DATA = 3'b010;
parameter STOP = 3'b011;
// 状态迁移
always @(posedge clk or posedge rst) begin
if (rst) begin
state <= IDLE;
rx_data <= 1'b0;
rx_ready <= 1'b0;
end else begin
case (state)
IDLE: begin
if (tx_ready) begin
state <= START;
end
end
START: begin
state <= DATA;
end
DATA: begin
rx_data <= tx_data;
state <= STOP;
end
STOP: begin
rx_ready <= 1'b1;
state <= IDLE;
end
endcase
end
end
endmodule```