Advertisement
mcleod_ideafix

Double-dabble y 7 segmentos

Nov 30th, 2020
1,681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company:  Universidad de Sevilla
  4. // Engineer: Miguel Angel Rodriguez Jodar
  5. //
  6. // Create Date:    18:05:17 11/13/2013
  7. // Design Name:
  8. // Module Name:    bcd7seg
  9. // Project Name:
  10. // Target Devices: Basys2
  11. // Tool versions:
  12. // Description:
  13. //
  14. // Dependencies:
  15. //
  16. // Revision:
  17. // Revision 0.01 - File Created
  18. // Additional Comments: (C)2013 Miguel Angel Rodriguez Jodar. Todos los derechos reservados
  19. //
  20. //////////////////////////////////////////////////////////////////////////////////
  21. module bcd7seg (
  22.     input wire [4:0] d,
  23.     output wire [7:0] seg
  24.     );
  25.  
  26.     reg [6:0] tabla[0:15];
  27.     initial begin
  28.         tabla[0]  = 7'b0111111;
  29.         tabla[1]  = 7'b0000110;
  30.         tabla[2]  = 7'b1011011;
  31.         tabla[3]  = 7'b1001111;
  32.         tabla[4]  = 7'b1100110;
  33.         tabla[5]  = 7'b1101101;
  34.         tabla[6]  = 7'b1111101;
  35.         tabla[7]  = 7'b0000111;
  36.         tabla[8]  = 7'b1111111;
  37.         tabla[9]  = 7'b1101111;
  38.         tabla[10] = 7'b1110111;
  39.         tabla[11] = 7'b1111100;
  40.         tabla[12] = 7'b0111001;
  41.         tabla[13] = 7'b1011110;
  42.         tabla[14] = 7'b1111001;
  43.         tabla[15] = 7'b1110001;
  44.     end
  45.  
  46.     assign seg = {~d[4],~tabla[d[3:0]]};
  47. endmodule
  48.  
  49. module display (
  50.     input wire clk,
  51.     input wire [15:0] d,
  52.     input wire [3:0] dp,
  53.     output wire [3:0] an,
  54.     output wire [7:0] seg
  55.     );
  56.    
  57.     reg [3:0] anodo = 4'b0111;
  58.     always @(posedge clk)
  59.         anodo <= {anodo[0],anodo[3:1]};
  60.        
  61.     assign an = anodo; 
  62.     bcd7seg conversor ( !anodo[3]? {dp[3], d[15:12]} :
  63.                         !anodo[2]? {dp[2], d[11:8]} :
  64.                               !anodo[1]? {dp[1], d[7:4]} :
  65.                               !anodo[0]? {dp[0], d[3:0]} :
  66.                                         5'b00000 ,
  67.                               seg);
  68. endmodule
  69.  
  70. module binary2bcd (
  71.    input wire clk,
  72.    input wire [7:0] n,
  73.    input wire start,
  74.    output wire [11:0] bcd,
  75.    output reg finish
  76.    );
  77.    
  78.    reg [3:0] loop = 4'h0;
  79.    reg [19:0] scratch = 20'h00000;
  80.    reg [19:0] scratch_modificado;
  81.    reg [11:0] output_reg = 12'h000;
  82.    assign bcd = output_reg;
  83.    
  84.    always @(posedge clk) begin
  85.       if (start) begin
  86.          loop <= 4'h0;
  87.          scratch <= {12'h000, n};
  88.          finish <= 1'b0;
  89.       end
  90.       else if (loop == 4'd8) begin
  91.          output_reg <= scratch[19:8];
  92.          loop <= loop + 1;
  93.          finish <= 1'b1;
  94.       end
  95.       else if (loop == 4'd9) begin
  96.          finish <= 1'b0;
  97.       end
  98.       else begin
  99.          loop <= loop + 1;
  100.          scratch <= {scratch_modificado[18:0],1'b0};
  101.       end
  102.    end
  103.  
  104.    always @* begin
  105.       scratch_modificado[7:0] = scratch[7:0];
  106.       if (scratch[11:8]>4)
  107.          scratch_modificado[11:8] = scratch[11:8] + 4'd3;
  108.       else
  109.          scratch_modificado[11:8] = scratch[11:8];
  110.       if (scratch[15:12]>4)
  111.          scratch_modificado[15:12] = scratch[15:12] + 4'd3;
  112.       else
  113.          scratch_modificado[15:12] = scratch[15:12];
  114.       if (scratch[19:16]>4)
  115.          scratch_modificado[19:16] = scratch[19:16] + 4'd3;
  116.       else
  117.          scratch_modificado[19:16] = scratch[19:16];
  118.    end
  119. endmodule
  120.  
  121.      
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement