我写了个串口接收的程序,但是仿真的时候没有波形,下到片子里也没有反应,哪位高手给指点一下! module onlyjie (clk,rst,rxd,rxd_buf); input clk,rst,rxd; output rxd_buf; reg [15:0] div_reg; reg div_baud; reg [2:0] div8_rec_reg; reg recstart; reg clkbaud_rec; reg [7:0] rxd_buf; reg rec_reg1; reg rec_reg2; reg [2:0] state_rec0; reg recstart_tmp; parameter div_par=16'h41; //是波特率为38400的八倍分频; always @ (posedge clk, negedge rst) begin if (!rst) div_reg<=0; else begin if (div_reg==div_par-1) div_reg<=0; else div_reg<=div_reg+1; end end always @ (posedge clk, negedge rst) begin if (!rst) div_baud<=0; else begin if (div_reg==div_par-1) div_baud<=~div_baud; end end always @ (posedge div_baud, negedge rst) begin if (!rst) div8_rec_reg<=0; else if (recstart) div8_rec_reg<=div8_rec_reg+1; end always @ (div8_rec_reg) begin if (div8_rec_reg==7) clkbaud_rec=1; else clkbaud_rec=0; end always @ (posedge div_baud,negedge rst) begin if (!rst) begin rec_reg1<=0; rec_reg2<=0; rxd_buf<=0; state_rec0<=0; recstart<=0; recstart_tmp<=0; end else begin rec_reg1<=rxd; rec_reg2<=rec_reg1; if (state_rec0==0) begin if (recstart_tmp==1) begin recstart_tmp<=0; recstart<=1; state_rec0<=state_rec0+1; end else if(!rec_reg1&&rec_reg2) recstart_tmp<=1; end else if (state_rec0<=1&&state_rec0>=8) begin if (clkbaud_rec) begin rxd_buf[7]<=rec_reg2; rxd_buf[6:0]<=rxd_buf[7:1]; state_rec0<=state_rec0+1; end end else if (state_rec0==9) begin if (clkbaud_rec) begin state_rec0<=0; recstart<=0; end end end end endmodule
|