It is currently Thu Sep 09, 2010 12:48 am




Post new topic Reply to topic  [ 1 post ] 
Verilog - 14-bit BCD ( Binary Converted to Decimal) 
Author Message
Site Admin

Joined: Sat Jan 24, 2009 3:56 pm
Posts: 32
Post Verilog - 14-bit BCD ( Binary Converted to Decimal)
This one is a bit complex so take a careful look. The essential role of this is to allow you to take a 14-bit register and convert the binary (or hex), into a decimal value. I used this code so that I could keep a hex value in a register, but display it as a decimal value onto the 7-segment display of my Nexys-2 board

Code:
module Convert14BitToBCD(bin, bcd);
   input [13:0] bin;
   output [15:0] bcd;

   wire [3:0] c0, c1, c2, c3, c4, c5, c6, c7, c8, c9;
   wire [3:0] c10, c11, c12, c13, c14, c15, c16, c17, c18, c19;
   wire [3:0] c20, c21, c22, c23;//, c24, c25, c26;

      onebit one0({1'd0, bin[13:11]}, c0);
      onebit one1({c0[2:0], bin[10]}, c1);
      onebit one2({c1[2:0], bin[9]}, c2);
      onebit one3({c2[2:0], bin[8]}, c3);
      onebit one4({c3[2:0], bin[7]}, c4);
      onebit one5({c4[2:0], bin[6]}, c5);
      onebit one6({c5[2:0], bin[5]}, c6);
      onebit one7({c6[2:0], bin[4]}, c7);
      onebit one8({c7[2:0], bin[3]}, c8);
      onebit one9({c8[2:0], bin[2]}, c9);
      onebit one10({c9[2:0], bin[1]}, c10);
      onebit one11({1'd0, c0[3], c1[3], c2[3]}, c11);
      onebit one12({c11[2:0], c3[3]}, c12);
      onebit one13({c12[2:0], c4[3]}, c13);
      onebit one14({c13[2:0], c5[3]}, c14);
      onebit one15({c14[2:0], c6[3]}, c15);
      onebit one16({c15[2:0], c7[3]}, c16);
      onebit one17({c16[2:0], c8[3]}, c17);
      onebit one18({c17[2:0], c9[3]}, c18);
      onebit one19({1'd0, c11[3], c12[3], c13[3]}, c19);
      onebit one20({c19[2:0], c14[3]}, c20);
      onebit one21({c20[2:0], c15[3]}, c21);
      onebit one22({c21[2:0], c16[3]}, c22);
      onebit one23({c22[2:0], c17[3]}, c23);
      
      assign bcd = {c20[3], c21[3], c22[3], c23, c18, c10, bin[0]};
endmodule


Thu Aug 06, 2009 6:59 am
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © phpBB Group.
Designed by Vjacheslav Trushkin for Free Forum/DivisionCore.