Advertisement
Guest User

Untitled

a guest
Mar 13th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module decoder_4_7_bit (
  2.     input [3:0] X,
  3.     output reg [6:0] H
  4. );
  5.  
  6.     always @(*)
  7.         case (X[3:0])
  8.             4'b0000:
  9.             begin
  10.                 H = 7'b1000000;
  11.             end
  12.             4'b0001:
  13.             begin
  14.                 H = 7'b1111001;
  15.             end
  16.             4'b0010:
  17.             begin
  18.                 H = 7'b0100100;
  19.             end
  20.             4'b0011:
  21.             begin
  22.                 H = 7'b0110000;
  23.             end
  24.             4'b0100:
  25.             begin
  26.                 H = 7'b0011001;
  27.             end
  28.             4'b0101:
  29.             begin
  30.                 H = 7'b0010010;
  31.             end
  32.             4'b0110:
  33.             begin
  34.                 H = 7'b0000010;
  35.             end
  36.             4'b0111:
  37.             begin
  38.                 H = 7'b1111000;
  39.             end
  40.             4'b1000:
  41.             begin
  42.                 H = 7'b0000000;
  43.             end
  44.             4'b1001:
  45.             begin
  46.                 H = 7'b0010000;
  47.             end
  48.         default:
  49.             begin
  50.                 H = 7'b1111111;
  51.             end
  52.         endcase
  53.  
  54. endmodule
  55.  
  56. module decoder_4_7_bit_hex (
  57.     input [3:0] X,
  58.     output reg [6:0] H
  59. );
  60.  
  61.     always @(*)
  62.         case (X[3:0])
  63.             4'b0000:
  64.             begin
  65.                 H = 7'b1000000;
  66.             end
  67.             4'b0001:
  68.             begin
  69.                 H = 7'b1111001;
  70.             end
  71.             4'b0010:
  72.             begin
  73.                 H = 7'b0100100;
  74.             end
  75.             4'b0011:
  76.             begin
  77.                 H = 7'b0110000;
  78.             end
  79.             4'b0100:
  80.             begin
  81.                 H = 7'b0011001;
  82.             end
  83.             4'b0101:
  84.             begin
  85.                 H = 7'b0010010;
  86.             end
  87.             4'b0110:
  88.             begin
  89.                 H = 7'b0000010;
  90.             end
  91.             4'b0111:
  92.             begin
  93.                 H = 7'b1111000;
  94.             end
  95.             4'b1000:
  96.             begin
  97.                 H = 7'b0000000;
  98.             end
  99.             4'b1001:
  100.             begin
  101.                 H = 7'b0010000;
  102.             end
  103.             4'b1010:
  104.             begin
  105.                 H = 7'b0001000;
  106.             end
  107.             4'b1011:
  108.             begin
  109.                 H = 7'b0000011;
  110.             end
  111.             4'b1100:
  112.             begin
  113.                 H = 7'b1000110;
  114.             end
  115.             4'b1101:
  116.             begin
  117.                 H = 7'b0100001;
  118.             end
  119.             4'b1110:
  120.             begin
  121.                 H = 7'b0000110;
  122.             end
  123.             4'b1111:
  124.             begin
  125.                 H = 7'b0001110;
  126.             end
  127.         default:
  128.             begin
  129.                 H = 7'b1111111;
  130.             end
  131.         endcase
  132.  
  133. endmodule
  134.  
  135. module decoder_hex_10 (
  136.     input [3:0]A1, A0,
  137.     output reg [1:0] ERR,
  138.     output [6:0] H1, H0
  139. );
  140.  
  141.     always @(*)
  142.         begin
  143.             if (A1 > 4'b1001)
  144.                 ERR[1] = 1;
  145.             else
  146.                 ERR[1] = 0;
  147.        
  148.             if (A0 > 4'b1001)
  149.                 ERR[0] = 1;
  150.             else
  151.                 ERR[0] = 0;
  152.         end
  153.        
  154.     decoder_4_7_bit ex0 (A1[3:0], H1[6:0]);
  155.     decoder_4_7_bit ex1 (A0[3:0], H0[6:0]);
  156.  
  157. endmodule
  158.  
  159. //module Zadanie2 (
  160. //  input [7:0] SW,
  161. //  output [9:0] LEDR,
  162. //  output [6:0] HEX0, HEX1
  163. //);
  164. //
  165. // decoder_hex_10 ex (SW[7:4], SW[3:0], LEDR[9:8], HEX1[6:0], HEX0[6:0]);
  166. //
  167. // assign LEDR[7:0] = SW[7:0];
  168. //
  169. //endmodule
  170.  
  171.  
  172. module decoder_hex_16 (
  173.     input [3:0]A1, A0,
  174.     output [6:0] H1, H0
  175. );
  176.  
  177.        
  178.     decoder_4_7_bit_hex ex0 (A1[3:0], H1[6:0]);
  179.     decoder_4_7_bit_hex ex1 (A0[3:0], H0[6:0]);
  180.  
  181. endmodule
  182.  
  183. //module Zadanie2 (
  184. //  input [7:0] SW,
  185. //  output [9:0] LEDR,
  186. //  output [6:0] HEX0, HEX1
  187. //);
  188. //
  189. // decoder_hex_16 ex (SW[7:4], SW[3:0], HEX1[6:0], HEX0[6:0]);
  190. //
  191. // assign LEDR[7:0] = SW[7:0];
  192. //
  193. //endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement