3) module modulus(input [5:0] a, output reg [1:0] b, output
reg [2:0] sum);
reg [2:0] sum = 3'b0;
always @(posedge a or negedge
a) begin
sum = a[0] + a[1] + a[2] + a[3] + a[4] + a[5];
case (sum)
0: b = {1'b1, 1'b0};
1: b = {1'b0, 1'b1};
2: b = {1'b1, 1'b0};
3: b = {1'b0, 1'b1};
4: b = {1'b1, 1'b0};
5: b = {1'b0, 1'b1};
6: b = {1'b1, 1'b0};
endcase
end
endmodule
if (hcount < HLIM - 1)
hcount <= hcount + 1;
else begin
hcount <= 0;
if (vcount < VLIM - 1)
vcount <= vcount + 1;
else
vcount <= 0;
end
if (vcount > sy) begin
pixel_addr <= -1;
enable <= 0;
end
else begin
if (hcount < sx) begin
enable <= 1;
pixel_addr <= pixel_addr + 1;
end
else
enable <= 0;
end
if (enable == 1) begin
case(color)
0: begin
red <= 4'b1111;
green <= 4'b0000;
blue <= 4'b0000;
end
1: begin
red <= 4'b0000;
green <= 4'b1111;
blue <= 4'b0000;
end
endcase
end
else begin
red <= 3'b000;
green <= 3'b000;
blue <= 2'b00;
end
module sequenceDetector(y, x, clk, clr);
input x, clk, clr;
output reg y;
reg [1:0] state = 2'b00;
parameter A = 2'b00, B = 2'b01, C =
2'b10, D = 2'b11;
always @ (posedge clk) begin
if(clr ==1) state <= A;
else begin
if (x == 0)
case(state)
A : state <= A;
B : state <= C;
C : state <= A;
D : state <= C;
endcase
else
case(state)
A : state <= B;
B : state <= B;
C : state <= D;
D : state <= B;
endcase
if(x == 0 && state == D) y <= 1;
else y <= 0;
end
end
endmodule
module debounce(sw, clk, sw_out);
reg prev_switch;
input clk;
input sw;
output reg sw_out;
initial begin
prev_switch = sw;
end
always @ (posedge clk)
if(sw != prev_switch)begin
prev_switch = sw;
sw_out = 1'b0;
end
else
sw_out = sw;
endmodule
module VGA_top_module(
input clk,
input [15:0] sw,
output [3:0] vgaRed,
output [3:0] vgaGreen,
output [3:0] vgaBlue,
output Hsync,
output Vsync
);