复件 uart_rec.txt

来自「大幅噶是大法师父啊方式大法发生的发生的发生的发生的发达省份发」· 文本 代码 · 共 102 行

TXT
102 行
字号


module uart_rec(rst,baud_clk_16x,sin,dout,rd_n,drdy);

input rst,baud_clk_16x,sin,rd_n;
output [7:0] dout;
output drdy;

reg [7:0] dout;
reg [0:0] drdy;
reg [3:0] read_bits_num;
reg [3:0] clock_times;
reg [7:0] buffer_reg;
reg [0:0] in_message;
reg [0:0] true;
true=1'b1;



always @ (posedge clk,posedge rst,negedge rd_n)//////模块始终检测有关信号,以做不同的工作
begin
  if(rst)////模块复位
    begin
       drdy=0;
       dout=8'bxxxxxxxx;
       clock_times=0;
       read_bits_num=0;
    end/////复位结束 
  else
    if(!rd_n)   
      drdy=0; ///////////rd_n有效,请零drdy
    else 
  if(drdy==0)  
    case(read_bits_num)
    4'd0:  /////一位都没读,开始检测开始信号。
         begin
         if(clock_times==0)/////检测信号是否为低电平
             in_messsage=sin;
         else
              if(clock_times==8)//////确认是否为低电平
                   begin
                    if(in_message==0 && sin==0)
                      begin
                      read_bits_num=1;
                      clock_times=0;
                      end
                   else  /////////发现不是低电平,则不能开始接受信息。继续检测。
                      clock_times=0;
                   end
              else
               clock_times=clock_times+1;
         end


    4'd1,  /////读第1位
    4'd2,  /////读第2位
    4'd3,  /////读第3位
    4'd4,  /////读第4位
    4'd5,  /////读第5位
    4'd6,  /////读第6位
    4'd7,  /////读第7位
    4'd8:  /////读第8位
         begin
         if(clock_times==4'b1111)
            begin
            buffer_reg[read_bits_num-1]=sin;
            read_bits_num=read_bits_num+1;
            clock_times=0;
            end
         else
            clock_times=clock_times+1;               
         end


    4'd9:  /////已经读完8位,开始检测结束信号。
         begin
         if(clock_times==4'b1111)
            begin            
            in_message=sin;
            if(in_message==1)//////检测到结束信号
               begin
               dout=buffer_reg;
               drdy=1;
               clock_times=0;
               end
            esle//////////////////未检测到结束信号
               begin
               read_bits_num=0;               
               clock_times=0;

               end                
            end
         else
            clock_times=clock_times+1;               
         end

    default:
    endcase

end

endmodule

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?