Advertisement
Guest User

Untitled

a guest
May 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module swfsj7(input [1:0] SW,
  2.     input KEY0,
  3.     output [9:0] LEDR);
  4.    
  5.     zad3 ex(SW[1], KEY0, SW[0], LEDR[9]);
  6. endmodule
  7.  
  8. module zad3(
  9.     input w,clk,aclr,
  10.     output reg z);
  11.    
  12.     reg [3:0] current, next;
  13.    
  14.     localparam [3:0]    
  15.             A = 4'b0000,   
  16.             B = 4'b0001,
  17.             C = 4'b0010,
  18.             D = 4'b0011,
  19.             E = 4'b0100,
  20.             F = 4'b0101,
  21.             G = 4'b0110,
  22.             H = 4'b0111,
  23.             I = 4'b1000;
  24.  
  25.     always @(*)
  26.     begin
  27.         A:  if (!w) next = B;   else next = F;
  28.     case (current)
  29.         B:  if (!w) next = C;   else next = F;
  30.         C:  if (!w) next = D;   else next = F;
  31.         D:  if (!w) next = E;   else next = F;
  32.         E:  if (!w) next = E;   else next = F;
  33.         F:  if (!w) next = B;   else next = G;
  34.         G:  if (!w) next = B;   else next = H;
  35.         H:  if (!w) next = B;   else next = I;
  36.         I:  if (!w) next = B;   else next = I;
  37.         default:    next = 4'bxxxx;
  38.     endcase
  39.     z = (current == E) | (current == I);
  40.     end
  41.    
  42.     always @(posedge clk,negedge aclr) 
  43.         if (~aclr)      current <= 0;
  44.         else        current <= next;
  45.        
  46. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement