loom
78 строк · 1.8 Кб
1module fsm(
2input logic clk,
3input logic rst,
4input logic [5:0] c,
5output logic [2:0] st,
6output logic [7:0] num
7);
8logic [2:0] State;
9always_comb
10st = State;
11always_ff @ (posedge clk, negedge rst)
12begin
13if(!rst) begin
14num <= 0;
15State <= 1;
16end
17else if(State == 1) begin
18if(c[4] == 1 && c[5] == 1) begin
19num <= 'b00000101;
20State <= 2;
21end
22else if(c[2] == 1 && c[3] == 0) begin
23num <= 'b00011000;
24State <= 4;
25end
26else if(c[0] == 1 || c[2] == 0) begin
27num <= 'b01100000;
28State <= 6;
29end
30else if(c[3] == 1)
31State <= 5;
32else begin
33num <= 'b00001000;
34State <= 1;
35end
36end
37else if(State == 2) begin
38if(c[0] == 1 && c[1] == 1 && c[2] == 1)
39State <= 2;
40else
41State <= 3;
42end
43else if (State == 3) begin
44if(c[0] == 1 && c[1] == 0) begin
45num <= 'b10010000;
46State <= 1;
47end
48else begin
49num <= 'b00000001;
50State <= 3;
51end
52end
53else if(State == 4) begin
54if(c[0] == 1 && c[5] == 0)
55State <= 4;
56else begin
57num <= 'b10001000;
58State <= 3;
59end
60end
61else if(State == 5) begin
62if (c[0] == 1 && c[1] == 1 && c[2] == 1) begin
63num <= 'b00000001;
64State <= 1;
65end
66else
67State <= 5;
68end
69else if(State == 6) begin
70if (c[4] == 1 || c[5] == 1) begin
71num <= 'b00000001;
72State <= 5;
73end
74else
75State <= 6;
76end
77end
78endmodule
79
80