|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 picassoye 于 2010-4-20 16:49 编辑
大家好:
我弄了一个uart接收模块,但是有问题,接收不到数据,看了好多遍还是找不出问题,不知道问题出在哪里???
各位帮帮忙啊,代码如下
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 16:25:45 04/14/2010
// Design Name:
// Module Name: uart_rev
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module uart_rev(
iclk,
irstx,
irxd,
odata,
oreceived_char
);
input iclk;
input irstx;
input irxd;
output [7:0]odata;
output oreceived_char;
reg rg_rxd;
reg [13:0]counter;
reg [3:0]rev_bits_count;
reg [7:0]odata;
reg rg_rev_check;
reg oreceived_char;
reg [3:0]CS,NS;
wire w_clk;
parameter IDLE=4'b0000,
START=4'b0001,
REV_BIT=4'b0010,
REV_CHECK=4'b0100,
REV_STOP=4'b1000;
parameter DELAY_COUNT=14'b01_0100_0101_0110;//'d5206
parameter BITS_PER_CHAR=3'b110; //'d6
//generate the slow clock
always@(posedge iclk or negedge irstx)begin
if(~irstx)
counter<=14'b0;
else
begin
if(w_clk)
counter<=14'b0;
else
counter<=counter+1'b1;
end
end
assign w_clk=(counter==DELAY_COUNT);
always@(posedge iclk or negedge irstx)begin
if(~irstx)
rg_rxd<=1'b1;
else
rg_rxd<=irxd;
end
//the state register
always@(posedge w_clk or negedge irstx)begin
if(~irstx)
CS<=IDLE;
else
CS<=NS;
end
//the combinational logic
always@(*)begin
case(CS)
IDLE:if(~rg_rxd) NS=START;
START:NS=REV_BIT;
REV_BIT:if(rev_bits_count[3])NS=REV_CHECK;//8 cycles, 1 byte
REV_CHECK:NS=REV_STOP;
REV_STOP:NS=IDLE;
default:NS=IDLE;
endcase
end
always@(posedge w_clk or negedge irstx)begin
if(~irstx)
rev_bits_count<=BITS_PER_CHAR;
else
if(CS==IDLE)
rev_bits_count<=BITS_PER_CHAR;
else
if(CS==REV_BIT)
rev_bits_count<=rev_bits_count-1'b1;
else
rev_bits_count<=rev_bits_count;
end
always@(posedge w_clk or negedge irstx)begin
if(~irstx)
odata<=8'b0;
else
if(CS==IDLE)
odata<=8'b0;
else
if(CS==REV_BIT)
odata[7:0]<={rg_rxd,odata[7:1]};//右移一位
else
odata<=odata;
end
always@(posedge w_clk or negedge irstx)begin
if(~irstx)
rg_rev_check<=1'b0;
else if(CS==IDLE)
rg_rev_check<=1'b0;
else if(CS==REV_CHECK)
rg_rev_check<=rg_rxd;
else
rg_rev_check<=rg_rev_check;
end
always@(posedge w_clk or negedge irstx)begin
if(~irstx)
oreceived_char<=1'b0;
else if(CS==IDLE)
oreceived_char<=1'b0;
else if(CS==REV_CHECK)
oreceived_char<=1'b1;
else
oreceived_char<=1'b0;
end
endmodule |
|