FPGA实现二进制转BCD码

Verilog代码:
module Binary_to_BCD
#(parameter INPUT_WIDTH,
parameter DECIMAL_DIGITS)
(
input i_Clock,
input [INPUT_WIDTH-1:0] i_Binary,
input i_Start,
//
output [DECIMAL_DIGITS*4-1:0] o_BCD,
output o_DV
);

parameter s_IDLE = 3’b000;
parameter s_SHIFT = 3’b001;
parameter s_CHECK_SHIFT_INDEX = 3’b010;
parameter s_ADD = 3’b011;
parameter s_CHECK_DIGIT_INDEX = 3’b100;
parameter s_BCD_DONE = 3’b101;

reg [2:0] r_SM_Main = s_IDLE;

// The vector that contains the output BCD
reg [DECIMAL_DIGITS*4-1:0] r_BCD = 0;

// The vector that contains the input binary value being shifted.
reg [INPUT_WIDTH-1:0] r_Binary = 0;

// Keeps track of which Decimal Digit we are indexing
reg [DECIMAL_DIGITS-1:0] r_Digit_Index = 0;

// Keeps track of which loop iteration we are on.
// Number of loops peRFormed = INPUT_WIDTH
reg [7:0] r_Loop_Count = 0;

wire [3:0] w_BCD_Digit;
reg r_DV = 1’b0;

always @(posedge i_Clock)
begin

  case (r_SM_Main) 

    // Stay in this state until i_Start comes along
    s_IDLE :
      begin
        r_DV <= 1'b0;
         
        if (i_Start == 1'b1)
          begin
            r_Binary  <= i_Binary;
            r_SM_Main <= s_SHIFT;
            r_BCD     <= 0;
          end
        else
          r_SM_Main <= s_IDLE;
      end
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值