论坛元老
- 积分
- 6369
- 金钱
- 6369
- 注册时间
- 2015-8-25
- 在线时间
- 1004 小时
|
发表于 2017-4-8 10:09:33
|
显示全部楼层
晶振50M,接收,波特率9600
module Uart_Recv(
sys_clk,
sys_rst_n,
uart_rxd,
LED
);
input sys_clk;
input sys_rst_n;
input uart_rxd;
output reg[WIDTH-1:0] LED;
reg[WIDTH-1:0] buff;
reg[WIDTH-1:0] data_out;
reg uart_rxd_dly1;
reg uart_rxd_dly2;
reg uart_rxd_dly3;
reg uart_rxd_dly4;
reg rxd_negdge_sig_dly1;
reg[SIZE-1:0] counter;
wire rxd_negdge_sig;
parameter WIDTH = 8;
parameter SIZE = 16;
always @(posedge sys_clk or negedge sys_rst_n)
begin
if(sys_rst_n == 1'b0)
begin
uart_rxd_dly1 <= 1'b0;
uart_rxd_dly2 <= 1'b0;
uart_rxd_dly3 <= 1'b0;
uart_rxd_dly4 <= 1'b0;
end
else
begin
uart_rxd_dly1 <= uart_rxd;
uart_rxd_dly2 <= uart_rxd_dly1;
uart_rxd_dly3 <= uart_rxd_dly2;
uart_rxd_dly4 <= uart_rxd_dly3;
end
end
assign rxd_negdge_sig = (~uart_rxd_dly3) & uart_rxd_dly4;
always @(posedge sys_clk or negedge sys_rst_n)
begin
if(sys_rst_n == 1'b0)
rxd_negdge_sig_dly1 <= 1'b0;
else
rxd_negdge_sig_dly1 <= rxd_negdge_sig;
end
always @(posedge sys_clk or negedge sys_rst_n)
begin
if(sys_rst_n == 1'b0)
counter <= 16'b0;
else if( rxd_negdge_sig_dly1 == 1'b1 && counter > 57200 )
counter <= 16'b0;
else if(counter <= 57200)
counter <= counter + 16'b1;
else ;
end
always @(posedge sys_clk or negedge sys_rst_n)
begin
if(sys_rst_n == 1'b0)
buff <= 8'b0;
else
begin
case(counter)
7800 :buff[0] <= uart_rxd_dly4;
13000 :buff[1] <= uart_rxd_dly4;
18200 :buff[2] <= uart_rxd_dly4;
23400 :buff[3] <= uart_rxd_dly4;
28600 :buff[4] <= uart_rxd_dly4;
33800 :buff[5] <= uart_rxd_dly4;
39000 :buff[6] <= uart_rxd_dly4;
44200 :buff[7] <= uart_rxd_dly4;
default:buff <= buff;
endcase
end
end
always @(posedge sys_clk or negedge sys_rst_n)
begin
if(sys_rst_n == 1'b0)
LED <= 8'b0;
else
LED <= buff;
end
endmodule |
|