ciel.xia的个人空间 https://blog.eetop.cn/1544698 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

UART发送器

已有 604 次阅读| 2018-8-17 17:05 |个人分类:代码带回家|系统分类:芯片设计


module UART_XMTR #(parameter word_size=8)(
 output       Serial_out,
 input [word_size-1:0]  Data_Bus,
 input      Load_XMT_datareg,Byte_ready,T_byte,Clock,rst_b
);
Control_Unit M0(Load_XMT_DR,Load_XMT_shftreg,start,clear,Load_XMT_datareg,
    Byte_ready,T_byte,BC_It_BCmax,Clock,rst_b);
Datapath_Unit M1(Serial_out,BC_It_BCmax,Data_Bus,Load_XMT_DR,
    Load_XMT_shftreg,start,shift,clear,Clock,rst_b);
endmodule
module Control_Unit #(
 parameter  one_hot_count=3,
    state_count=one_hot_count,
    size_bit_count=3,
    idle = 3'b001,
    waiting = 3'b010,
    sending = 3'b100,
    all_ones=9'b1_1111_1111)
 (output reg     Load_XMT_DR,
 output reg     Load_XMT_datareg,
 output reg     start,
 output reg     shift,clear,
 input      Load_XMT_datareg,Byte_ready,T_byte,BC_It_BCmax,
 input      Clock,rst_b
 );
 reg [state_count-1:0] state,next_state;
 always@(state,Load_XMT_datareg,Byte_ready,T_byte,BC_It_BCmax)
 begin:Output_and_next_state
  Load_XMT_DR = 0;
  Load_XMT_shftreg = 0;
  start  = 0;
  shift  = 0;
  clear  = 0;
  next_state = idle;
  case(state)
  idle:  if(Load_XMT_datareg==1'b1)begin
     Load_XMT_DR  = 1;
     next_state = idle;
    end
    else if(Byte_ready==1'b1)begin
     Load_XMT_shftreg = 1;
     next_state = waiting;
    end
  waiting:if(T_byte==1)begin
     start = 1;
     next_state = sending;
    end
    else
     next_state = waiting;
  sending:if(BC_It_BCmax)begin
     shift = 1;
     next_state = sending;
    end
    else begin
     clear = 1;
     next_state = idle;
    end
  default:next_state = idle;
  endcase
 end
 always@(posedge clk or negedge rst_b)begin:State_Transitions
  if(!rst_b)
   stae <= idle;
  else
   stae <= next_state; 
endmodule
module Datapath_Unit #(
 parameter  word_size = 8,
 size_bit_count = 3,
 all_ones = {(word_size+1){1'b1}}
)(
 output       Serial_out,BC_It_BCmax,
 input [word_size-1:0]  Data_Bus,
 input      Load_XMT_DR,Load_XMT_shftreg,
 input      start,clear,shift,Clock,rst_b
);
 reg  [word_size-1:0]  XMT_datareg;
 reg  [word_size:0]  XMT_shftreg;
 reg  [size_bit_count:0] bit_count;
 
 assign  Serial_out  = XMT_shftreg[0];
 assign BC_It_BCmax = (bit_count<word_size+1);
 
 always@(posedge Clock,negedge rst_b)
  if(!rst_b)begin
   XMT_shftreg <= all_ones;
   bit_count <= 0;
  end
  else begin:Regster_Transfers
   if(Load_XMT_DR==1'b1)
    XMT_datareg <= Data_Bus;
   if(Load_XMT_shftreg==1'b1)
    XMT_shftreg <= {XMT_datareg,1'b1};
   if(start ==1'b1)
    XMT_shftreg[0] <= 0;
   if(clear ==1'b1)
    bit_count <= 0;
   if(shift ==1'b1)begin
    XMT_shftreg <= {1'b1,XMT_shftreg[word_size:1]};
    bit_count <= bit_count+1;
   end
  end
endmodule

点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 1

    粉丝
  • 0

    好友
  • 0

    获赞
  • 1

    评论
  • 访问数
关闭

站长推荐 上一条 /2 下一条


小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-12-18 20:12 , Processed in 0.015434 second(s), 12 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部