Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module projectf(clk,r,g,sw,k,hex0,hex1,hex2,hex3);
- input clk;
- input [9:0] sw;
- input [3:0] k;
- output [9:0] r;
- output [7:0] g;
- output [6:0] hex0,hex1,hex2,hex3;
- reg kn0, kn1, kn2, kn3, trig0, trig1, trig2, trig3, a, a0, a1, a2, b, bb;
- reg [6:0] d0, d1, d2, d3, t0, t1, t2, t3, s0, s1, s2, s3;
- reg [6:0] d83, d82, d81, d80, d63, d62, d61, d60, d43, d42, d41, d40, d33, d32, d31, d30;
- reg [6:0] d23, d22, d21, d20, d13, d12, d11, d10;
- reg [9:0] state1, state2, c, j0;
- reg [10:0] x, x1, x0, y, y1, y0, c1, c2, cc1, cc2, j1, j2, j3, j4, c10, c11, c20, c21;
- reg [30:0] ctr;
- assign hex0 = d0;
- assign hex1 = d1;
- assign hex2 = d2;
- assign hex3 = d3;
- assign r = state1;
- assign g = state2;
- parameter n1 = 7'b1001111;
- parameter n2 = 7'b0010010;
- parameter n3 = 7'b0000110;
- parameter n4 = 7'b1001100;
- parameter n5 = 7'b0100100;
- parameter n6 = 7'b0100000;
- parameter n7 = 7'b0001111;
- parameter n8 = 7'b0000000;
- parameter n9 = 7'b0000100;
- parameter n0 = 7'b0000001;
- initial c <= 0;
- initial begin j3 = 1; j2 = 2; j1 = 1; j0 = 2; end
- initial begin d13 <= n0; d12 <= n0; end
- always @ (posedge clk) // Counter //
- if (ctr == 50_000_000)
- ctr <= 0;
- else if (a == 0 && c == 0)
- ctr <= ctr+1;
- always @ (posedge clk) // Trigger Buttons //
- begin
- kn0 <= ~k[0];
- kn1 <= ~k[1];
- kn2 <= ~k[2];
- kn3 <= ~k[3];
- trig0 <= k[0] & kn0;
- trig1 <= k[1] & kn1;
- trig2 <= k[2] & kn2;
- trig3 <= k[3] & kn3;
- end
- always @ (posedge clk)
- if (sw == 10'b1000000000) // Master Reset //
- begin
- t3 <= n1; t2 <= n0; t1 <= n0; t0 <= n0;
- s3 <= 127; s2 <= 127; s1 <= n2; s0 <= n4;
- d63 <= n1; b <= 0; d13 <= n6; d12 <= n0;
- end
- else if (sw == 10'b0010000000 && trig0 == 1 && b == 0) // Reset Basketball Timer //
- begin
- t3 <= n1; t2 <= n0; t1 <= n0; t0 <= n0;
- s3 <= 127; s2 <= 127; s1 <= n2; s0 <= n4;
- end
- else if (sw == 10'b0000100000 && trig0 == 1 && b == 0) // Reset Shot Clock //
- begin
- s3 <= 127; s2 <= 127; s1 <= n2; s0 <= n4;
- end
- else if (sw == 10'b0000100000 && trig2 == 1 && b == 0) // Decrement Shot Clock //
- begin
- if (s1 == n0 && s0 == n0)
- s0 <= n0;
- else
- case (s0)
- n9: s0 <= n8;
- n8: s0 <= n7;
- n7: s0 <= n6;
- n6: s0 <= n5;
- n5: s0 <= n4;
- n4: s0 <= n3;
- n3: s0 <= n2;
- n2: s0 <= n1;
- n1: s0 <= n0;
- n0: s0 <= n9;
- endcase
- if (s0 == n0)
- case (s1)
- n2: s1 <= n1;
- default: s1 <= n0;
- endcase
- end
- else if (sw == 10'b0000100000 && trig3 == 1 && b == 0) // Increment Shot Clock //
- begin
- if (s1 == n2 && s0 == n4)
- s0 <= n4;
- else
- case (s0)
- n9: s0 <= n0;
- n8: s0 <= n9;
- n7: s0 <= n8;
- n6: s0 <= n7;
- n5: s0 <= n6;
- n4: s0 <= n5;
- n3: s0 <= n4;
- n2: s0 <= n3;
- n1: s0 <= n2;
- n0: s0 <= n1;
- endcase
- if (s0 == n0)
- case (s1)
- n0: s1 <= n1;
- default: s1 <= n2;
- endcase
- end
- else if (sw == 10'b0000000100 && (trig3 == 1 || trig1 == 1) && b == 0) // 60 secs timeout //
- begin
- d13 <= n6; d12 <= n0;
- end
- else if (sw == 10'b0000000100 && (trig2 == 1 || trig0 == 1) && b == 0) // 30 secs timeout //
- begin
- d13 <= n3; d12 <= n0;
- end
- else if (ctr == 50_000_000 && b == 0 && a0 == 1 && bb == 0) // Shot Clock Count //
- begin
- case (d12)
- n9: d12 <= n8;
- n8: d12 <= n7;
- n7: d12 <= n6;
- n6: d12 <= n5;
- n5: d12 <= n4;
- n4: d12 <= n3;
- n3: d12 <= n2;
- n2: d12 <= n1;
- n1: d12 <= n0;
- n0: d12 <= n9;
- endcase
- if (d12 == n0)
- case (d13)
- n6: d13 <= n5;
- n5: d13 <= n4;
- n4: d13 <= n3;
- n3: d13 <= n2;
- n2: d13 <= n1;
- n1: d13 <= n0;
- endcase
- end
- else if (ctr == 50_000_000 && b == 0 && a0 == 0) // Basketball Timer Count //
- begin
- case (t3)
- n1: t3 <= n0;
- endcase
- case (t0)
- n9: t0 <= n8;
- n8: t0 <= n7;
- n7: t0 <= n6;
- n6: t0 <= n5;
- n5: t0 <= n4;
- n4: t0 <= n3;
- n3: t0 <= n2;
- n2: t0 <= n1;
- n1: t0 <= n0;
- n0: t0 <= n9;
- endcase
- if (s1 == n0)
- case (s0)
- n9: s0 <= n8;
- n8: s0 <= n7;
- n7: s0 <= n6;
- n6: s0 <= n5;
- n5: s0 <= n4;
- n4: s0 <= n3;
- n3: s0 <= n2;
- n2: s0 <= n1;
- n1: s0 <= n0;
- n0: s0 <= n4;
- endcase
- if (s1 != n0)
- case (s0)
- n9: s0 <= n8;
- n8: s0 <= n7;
- n7: s0 <= n6;
- n6: s0 <= n5;
- n5: s0 <= n4;
- n4: s0 <= n3;
- n3: s0 <= n2;
- n2: s0 <= n1;
- n1: s0 <= n0;
- n0: s0 <= n9;
- endcase
- if (s0 == n0)
- case (s1)
- n2: s1 <= n1;
- n1: s1 <= n0;
- n0: s1 <= n2;
- endcase
- if (t0 == n0)
- case (t1)
- n5: t1 <= n4;
- n4: t1 <= n3;
- n3: t1 <= n2;
- n2: t1 <= n1;
- n1: t1 <= n0;
- n0: t1 <= n5;
- endcase
- if (t1 == n0 && t0 == n0)
- case (t2)
- n9: t2 <= n8;
- n8: t2 <= n7;
- n7: t2 <= n6;
- n6: t2 <= n5;
- n5: t2 <= n4;
- n4: t2 <= n3;
- n3: t2 <= n2;
- n2: t2 <= n1;
- n1: t2 <= n0;
- n0: t2 <= n9;
- endcase
- if (t3 == n0 && t2 == n0 && t1 == n0 && t0 == n0)
- begin
- t3 <= n1; t2 <= n0; t1 <= n0; t0 <= n0;
- case (d63)
- n1: d63 <= n2;
- n2: d63 <= n3;
- n3: d63 <= n4;
- default: b <= 1; // Game Ends //
- endcase
- end
- if (s3 == 127 && s2 == 127 && s1 == n0 && s0 == n0)
- begin
- s3 <= 127; s2 <= 127; s1 <= n2; s0 <= n4;
- end
- end
- always @ (posedge clk)
- begin
- if (sw == 10'b1000000000) // SW9 - Master Reset //
- begin
- d80 <= n0; d81 <= n0; d82 <= n0; d83 <= n0;
- d40 <= n0; d41 <= n0; d42 <= n0; d43 <= n0;
- d30 <= n0; d31 <= n0; d32 <= n0; d33 <= n0;
- d20 <= n2; d21 <= n1; d22 <= n2; d23 <= n1;
- state1 <= 10'b0000000000; state2 <= 8'b00000000;
- x <=0 ; x1 <= 0; x0 <= 0; y <= 0; y1 <= 0; y0 <= 0;
- j0 = 2 ; j1 = 1; j2 = 2; j3 = 1;
- c1 =0 ; c11 = 0; c10 = 0; c2 = 0; c21 = 0; c20 = 0;
- cc1 = 0; cc2 = 0; bb <= 1;
- a <= 0; a0 <= 0;
- d3 <= 127; d2 <= 127; d1 <= 127; d0 <= 127;
- end
- else if (sw == 10'b0100000000) // SW8 - Basketball Scoreboard //
- begin
- if (trig3 == 1 && b == 0) // increment 1st team //
- begin
- x = x + 1;
- if (x >= 99)
- x = 99;
- x0 = x%10;
- x1 = (x-x0)/10;
- end
- else if (trig2 == 1 && b == 0) // decrement 1st team //
- begin
- if (x <= 1)
- x = 0;
- else
- x = x - 1;
- x0 = x%10;
- x1 = (x-x0)/10;
- end
- else if (trig1 == 1 && b == 0) // increment 2nd team //
- begin
- y = y + 1;
- if (y >= 99)
- y = 99;
- y0 = y%10;
- y1 = (y-y0)/10;
- end
- else if (trig0 == 1 && b == 0) // decrement 2nd team //
- begin
- if (y <= 1)
- y = 0;
- else
- y = y - 1;
- y0 = y%10;
- y1 = (y-y0)/10;
- end
- case (x1) // value of HEX3 //
- 0: d83<=n0;
- 1: d83<=n1;
- 2: d83<=n2;
- 3: d83<=n3;
- 4: d83<=n4;
- 5: d83<=n5;
- 6: d83<=n6;
- 7: d83<=n7;
- 8: d83<=n8;
- 9: d83<=n9;
- endcase
- case (x0) // value of HEX2 //
- 0: d82<=n0;
- 1: d82<=n1;
- 2: d82<=n2;
- 3: d82<=n3;
- 4: d82<=n4;
- 5: d82<=n5;
- 6: d82<=n6;
- 7: d82<=n7;
- 8: d82<=n8;
- 9: d82<=n9;
- endcase
- case (y1) // value of HEX1 //
- 0: d81<=n0;
- 1: d81<=n1;
- 2: d81<=n2;
- 3: d81<=n3;
- 4: d81<=n4;
- 5: d81<=n5;
- 6: d81<=n6;
- 7: d81<=n7;
- 8: d81<=n8;
- 9: d81<=n9;
- endcase
- case (y0) // value of HEX0 //
- 0: d80<=n0;
- 1: d80<=n1;
- 2: d80<=n2;
- 3: d80<=n3;
- 4: d80<=n4;
- 5: d80<=n5;
- 6: d80<=n6;
- 7: d80<=n7;
- 8: d80<=n8;
- 9: d80<=n9;
- endcase
- d3 <= d83; d2 <= d82; d1 <= d81; d0 <= d80;
- end
- else if (sw == 10'b0010000000) // SW7 - Basketball Timer //
- begin
- if (trig1 == 1 && b == 0)
- a <= ~a;
- d3 <= t3; d2 <= t2; d1 <= t1; d0 <= t0;
- end
- else if (sw == 10'b0001000000) // SW6 - Game Quarter //
- begin
- d3 <= d63; d2 <= 127; d1 <= 127; d0 <= 127;
- end
- else if (sw == 10'b0000100000) // SW5 - Shot Clock //
- begin
- if (trig1 == 1 && b == 0)
- a <= ~a;
- d3 <= s3; d2 <= s2; d1 <= s1; d0 <= s0;
- end
- else if (sw == 10'b0000011000) // SW4 with SW3 up - Team Fouls of 1st team //
- begin
- if (trig3 == 1 && b == 0)
- begin
- c1 = c1+1;
- if (c1 >= 99)
- c1 = 99;
- c10 = c1%10;
- c11 = (c1-c10)/10;
- end
- else if (trig2 == 1 && b == 0)
- begin
- c1 = c1+1;
- if (c1 >= 99)
- c1 = 99;
- c10 = c1%10;
- c11 = (c1-c10)/10;
- x = x+1;
- if (x >= 99)
- x = 99;
- x0 = x%10;
- x1 = (x-x0)/10;
- end
- else if (trig1 == 1 && b == 0)
- begin
- c1 = c1+1;
- if (c1 >= 99)
- c1 = 99;
- c10 = c1%10;
- c11 = (c1-c10)/10;
- x = x+2;
- if (x >= 99)
- x = 99;
- x0 = x%10;
- x1 = (x-x0)/10;
- end
- else if (trig0 == 1 && b == 0)
- begin
- c1 = c1+1;
- if (c1 >= 99)
- c1 = 99;
- c10 = c1%10;
- c11 = (c1-c10)/10;
- x = x+3;
- if (x >= 99)
- x = 99;
- x0 = x%10;
- x1 = (x-x0)/10;
- end
- case (c11) // value of HEX3 //
- 0: d43<=n0;
- 1: d43<=n1;
- 2: d43<=n2;
- 3: d43<=n3;
- 4: d43<=n4;
- 5: d43<=n5;
- 6: d43<=n6;
- 7: d43<=n7;
- 8: d43<=n8;
- 9: d43<=n9;
- endcase
- case (c10) // value of HEX2 //
- 0: d42<=n0;
- 1: d42<=n1;
- 2: d42<=n2;
- 3: d42<=n3;
- 4: d42<=n4;
- 5: d42<=n5;
- 6: d42<=n6;
- 7: d42<=n7;
- 8: d42<=n8;
- 9: d42<=n9;
- endcase
- if (c1 >= 4)
- state1 <= 10'b0011111111;
- d3 <= d43; d2 <= d42; d1 <= 127; d0 <= 127;
- end
- else if (sw == 10'b0000010000) // SW4 with SW3 down - Team Fouls of 2nd team //
- begin
- if (trig3 == 1 && b == 0)
- begin
- c2 = c2+1;
- if (c2 >= 99)
- c2 = 99;
- c20 = c2%10;
- c21 = (c2-c20)/10;
- end
- else if (trig2 == 1 && b == 0)
- begin
- c2 = c2+1;
- if (c2 >= 99)
- c2 = 99;
- c20 = c2%10;
- c21 = (c2-c20)/10;
- y = y+1;
- if (y >= 99)
- y = 99;
- y0 = y%10;
- y1 = (y-y0)/10;
- end
- else if (trig1 == 1 && b == 0)
- begin
- c2 = c2+1;
- if (c2 >= 99)
- c2 = 99;
- c20 = c2%10;
- c21 = (c2-c20)/10;
- y = y+2;
- if (y >= 99)
- y = 99;
- y0 = y%10;
- y1 = (y-y0)/10;
- end
- else if (trig0 == 1 && b == 0)
- begin
- c2 = c2+1;
- if (c2 >= 99)
- c2 = 99;
- c20 = c2%10;
- c21 = (c2-c20)/10;
- y = y+3;
- if (y >= 99)
- y = 99;
- y0 = y%10;
- y1 = (y-y0)/10;
- end
- case (c21) // value of HEX3 //
- 0: d33<=n0;
- 1: d33<=n1;
- 2: d33<=n2;
- 3: d33<=n3;
- 4: d33<=n4;
- 5: d33<=n5;
- 6: d33<=n6;
- 7: d33<=n7;
- 8: d33<=n8;
- 9: d33<=n9;
- endcase
- case (c20) // value of HEX2 //
- 0: d32<=n0;
- 1: d32<=n1;
- 2: d32<=n2;
- 3: d32<=n3;
- 4: d32<=n4;
- 5: d32<=n5;
- 6: d32<=n6;
- 7: d32<=n7;
- 8: d32<=n8;
- 9: d32<=n9;
- endcase
- if (c2 >= 4)
- state2 <= 8'b11111111;
- d3 <= d33; d2 <= d32; d1 <= 127; d0 <= 127;
- end
- else if (sw == 10'b0000000110) // SW2 with SW1 up - Timeout Countdown //
- begin
- a0 <= 1;
- d3 <= d13; d2 <= d12; d1 <= 127; d0 <= 127;
- end
- else if (sw == 10'b0000000100) // SW2 with SW1 down - Number of Timeouts for both team //
- begin
- a0 <= 1;
- if (trig3 == 1 && b == 0)
- begin
- if (j3 <= 1)
- j3 = 0;
- else
- j3 = j3 - 1;
- bb <= 0;
- end
- else if (trig2 == 1 && b == 0)
- begin
- if (j2 <= 1)
- j2 = 0;
- else
- j2 = j2 - 1;
- bb <= 0;
- end
- else if (trig1 == 1 && b == 0)
- begin
- if (j1 <= 1)
- j1 = 0;
- else
- j1 = j1 - 1;
- bb <= 0;
- end
- else if (trig0 == 1 && b == 0)
- begin
- if (j0 <= 1)
- j0 = 0;
- else
- j0 = j0 - 1 ;
- bb <= 0;
- end
- case (j3) // value of HEX3 //
- 0: d23<=n0;
- 1: d23<=n1;
- 2: d23<=n2;
- 3: d23<=n3;
- 4: d23<=n4;
- 5: d23<=n5;
- 6: d23<=n6;
- 7: d23<=n7;
- 8: d23<=n8;
- 9: d23<=n9;
- endcase
- case (j2) // value of HEX2 //
- 0: d22<=n0;
- 1: d22<=n1;
- 2: d22<=n2;
- 3: d22<=n3;
- 4: d22<=n4;
- 5: d22<=n5;
- 6: d22<=n6;
- 7: d22<=n7;
- 8: d22<=n8;
- 9: d22<=n9;
- endcase
- case (j1) // value of HEX1 //
- 0: d21<=n0;
- 1: d21<=n1;
- 2: d21<=n2;
- 3: d21<=n3;
- 4: d21<=n4;
- 5: d21<=n5;
- 6: d21<=n6;
- 7: d21<=n7;
- 8: d21<=n8;
- 9: d21<=n9;
- endcase
- case (j0) // value of HEX0 //
- 0: d20<=n0;
- 1: d20<=n1;
- 2: d20<=n2;
- 3: d20<=n3;
- 4: d20<=n4;
- 5: d20<=n5;
- 6: d20<=n6;
- 7: d20<=n7;
- 8: d20<=n8;
- 9: d20<=n9;
- endcase
- d3 <= d23; d2 <= d22; d1 <= d21; d0 <= d20;
- end
- else // No Active Switch //
- begin
- a0 <= 0;
- d3 <= 127; d2 <= 127; d1 <= 127; d0 <= 127;
- end
- if (t3 == n0 && t2 == n0 && t1 == n0 && t0 == n0) // Quarter Changes //
- begin
- case (d63)
- n1: begin
- c1 = 0; c2 = 0; state1 <= 10'b0000000000; state2 <= 8'b00000000;
- c10 <= 0; c11 <= 0; c20 <= 0; c21 <= 0;
- j3 <= j3 + 1; j2 <= j2 + 2; j1 <= j1 + 1; j0 <= j0 + 2;
- end
- n2: begin
- c1 = 0; c2 = 0; state1 <= 10'b0000000000; state2 <= 8'b00000000;
- c10 <= 0; c11 <= 0; c20 <= 0; c21 <= 0;
- j3 <= 1; j2 <= 2; j1 <= 1; j0 <= 2;
- end
- n3: begin
- c1 = 0; c2 = 0; state1 <= 10'b0000000000; state2 <= 8'b00000000;
- c10 <= 0; c11 <= 0; c20 <= 0; c21 <= 0;
- j3 <= j3 + 1; j2 <= j2 + 2; j1 <= j1 + 1; j0 <= j0 + 2;
- end
- endcase
- end
- if (d13 == n0 && d12 == n0) // Timeout Ends //
- bb <= 1;
- end
- endmodule
- set_location_assignment PIN_L1 -to clk
- set_location_assignment PIN_R17 -to r[9]
- set_location_assignment PIN_R18 -to r[8]
- set_location_assignment PIN_U18 -to r[7]
- set_location_assignment PIN_Y18 -to r[6]
- set_location_assignment PIN_V19 -to r[5]
- set_location_assignment PIN_T18 -to r[4]
- set_location_assignment PIN_Y19 -to r[3]
- set_location_assignment PIN_U19 -to r[2]
- set_location_assignment PIN_R19 -to r[1]
- set_location_assignment PIN_R20 -to r[0]
- set_location_assignment PIN_Y21 -to g[7]
- set_location_assignment PIN_Y22 -to g[6]
- set_location_assignment PIN_W21 -to g[5]
- set_location_assignment PIN_W22 -to g[4]
- set_location_assignment PIN_V21 -to g[3]
- set_location_assignment PIN_V22 -to g[2]
- set_location_assignment PIN_U21 -to g[1]
- set_location_assignment PIN_U22 -to g[0]
- set_location_assignment PIN_L2 -to sw[9]
- set_location_assignment PIN_M1 -to sw[8]
- set_location_assignment PIN_M2 -to sw[7]
- set_location_assignment PIN_U11 -to sw[6]
- set_location_assignment PIN_U12 -to sw[5]
- set_location_assignment PIN_W12 -to sw[4]
- set_location_assignment PIN_V12 -to sw[3]
- set_location_assignment PIN_M22 -to sw[2]
- set_location_assignment PIN_L21 -to sw[1]
- set_location_assignment PIN_L22 -to sw[0]
- set_location_assignment PIN_T21 -to k[3]
- set_location_assignment PIN_T22 -to k[2]
- set_location_assignment PIN_R21 -to k[1]
- set_location_assignment PIN_R22 -to k[0]
- set_location_assignment PIN_E2 -to hex0[0]
- set_location_assignment PIN_F1 -to hex0[1]
- set_location_assignment PIN_F2 -to hex0[2]
- set_location_assignment PIN_H1 -to hex0[3]
- set_location_assignment PIN_H2 -to hex0[4]
- set_location_assignment PIN_J1 -to hex0[5]
- set_location_assignment PIN_J2 -to hex0[6]
- set_location_assignment PIN_D1 -to hex1[0]
- set_location_assignment PIN_D2 -to hex1[1]
- set_location_assignment PIN_G3 -to hex1[2]
- set_location_assignment PIN_H4 -to hex1[3]
- set_location_assignment PIN_H5 -to hex1[4]
- set_location_assignment PIN_H6 -to hex1[5]
- set_location_assignment PIN_E1 -to hex1[6]
- set_location_assignment PIN_D3 -to hex2[0]
- set_location_assignment PIN_E4 -to hex2[1]
- set_location_assignment PIN_E3 -to hex2[2]
- set_location_assignment PIN_C1 -to hex2[3]
- set_location_assignment PIN_C2 -to hex2[4]
- set_location_assignment PIN_G6 -to hex2[5]
- set_location_assignment PIN_G5 -to hex2[6]
- set_location_assignment PIN_D4 -to hex3[0]
- set_location_assignment PIN_F3 -to hex3[1]
- set_location_assignment PIN_L8 -to hex3[2]
- set_location_assignment PIN_J4 -to hex3[3]
- set_location_assignment PIN_D6 -to hex3[4]
- set_location_assignment PIN_D5 -to hex3[5]
- set_location_assignment PIN_F4 -to hex3[6]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement