Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //7 binary_7_bits_BCD
- module binary_7_bits_BCD ( // display decimal value of 7-digit binary input
- input [6:0] SW,
- output [6:0] LEDR,
- output [0:6] HEX0, HEX1, HEX2);
- assign LEDR[6:0] = SW[6:0];
- wire [0:6] sw1 = SW[6:0]; // max 128
- reg hundreds = 0;
- reg tens = 0;
- reg n1 = 0;
- showDigitDec ex1(n1, HEX0);
- showDigitDec ex2(tens, HEX1);
- showDigitDec ex3(hundreds, HEX2);
- always @*
- begin
- if(sw1 >= 100) hundreds = 1;
- else hundreds = 0;
- if (sw1 >= 90 + hundreds * 100) tens = 9;
- else if (sw1 >= 80 + hundreds * 100) tens = 8;
- else if (sw1 >= 70 + hundreds * 100) tens = 7;
- else if (sw1 >= 60 + hundreds * 100) tens = 6;
- else if (sw1 >= 50 + hundreds * 100) tens = 5;
- else if (sw1 >= 40 + hundreds * 100) tens = 4;
- else if (sw1 >= 30 + hundreds * 100) tens = 3;
- else if (sw1 >= 20 + hundreds * 100) tens = 2;
- else if (sw1 >= 10 + hundreds * 100) tens = 1;
- else tens = 0;
- n1 = sw1 - tens * 10 - hundreds * 100;
- end
- endmodule
- //8 binary_8_bits_BCD
- module binary_8_bits_BCD ( // display decimal value of 8-digit binary input
- input [7:0] SW,
- output [7:0] LEDR,
- output [0:6] HEX0, HEX1, HEX2);
- assign LEDR[7:0] = SW[7:0];
- wire [0:7] sw1 = SW[7:0]; // max 256
- reg hundreds = 0;
- reg tens = 0;
- reg n1 = 0;
- showDigitDec ex1(n1, HEX0);
- showDigitDec ex2(tens, HEX1);
- showDigitDec ex3(hundreds, HEX2);
- integer i;
- always @*
- begin
- if(sw1 >= 200) hundreds = 2;
- else if(sw1 >= 100) hundreds = 1;
- else hundreds = 0;
- if (sw1 >= 90 + hundreds * 100) tens = 9;
- else if (sw1 >= 80 + hundreds * 100) tens = 8;
- else if (sw1 >= 70 + hundreds * 100) tens = 7;
- else if (sw1 >= 60 + hundreds * 100) tens = 6;
- else if (sw1 >= 50 + hundreds * 100) tens = 5;
- else if (sw1 >= 40 + hundreds * 100) tens = 4;
- else if (sw1 >= 30 + hundreds * 100) tens = 3;
- else if (sw1 >= 20 + hundreds * 100) tens = 2;
- else if (sw1 >= 10 + hundreds * 100) tens = 1;
- else tens = 0;
- n1 = sw1 - tens * 10 - hundreds * 100;
- end
- endmodule
- //9 binary_9_bits_BCD
- module binary_9_bits_BCD ( // display decimal value of 9-digit binary input
- input [8:0] SW,
- output [8:0] LEDR,
- output [0:6] HEX0, HEX1, HEX2);
- assign LEDR[8:0] = SW[8:0];
- wire [0:8] sw1 = SW[8:0]; // max 512
- reg hundreds = 0;
- reg tens = 0;
- reg n1 = 0;
- showDigitDec ex1(n1, HEX0);
- showDigitDec ex2(tens, HEX1);
- showDigitDec ex3(hundreds, HEX2);
- integer i;
- always @*
- begin
- if(sw1 >= 500) hundreds = 5;
- else if(sw1 >= 400) hundreds = 4;
- else if(sw1 >= 300) hundreds = 3;
- else if(sw1 >= 200) hundreds = 2;
- else if(sw1 >= 100) hundreds = 1;
- else hundreds = 0;
- if (sw1 >= 90 + hundreds * 100) tens = 9;
- else if (sw1 >= 80 + hundreds * 100) tens = 8;
- else if (sw1 >= 70 + hundreds * 100) tens = 7;
- else if (sw1 >= 60 + hundreds * 100) tens = 6;
- else if (sw1 >= 50 + hundreds * 100) tens = 5;
- else if (sw1 >= 40 + hundreds * 100) tens = 4;
- else if (sw1 >= 30 + hundreds * 100) tens = 3;
- else if (sw1 >= 20 + hundreds * 100) tens = 2;
- else if (sw1 >= 10 + hundreds * 100) tens = 1;
- else tens = 0;
- n1 = sw1 - tens * 10 - hundreds * 100;
- end
- endmodule
- //10 binary_10_bits_BCD
- module binary_10_bits_BCD ( // display decimal value of 10-digit binary input
- input [9:0] SW,
- output [9:0] LEDR,
- output [0:6] HEX0, HEX1, HEX2, HEX3);
- assign LEDR[9:0] = SW[9:0];
- wire [0:9] sw1 = SW[9:0]; // max 1024
- reg thousands = 0;
- reg hundreds = 0;
- reg tens = 0;
- reg n1 = 0;
- showDigitDec ex1(n1, HEX0);
- showDigitDec ex2(tens, HEX1);
- showDigitDec ex3(hundreds, HEX2);
- showDigitDec ex4(thousands, HEX3);
- integer i;
- always @*
- begin
- if(sw1 >= 1000) thousands= 1;
- else thousands = 0;
- if(sw1 >= 900) hundreds = 9;
- else if(sw1 >= 800 + thousands * 1000) hundreds = 8;
- else if(sw1 >= 700 + thousands * 1000) hundreds = 7;
- else if(sw1 >= 600 + thousands * 1000) hundreds = 6;
- else if(sw1 >= 500 + thousands * 1000) hundreds = 5;
- else if(sw1 >= 400 + thousands * 1000) hundreds = 4;
- else if(sw1 >= 300 + thousands * 1000) hundreds = 3;
- else if(sw1 >= 200 + thousands * 1000) hundreds = 2;
- else if(sw1 >= 100 + thousands * 1000) hundreds = 1;
- else hundreds = 0;
- if (sw1 >= 90 + hundreds * 100 + thousands * 1000) tens = 9;
- else if (sw1 >= 80 + hundreds * 100 + thousands * 1000) tens = 8;
- else if (sw1 >= 70 + hundreds * 100 + thousands * 1000) tens = 7;
- else if (sw1 >= 60 + hundreds * 100 + thousands * 1000) tens = 6;
- else if (sw1 >= 50 + hundreds * 100 + thousands * 1000) tens = 5;
- else if (sw1 >= 40 + hundreds * 100 + thousands * 1000) tens = 4;
- else if (sw1 >= 30 + hundreds * 100 + thousands * 1000) tens = 3;
- else if (sw1 >= 20 + hundreds * 100 + thousands * 1000) tens = 2;
- else if (sw1 >= 10 + hundreds * 100 + thousands * 1000) tens = 1;
- else if tens = 0;
- n1 = sw1 - tens * 10 - hundreds * 100 - thousands * 1000;
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement