Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. module FSM_lab7_part1a(
  2. input w,clk,aclr,
  3. output reg z,
  4. output reg [8:0] y);
  5. reg [8:0] state, next;
  6.  
  7. localparam [8:0] A = 9'b000000000, // kody stanów
  8. B = 9'b000000011,
  9. C = 9'b000000101,
  10. D = 9'b000001001,
  11. E = 9'b000010001,
  12. F = 9'b000100001,
  13. G = 9'b001000001,
  14. H = 9'b010000001,
  15. I = 9'b100000001;
  16.  
  17.  
  18. always @(*) // defenicia przejść
  19. case (state)
  20.  
  21. A: if (!w) next = B; else next = F;
  22. B: if (!w) next = C; else next = F;
  23. C: if (!w) next = D; else next = F;
  24. D: if (!w) next = E; else next = F;
  25. E: if (!w) next = E; else next = F;
  26. F: if (!w) next = B; else next = G;
  27. G: if (!w) next = B; else next = H;
  28. H: if (!w) next = B; else next = I;
  29. I: if (!w) next = B; else next = I;
  30.  
  31. /*default: next = 9'bxxxxxxxxx;*/
  32. endcase
  33.  
  34. always @(posedge clk,negedge aclr) // defenicja pamęci
  35. if (~aclr)
  36. state <= 0;
  37.  
  38. else
  39. state <= next;
  40.  
  41. always @(*) // defenicja wyjść
  42. z = (state == E) | (state == I);
  43.  
  44. always @(*)
  45. // opis funkcji wyjściowych
  46.  
  47. case (state)
  48.  
  49. A: y= 9'b000000000;
  50. B: y= 9'b000000011;
  51. C: y= 9'b000000101;
  52. D: y= 9'b000001001;
  53. E: y= 9'b000010001;
  54. F: y= 9'b000100001;
  55. G: y= 9'b001000001;
  56. H: y= 9'b010000001;
  57. I: y= 9'b100000001;
  58. endcase
  59.  
  60. endmodule
  61.  
  62.  
  63.  
  64. module zadanie1v1(
  65. input [1:0] SW,
  66. input [1:0] KEY,
  67. output [9:0] LEDR);
  68.  
  69. FSM_lab7_part1a ex(SW[1],KEY[0],SW[0],LEDR[9],LEDR[8:0]);
  70.  
  71. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement