Advertisement
Krystian102

Untitled

Apr 1st, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module zad4(
  2.     input CLOCK_50,
  3.     output [0:6] HEX0, HEX1, HEX2, HEX3);
  4.    
  5.     turn_word(CLOCK_50, HEX0, HEX1,HEX2,HEX3);
  6.    
  7. endmodule
  8.  
  9. module turn_word(
  10.     input clk,
  11.     output [0:6] h0, h1, h2, h3);
  12.    
  13.     wire left, right;
  14.     assign left=0;
  15.     assign right=1;
  16.    
  17.     reg [1:0] combination;
  18.     wire clockTact;
  19.    
  20.     display_word(combination,h0,h1,h2,h3);
  21.     counter_to_make_delay(clk,1,clockTact);
  22.    
  23.     always@(posedge clockTact)
  24.         begin
  25.             if(left==1)
  26.                 begin
  27.                     if(combination==2'b00)
  28.                         combination<=3;
  29.                     else
  30.                         combination<=combination-1;
  31.                 end
  32.             if(right==1)
  33.                 begin
  34.                     if(combination==2'b11)
  35.                         combination<=0;
  36.                     else
  37.                         combination<=combination+1;
  38.                 end
  39.         end
  40.    
  41. endmodule
  42.  
  43. module display_word(
  44.     input [1:0] combination,
  45.     output [0:6] h0, h1, h2, h3);
  46.    
  47.     reg [1:0] char0 = 2'b00; //spacja
  48.     reg [1:0] char1 = 2'b01; // 1
  49.     reg [1:0] char2 = 2'b10; // E
  50.     reg [1:0] char3 = 2'b11; // d
  51.    
  52.     decoder_hex(char0,h0);
  53.     decoder_hex(char1,h1);
  54.     decoder_hex(char2,h2);
  55.     decoder_hex(char3,h3);
  56.    
  57.     always@(*)
  58.         case(combination)
  59.             2'b00:
  60.                 begin
  61.                     char0<=2'b00;
  62.                     char1<=2'b01;
  63.                     char2<=2'b10;
  64.                     char3<=2'b11;
  65.                 end
  66.             2'b01:
  67.                 begin
  68.                     char0<=2'b01;
  69.                     char1<=2'b10;
  70.                     char2<=2'b11;
  71.                     char3<=2'b00;
  72.                 end
  73.             2'b10:
  74.                 begin
  75.                     char0<=2'b10;
  76.                     char1<=2'b11;
  77.                     char2<=2'b00;
  78.                     char3<=2'b01;
  79.                 end
  80.             2'b11:
  81.                 begin
  82.                     char0<=2'b11;
  83.                     char1<=2'b00;
  84.                     char2<=2'b01;
  85.                     char3<=2'b10;
  86.                 end
  87.             endcase
  88.    
  89. endmodule
  90.  
  91. module decoder_hex(
  92.     input [1:0] IN,
  93.     output reg [0:6] h);
  94.    
  95.     always@(*)
  96.         case(IN)
  97.             2'b00: h=7'b1111111;
  98.             2'b01: h=7'b1001111;
  99.             2'b10: h=7'b0110000;
  100.             2'b11: h=7'b1000010;
  101.         endcase
  102.    
  103. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement