Maker Pro
RobotGeek

Frogger

July 01, 2022 by Nick Khormaei
 
Share
banner

This project is a Frogger game programmed using an FPGA.

This version of the Frogger game works as follows. The frog is represented by a singular green dot and the cars are a pattern of red LEDs. The frog begins on the bottom rows and using the keys the user will be able to attempt to make it to the end. KEY[3] corresponds to moving to the left, KEY[2] corresponds to moving forward, KEY[1] corresponds to moving backwards and KEY[0] represents moving to the right. Once the frog makes it to the end, it has won the game.

The user can play the game again by clicking SW[9]. An additional feature that I added was to give the user the option to change the difficulty of the game. There are 8 main difficulty modes which can be adjusted by the user which makes the speed of the cars faster. Lastly, if the frog collides with one of the cars, the frog disappears and the game is over

Block Diagram

Here is a block diagram of the system. There are D-flip flops, shift registers, sequential and combinational logic.

blockdiagram.PNG
// Top-level module that defines the I/Os for the DE-1 SoC board
module DE1_SoC (HEX0, HEX1, HEX2, HEX3, HEX4, HEX5, KEY, SW, LEDR, GPIO_1, CLOCK_50);
    output logic [6:0]  HEX0, HEX1, HEX2, HEX3, HEX4, HEX5;
	output logic [9:0]  LEDR;
    input  logic [3:0]  KEY;
    input  logic [9:0]  SW;
    output logic [35:0] GPIO_1;
    input logic CLOCK_50;

	 // Turn off HEX displays
    assign HEX0 = '1;
    assign HEX1 = '1;
    assign HEX2 = '1;
    assign HEX3 = '1;
    assign HEX4 = '1;
    assign HEX5 = '1;
	 
	 
	 /* Set up system base clock to 1526 Hz (50 MHz / 2**(14+1))
	    ===========================================================*/
	 logic [31:0] clk;
	 logic SYSTEM_CLOCK;
	 logic RST;
	 
	 clock_divider divider (.clock(CLOCK_50), .divided_clocks(clk));
	 
	 assign SYSTEM_CLOCK = clk[14]; // clock for FPGA	
	 
	 // assign SYSTEM_CLOCK = CLOCK_50; // clock for sim 
	 
	 /* If you notice flickering, set SYSTEM_CLOCK faster.
	    However, this may reduce the brightness of the LED board. */
	
	 
	 /* Set up LED board driver
	    ================================================================== */
	 logic [15:0][15:0]RedPixels; // 16 x 16 array representing red LEDs
    logic [15:0][15:0]GrnPixels; // 16 x 16 array representing green LEDs
	// logic reset;                   // reset - toggle this on startup
	 
	 assign RST = SW[9];
	 
	 logic count1, count2, gameDone;
	 logic key0, key1, key2, key3;
	 logic key_0_stable, key_1_stable, key_2_stable, key_3_stable; 
	 logic cyber_out, cyber_out_stable;
	 logic good;
	 
	 logic [9:0] out_LSFR; 
	 logic [5:0] out_LSFR_2;
	 
	 logic overlap;
	 
	 assign overlap = |(RedPixels & GrnPixels);
	 
	 /* Standard LED Driver instantiation - set once and 'forget it'. 
	    See LEDDriver.sv for more info. Do not modify unless you know what you are doing! */
	 LEDDriver Driver (.CLK(SYSTEM_CLOCK), .RST, .EnableCount(1'b1), .RedPixels, .GrnPixels, .GPIO_1);
	 
	 
	 /* LED board test submodule - paints the board with a static pattern.
	    Replace with your own code driving RedPixels and GrnPixels.
		 
	 	 KEY0      : Reset
		 =================================================================== */
	 // LED_test test (.RST(~KEY[0]), .RedPixels, .GrnPixels);
	 
	 // assign reset = RST;
	 
	 LSFR cars(.clk(SYSTEM_CLOCK), .reset(SW[9]), .Q(out_LSFR[9:0]));
  
	 LSFR_2 helper(.clk(SYSTEM_CLOCK), .reset(SW[9]), .Q(out_LSFR_2[5:0]));
	 
    comparator cool(.clk(SYSTEM_CLOCK), .reset(SW[9]), .value(cyber_out), .A(SW[8:0]), .B(out_LSFR[9:0]));
  
	 shift_register_car car1(.clk(SYSTEM_CLOCK), .reset(SW[9]), .click(cyber_key), .load(out_LSFR_2[3]), .q(RedPixels[01]));
	 shift_register_car car2(.clk(SYSTEM_CLOCK), .reset(SW[9]), .click(cyber_key), .load(out_LSFR_2[2]), .q(RedPixels[03]));
	 shift_register_car car3(.clk(SYSTEM_CLOCK), .reset(SW[9]), .click(cyber_key), .load(out_LSFR_2[4]), .q(RedPixels[05]));
	 shift_register_car car4(.clk(SYSTEM_CLOCK), .reset(SW[9]), .click(cyber_key), .load(out_LSFR_2[3]), .q(RedPixels[07]));
	 shift_register_car car5(.clk(SYSTEM_CLOCK), .reset(SW[9]), .click(cyber_key), .load(out_LSFR_2[3]), .q(RedPixels[09]));
	 shift_register_car car6(.clk(SYSTEM_CLOCK), .reset(SW[9]), .click(cyber_key), .load(out_LSFR_2[2]), .q(RedPixels[10]));
	 shift_register_car car7(.clk(SYSTEM_CLOCK), .reset(SW[9]), .click(cyber_key), .load(out_LSFR_2[3]), .q(RedPixels[11]));
	 shift_register_car car8(.clk(SYSTEM_CLOCK), .reset(SW[9]), .click(cyber_key), .load(out_LSFR_2[3]), .q(RedPixels[13]));
	 
	 
	 double_flip ff1 (.clk(SYSTEM_CLOCK), .reset(SW[9]), .in(KEY[3]), .out(key_3_stable));
     double_flip ff2 (.clk(SYSTEM_CLOCK), .reset(SW[9]), .in(KEY[2]), .out(key_2_stable));
	 double_flip ff3 (.clk(SYSTEM_CLOCK), .reset(SW[9]), .in(KEY[1]), .out(key_1_stable));
     double_flip ff4 (.clk(SYSTEM_CLOCK), .reset(SW[9]), .in(KEY[0]), .out(key_0_stable));
	 
	 double_flip ff5 (.clk(SYSTEM_CLOCK), .reset(SW[9]), .in(cyber_out), .out(cyber_out_stable));
	 
	 user_input switchThree (.clk(SYSTEM_CLOCK), .reset(SW[9]), .in(key_3_stable), .out(key3));
	 user_input switchTwo (.clk(SYSTEM_CLOCK), .reset(SW[9]), .in(key_2_stable), .out(key2));
	 user_input switchOne (.clk(SYSTEM_CLOCK), .reset(SW[9]), .in(key_1_stable), .out(key1));
	 user_input switchZero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .in(key_0_stable), .out(key0));
	 
	 user_input switchCyber (.clk(SYSTEM_CLOCK), .reset(SW[9]), .in(cyber_out_stable), .out(cyber_key));
	 
	 // where the frog begins
	 center_light fifteen_seven(.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][8]), .LEFT_LED(GrnPixels[15][6]), .UP_LED(GrnPixels[14][7]), .DOWN_LED(GrnPixels[15][7]), .CUR_LED(GrnPixels[15][7]), .winner_frog(count1), .winner_car(count2));
	 
	 // row 1
	 normal_light one_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[1][0]), .LEFT_LED(GrnPixels[1][1]), .UP_LED(GrnPixels[0][0]), .DOWN_LED(GrnPixels[2][0]), .CUR_LED(GrnPixels[1][0]), .winner_frog(count1), .winner_car(count2), .lose(overlap));
	 normal_light one_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[1][15]), .LEFT_LED(GrnPixels[1][14]), .UP_LED(GrnPixels[0][15]), .DOWN_LED(GrnPixels[2][15]), .CUR_LED(GrnPixels[1][15]), .winner_frog(count1), .winner_car(count2), .lose(overlap));
	 
	 // row 2
	 normal_light two_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[2][0]), .LEFT_LED(GrnPixels[2][1]), .UP_LED(GrnPixels[1][0]), .DOWN_LED(GrnPixels[3][0]), .CUR_LED(GrnPixels[2][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light two_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[2][14]), .LEFT_LED(GrnPixels[2][15]), .UP_LED(GrnPixels[1][15]), .DOWN_LED(GrnPixels[3][15]), .CUR_LED(GrnPixels[2][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 
	 
	 // row 3
	 normal_light three_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[3][0]), .LEFT_LED(GrnPixels[3][1]), .UP_LED(GrnPixels[2][0]), .DOWN_LED(GrnPixels[4][0]), .CUR_LED(GrnPixels[3][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light three_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[3][14]), .LEFT_LED(GrnPixels[3][15]), .UP_LED(GrnPixels[2][15]), .DOWN_LED(GrnPixels[4][15]), .CUR_LED(GrnPixels[3][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 
	 
	 // row 4
	 normal_light four_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[4][0]), .LEFT_LED(GrnPixels[4][1]), .UP_LED(GrnPixels[3][0]), .DOWN_LED(GrnPixels[5][0]), .CUR_LED(GrnPixels[4][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light four_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[4][14]), .LEFT_LED(GrnPixels[4][15]), .UP_LED(GrnPixels[3][15]), .DOWN_LED(GrnPixels[5][15]), .CUR_LED(GrnPixels[4][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 
	 
	 // row 5
	 normal_light five_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[5][0]), .LEFT_LED(GrnPixels[5][1]), .UP_LED(GrnPixels[4][0]), .DOWN_LED(GrnPixels[6][0]), .CUR_LED(GrnPixels[5][0]), .winner_frog(count1), .winner_car(count2), .lose(overlap));
	 normal_light five_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[5][14]), .LEFT_LED(GrnPixels[5][15]), .UP_LED(GrnPixels[4][15]), .DOWN_LED(GrnPixels[6][15]), .CUR_LED(GrnPixels[5][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 
	 
	 // row 6
	 normal_light six_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[6][0]), .LEFT_LED(GrnPixels[6][1]), .UP_LED(GrnPixels[5][0]), .DOWN_LED(GrnPixels[7][0]), .CUR_LED(GrnPixels[6][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light six_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[6][14]), .LEFT_LED(GrnPixels[6][15]), .UP_LED(GrnPixels[5][15]), .DOWN_LED(GrnPixels[7][15]), .CUR_LED(GrnPixels[6][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 
	 
	 // row 7
	 normal_light seven_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[7][0]), .LEFT_LED(GrnPixels[7][1]), .UP_LED(GrnPixels[6][0]), .DOWN_LED(GrnPixels[8][0]), .CUR_LED(GrnPixels[7][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light seven_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[7][14]), .LEFT_LED(GrnPixels[7][15]), .UP_LED(GrnPixels[6][15]), .DOWN_LED(GrnPixels[8][15]), .CUR_LED(GrnPixels[7][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	

	 // row 8
	 normal_light eight_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[8][0]), .LEFT_LED(GrnPixels[8][1]), .UP_LED(GrnPixels[7][0]), .DOWN_LED(GrnPixels[9][0]), .CUR_LED(GrnPixels[8][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light eight_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[8][14]), .LEFT_LED(GrnPixels[8][15]), .UP_LED(GrnPixels[7][15]), .DOWN_LED(GrnPixels[9][15]), .CUR_LED(GrnPixels[8][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 
	 
	 // row 9
	 normal_light nine_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[9][0]), .LEFT_LED(GrnPixels[9][1]), .UP_LED(GrnPixels[8][0]), .DOWN_LED(GrnPixels[10][0]), .CUR_LED(GrnPixels[9][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light nine_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[9][14]), .LEFT_LED(GrnPixels[9][15]), .UP_LED(GrnPixels[8][15]), .DOWN_LED(GrnPixels[10][15]), .CUR_LED(GrnPixels[9][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 
	 // row 10
	 normal_light ten_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[10][0]), .LEFT_LED(GrnPixels[10][1]), .UP_LED(GrnPixels[9][0]), .DOWN_LED(GrnPixels[11][0]), .CUR_LED(GrnPixels[10][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light ten_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[10][14]), .LEFT_LED(GrnPixels[10][15]), .UP_LED(GrnPixels[9][15]), .DOWN_LED(GrnPixels[11][15]), .CUR_LED(GrnPixels[10][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 
	 // row 11
	 normal_light eleven_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[11][0]), .LEFT_LED(GrnPixels[11][1]), .UP_LED(GrnPixels[10][0]), .DOWN_LED(GrnPixels[12][0]), .CUR_LED(GrnPixels[11][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light eleven_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[11][14]), .LEFT_LED(GrnPixels[11][15]), .UP_LED(GrnPixels[10][15]), .DOWN_LED(GrnPixels[12][15]), .CUR_LED(GrnPixels[11][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 
	 // row 12 
	 normal_light twelve_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[12][0]), .LEFT_LED(GrnPixels[12][1]), .UP_LED(GrnPixels[11][0]), .DOWN_LED(GrnPixels[13][0]), .CUR_LED(GrnPixels[12][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light twelve_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[12][14]), .LEFT_LED(GrnPixels[12][15]), .UP_LED(GrnPixels[11][15]), .DOWN_LED(GrnPixels[13][15]), .CUR_LED(GrnPixels[12][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 
	 // row 13 
	 normal_light threeteen_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[13][0]), .LEFT_LED(GrnPixels[13][1]), .UP_LED(GrnPixels[12][0]), .DOWN_LED(GrnPixels[14][0]), .CUR_LED(GrnPixels[13][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light threeteen_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[13][14]), .LEFT_LED(GrnPixels[13][15]), .UP_LED(GrnPixels[12][15]), .DOWN_LED(GrnPixels[14][15]), .CUR_LED(GrnPixels[13][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 
	// row 14 
	 normal_light fourteen_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[14][0]), .LEFT_LED(GrnPixels[14][1]), .UP_LED(GrnPixels[13][0]), .DOWN_LED(GrnPixels[15][0]), .CUR_LED(GrnPixels[14][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fourteen_fifteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[14][14]), .LEFT_LED(GrnPixels[14][15]), .UP_LED(GrnPixels[13][15]), .DOWN_LED(GrnPixels[15][15]), .CUR_LED(GrnPixels[14][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 
	// row 15
	 normal_light fifthteen_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][1]), .LEFT_LED(GrnPixels[15][0]), .UP_LED(GrnPixels[14][0]), .DOWN_LED(GrnPixels[15][0]), .CUR_LED(GrnPixels[15][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fifthteen_one (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][2]), .LEFT_LED(GrnPixels[15][0]), .UP_LED(GrnPixels[14][1]), .DOWN_LED(GrnPixels[15][1]), .CUR_LED(GrnPixels[15][1]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fifthteen_two (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][3]), .LEFT_LED(GrnPixels[15][1]), .UP_LED(GrnPixels[14][2]), .DOWN_LED(GrnPixels[15][2]), .CUR_LED(GrnPixels[15][2]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fifthteen_three (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][4]), .LEFT_LED(GrnPixels[15][2]), .UP_LED(GrnPixels[14][3]), .DOWN_LED(GrnPixels[15][3]), .CUR_LED(GrnPixels[15][3]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fifthteen_four (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][5]), .LEFT_LED(GrnPixels[15][3]), .UP_LED(GrnPixels[14][4]), .DOWN_LED(GrnPixels[15][4]), .CUR_LED(GrnPixels[15][4]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fifthteen_five (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][6]), .LEFT_LED(GrnPixels[15][4]), .UP_LED(GrnPixels[14][5]), .DOWN_LED(GrnPixels[15][5]), .CUR_LED(GrnPixels[15][5]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fifthteen_six (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][7]), .LEFT_LED(GrnPixels[15][5]), .UP_LED(GrnPixels[14][6]), .DOWN_LED(GrnPixels[15][6]), .CUR_LED(GrnPixels[15][6]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 
	 normal_light fifthteen_eight (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][9]), .LEFT_LED(GrnPixels[15][7]), .UP_LED(GrnPixels[14][8]), .DOWN_LED(GrnPixels[15][8]), .CUR_LED(GrnPixels[15][8]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fifthteen_nine (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][10]), .LEFT_LED(GrnPixels[15][8]), .UP_LED(GrnPixels[14][9]), .DOWN_LED(GrnPixels[15][9]), .CUR_LED(GrnPixels[15][9]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fifthteen_ten (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][11]), .LEFT_LED(GrnPixels[15][9]), .UP_LED(GrnPixels[14][10]), .DOWN_LED(GrnPixels[15][10]), .CUR_LED(GrnPixels[15][10]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fifthteen_eleven (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][12]), .LEFT_LED(GrnPixels[15][10]), .UP_LED(GrnPixels[14][11]), .DOWN_LED(GrnPixels[15][11]), .CUR_LED(GrnPixels[15][11]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fifthteen_twelve (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][13]), .LEFT_LED(GrnPixels[15][11]), .UP_LED(GrnPixels[14][12]), .DOWN_LED(GrnPixels[15][12]), .CUR_LED(GrnPixels[15][12]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fifthteen_threeteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][14]), .LEFT_LED(GrnPixels[15][12]), .UP_LED(GrnPixels[14][13]), .DOWN_LED(GrnPixels[15][13]), .CUR_LED(GrnPixels[15][13]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fifthteen_fourteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][15]), .LEFT_LED(GrnPixels[15][13]), .UP_LED(GrnPixels[14][14]), .DOWN_LED(GrnPixels[15][14]), .CUR_LED(GrnPixels[15][14]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light fifthteen_fifthteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[15][15]), .LEFT_LED(GrnPixels[15][14]), .UP_LED(GrnPixels[14][15]), .DOWN_LED(GrnPixels[15][15]), .CUR_LED(GrnPixels[15][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	  
	// row 0
	 normal_light zero_zero (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][0]), .LEFT_LED(GrnPixels[0][1]), .UP_LED(GrnPixels[0][0]), .DOWN_LED(GrnPixels[1][0]), .CUR_LED(GrnPixels[0][0]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_one (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][0]), .LEFT_LED(GrnPixels[0][2]), .UP_LED(GrnPixels[0][1]), .DOWN_LED(GrnPixels[1][1]), .CUR_LED(GrnPixels[0][1]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_two (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][1]), .LEFT_LED(GrnPixels[0][3]), .UP_LED(GrnPixels[0][2]), .DOWN_LED(GrnPixels[1][2]), .CUR_LED(GrnPixels[0][2]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_three (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][2]), .LEFT_LED(GrnPixels[0][4]), .UP_LED(GrnPixels[0][3]), .DOWN_LED(GrnPixels[1][3]), .CUR_LED(GrnPixels[0][3]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_four (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][3]), .LEFT_LED(GrnPixels[0][5]), .UP_LED(GrnPixels[0][4]), .DOWN_LED(GrnPixels[1][4]), .CUR_LED(GrnPixels[0][4]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_five (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][4]), .LEFT_LED(GrnPixels[0][6]), .UP_LED(GrnPixels[0][5]), .DOWN_LED(GrnPixels[1][5]), .CUR_LED(GrnPixels[0][5]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_six (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][5]), .LEFT_LED(GrnPixels[0][7]), .UP_LED(GrnPixels[0][6]), .DOWN_LED(GrnPixels[1][6]), .CUR_LED(GrnPixels[0][6]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_seven (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][6]), .LEFT_LED(GrnPixels[0][8]), .UP_LED(GrnPixels[0][7]), .DOWN_LED(GrnPixels[1][7]), .CUR_LED(GrnPixels[0][7]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_eight (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][7]), .LEFT_LED(GrnPixels[0][9]), .UP_LED(GrnPixels[0][8]), .DOWN_LED(GrnPixels[1][8]), .CUR_LED(GrnPixels[0][8]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_nine (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][8]), .LEFT_LED(GrnPixels[0][10]), .UP_LED(GrnPixels[0][9]), .DOWN_LED(GrnPixels[1][9]), .CUR_LED(GrnPixels[0][9]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_ten (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][9]), .LEFT_LED(GrnPixels[0][11]), .UP_LED(GrnPixels[0][10]), .DOWN_LED(GrnPixels[1][10]), .CUR_LED(GrnPixels[0][10]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_eleven (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][10]), .LEFT_LED(GrnPixels[0][12]), .UP_LED(GrnPixels[0][11]), .DOWN_LED(GrnPixels[1][11]), .CUR_LED(GrnPixels[0][11]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_twelve (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][11]), .LEFT_LED(GrnPixels[0][13]), .UP_LED(GrnPixels[0][12]), .DOWN_LED(GrnPixels[1][12]), .CUR_LED(GrnPixels[0][12]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_threeteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][12]), .LEFT_LED(GrnPixels[0][14]), .UP_LED(GrnPixels[0][13]), .DOWN_LED(GrnPixels[1][13]), .CUR_LED(GrnPixels[0][13]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_fourteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][13]), .LEFT_LED(GrnPixels[0][15]), .UP_LED(GrnPixels[0][14]), .DOWN_LED(GrnPixels[1][14]), .CUR_LED(GrnPixels[0][14]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	 normal_light zero_fifthteen (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), .DOWN_KEY(key1), .RIGHT_LED(GrnPixels[0][14]), .LEFT_LED(GrnPixels[0][15]), .UP_LED(GrnPixels[0][15]), .DOWN_LED(GrnPixels[1][15]), .CUR_LED(GrnPixels[0][15]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
	   
genvar i,j;
    
    generate 
        for(i = 1; i < 15; i++) begin : rows  
            for(j = 1; j < 15; j++) begin: columns 
               normal_light ball (.clk(SYSTEM_CLOCK), .reset(SW[9]), .RIGHT_KEY(key0), .LEFT_KEY(key3), .UP_KEY(key2), 
					.DOWN_KEY(key1), .RIGHT_LED(GrnPixels[i][j-1]), .LEFT_LED(GrnPixels[i][j+1]), .UP_LED(GrnPixels[i-1][j]), 
					.DOWN_LED(GrnPixels[i+1][j]), .CUR_LED(GrnPixels[i][j]), .winner_frog(count1), .winner_car(count2),.lose(overlap));
       end
     end
   endgenerate

	 
endmodule


// testbench
module DE1_SoC_testbench();
    logic CLOCK_50;
    logic [6:0] HEX0, HEX1, HEX2, HEX3, HEX4, HEX5;
    logic [9:0] LEDR;
    logic [3:0] KEY;
    logic [9:0] SW;
    logic [35:0] GPIO_1;
	 
	 
    DE1_SoC dut(.CLOCK_50, .HEX0, .HEX1, .HEX2, .HEX3, .HEX4, .HEX5, .KEY, .LEDR, .SW, .GPIO_1);

    // Set up a simulated clock.
    parameter CLOCK_PERIOD=100;
    initial begin
        CLOCK_50 <= 0;
        forever #(CLOCK_PERIOD/2) CLOCK_50 <= ~CLOCK_50; // Forever toggle the clock
    end

// Test the design.
initial begin
    SW[9] <= 1; repeat(2)  @(posedge CLOCK_50);
    SW[9] <= 0; repeat(2)  @(posedge CLOCK_50);
    
    KEY[3] <= 1; repeat(1) @(posedge CLOCK_50);  
    KEY[3] <= 0; repeat(1) @(posedge CLOCK_50);  
    KEY[3] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[3] <= 0; repeat(1) @(posedge CLOCK_50);
	 SW[9] <= 1; repeat(2)  @(posedge CLOCK_50);
    SW[9] <= 0; repeat(2)  @(posedge CLOCK_50);
	 
	 KEY[2] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[2] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[2] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[2] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[2] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[2] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[2] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[2] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[2] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[2] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[2] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[2] <= 0; repeat(1) @(posedge CLOCK_50);
    SW[9] <= 1; repeat(1) @(posedge CLOCK_50);
    SW[9] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[2] <= 0; repeat(1) @(posedge CLOCK_50); 
    KEY[2] <= 1; repeat(1) @(posedge CLOCK_50);
	 
	 KEY[1] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[1] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[1] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[1] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[1] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[1] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[1] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[1] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[1] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[1] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[1] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[1] <= 0; repeat(1) @(posedge CLOCK_50);
	 KEY[1] <= 1; repeat(1) @(posedge CLOCK_50);
	 SW[9] <= 1; repeat(2)  @(posedge CLOCK_50);
    SW[9] <= 0; repeat(2)  @(posedge CLOCK_50);
	 
	 KEY[0] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[0] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[0] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[0] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[0] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[0] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[0] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[0] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[0] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[0] <= 0; repeat(1) @(posedge CLOCK_50);
    KEY[0] <= 1; repeat(1) @(posedge CLOCK_50);
    KEY[0] <= 0; repeat(1) @(posedge CLOCK_50);
	 
	 
    $stop; // End the simulation.
    end
    
    initial begin 
        SW[8:0] <= 9'b010101010; repeat(50) @(posedge CLOCK_50);
    
    $stop;
    end
endmodule
fpga1.png

Figure 1. DE1 SoC Board with 16x16 LED peripheral 

game.PNG

Figure 2. 16x16 display

The green dot represents the frog, and the red dots represent the cars. The user will use the keys on the DE1 SoC board to control the movement of the frog. 

Related Content

Tags

Comments


You May Also Like