Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. module stany(
  2. input w,clk,aclr,
  3. output reg [9:0] y);
  4.  
  5. reg [8:0] d;
  6. (*keep*) reg[3:0] state, next;
  7. localparam[3:0]
  8. s0 = 4'h0,
  9. s1 = 4'h1,
  10. s2 = 4'h2,
  11. s3 = 4'h3,
  12. s4 = 4'h4,
  13. s5 = 4'h5,
  14. s6 = 4'h6,
  15. s7 = 4'h7,
  16. s8 = 4'h8;
  17. always @(posedge clk, negedge aclr)
  18. if(~aclr) state<= s0;
  19. else state <= next;
  20.  
  21. always @(*)
  22. begin
  23. case(state)
  24. s0: if(w) next=s1;
  25. else next = s5;
  26. s1: if(w) next=s2;
  27. else next = s5;
  28. s2: if(w) next=s3;
  29. else next = s5;
  30. s3: if(w) next=s4;
  31. else next = s5;
  32. s4: if(w) next=s4;
  33. else next = s5;
  34. s5: if(~w) next=s6;
  35. else next = s1;
  36. s6: if(~w) next=s7;
  37. else next = s1;
  38. s7: if(~w) next=s8;
  39. else next = s1;
  40. s8: if(~w) next=s8;
  41. else next = s1;
  42.  
  43. endcase;
  44.  
  45.  
  46. end
  47.  
  48. always @(*)
  49. case(state)
  50. s0:
  51. begin
  52. y=0;
  53. y[0]=1'b1;
  54. end
  55. s1:
  56. begin
  57. y=0;
  58. y[1]=1'b1;
  59. end
  60. s2:
  61. begin
  62. y=0;
  63. y[2]=1'b1;
  64. end
  65. s3:
  66. begin
  67. y=0;
  68. y[3]=1'b1;
  69. end
  70. s4:
  71. begin
  72. y=0;
  73. y[4]=1'b1;
  74. y[9] = 1'b1;
  75. end
  76. s5:
  77. begin
  78. y=0;
  79. y[5]=1'b1;
  80. end
  81. s6:
  82. begin
  83. y=0;
  84. y[6]=1'b1;
  85. end
  86. s7:
  87. begin
  88. y=0;
  89. y[7]=1'b1;
  90. end
  91. s8:
  92. begin
  93. y=0;
  94. y[8]=1'b1;
  95. y[9] = 1'b1;
  96. end
  97.  
  98.  
  99. endcase
  100.  
  101. endmodule
  102.  
  103. module zad1(
  104. input [1:0] SW,
  105. input [1:0] KEY,
  106. output [9:0] LEDR);
  107.  
  108. stany s(SW[1],KEY[0],SW[0],LEDR[9:0]);
  109.  
  110. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement