fpga
This commit is contained in:
79
spartanTest/ALU.v
Normal file
79
spartanTest/ALU.v
Normal file
@ -0,0 +1,79 @@
|
||||
module ALU (
|
||||
input [3:0] A, B,
|
||||
input CarryIN,
|
||||
input [2:0] opCodeA,
|
||||
output [7:0] Y,
|
||||
output CarryOUT, overflow
|
||||
);
|
||||
|
||||
// Supports: ADD[0], SUB[1], MULT[2], AND[4], OR[5], XOR[6]
|
||||
|
||||
wire [7:0] opCode8;
|
||||
wire [3:0] add_Y, sub_Y;
|
||||
wire [3:0] resultA, resultO, resultX, lUOutput1;
|
||||
wire [3:0] aUtemp1, aUtemp2, lUOutput2;
|
||||
wire [3:0] wireY, wireLA;
|
||||
wire [7:0] opwireM, wireM, Y;
|
||||
|
||||
opCode opCd (.A(opCodeA), .opCode(opCode8));
|
||||
|
||||
arithmeticUnit aU(.opCode(opCode8[1:0]), .A(A), .B(B), .CarryIN(CarryIN), .add_Y(add_Y), .sub_Y(sub_Y), .CarryOUT(CarryOUT), .overflow(overflow));
|
||||
logicUnit lU (.opCode(opCode8[6:4]), .A(A), .B(B), .resultA(resultA), .resultO(resultO), .resultX(resultX));
|
||||
multiplier mU (.A(A), .B(B), .Y(opwireM));
|
||||
|
||||
or o01 (lUOutput1[0], resultA[0], resultO[0]);
|
||||
or o02 (lUOutput1[1], resultA[1], resultO[1]);
|
||||
or o03 (lUOutput1[2], resultA[2], resultO[2]);
|
||||
or o04 (lUOutput1[3], resultA[3], resultO[3]);
|
||||
|
||||
or o11 (lUOutput2[0], lUOutput1[0], resultX[0]);
|
||||
or o12 (lUOutput2[1], lUOutput1[1], resultX[1]);
|
||||
or o13 (lUOutput2[2], lUOutput1[2], resultX[2]);
|
||||
or o14 (lUOutput2[3], lUOutput1[3], resultX[3]);
|
||||
|
||||
|
||||
and a01 (aUtemp1[0], opCode8[0], add_Y[0]);
|
||||
and a02 (aUtemp1[1], opCode8[0], add_Y[1]);
|
||||
and a03 (aUtemp1[2], opCode8[0], add_Y[2]);
|
||||
and a04 (aUtemp1[3], opCode8[0], add_Y[3]);
|
||||
|
||||
|
||||
and a11 (aUtemp2[0], opCode8[1], sub_Y[0]);
|
||||
and a12 (aUtemp2[1], opCode8[1], sub_Y[1]);
|
||||
and a13 (aUtemp2[2], opCode8[1], sub_Y[2]);
|
||||
and a14 (aUtemp2[3], opCode8[1], sub_Y[3]);
|
||||
|
||||
and a21 (wireM[0], opCode8[2], opwireM[0]);
|
||||
and a22 (wireM[1], opCode8[2], opwireM[1]);
|
||||
and a23 (wireM[2], opCode8[2], opwireM[2]);
|
||||
and a24 (wireM[3], opCode8[2], opwireM[3]);
|
||||
and a25 (wireM[4], opCode8[2], opwireM[4]);
|
||||
and a26 (wireM[5], opCode8[2], opwireM[5]);
|
||||
and a27 (wireM[6], opCode8[2], opwireM[6]);
|
||||
and a28 (wireM[7], opCode8[2], opwireM[7]);
|
||||
|
||||
|
||||
or o21 (wireY[0], aUtemp1[0], aUtemp2[0]);
|
||||
or o22 (wireY[1], aUtemp1[1], aUtemp2[1]);
|
||||
or o23 (wireY[2], aUtemp1[2], aUtemp2[2]);
|
||||
or o24 (wireY[3], aUtemp1[3], aUtemp2[3]);
|
||||
|
||||
|
||||
or o1 (wireLA[0], lUOutput2[0], wireY[0]);
|
||||
or o2 (wireLA[1], lUOutput2[1], wireY[1]);
|
||||
or o3 (wireLA[2], lUOutput2[2], wireY[2]);
|
||||
or o4 (wireLA[3], lUOutput2[3], wireY[3]);
|
||||
|
||||
or o31 (Y[0], wireLA[0], wireM[0]);
|
||||
or o32 (Y[1], wireLA[1], wireM[1]);
|
||||
or o33 (Y[2], wireLA[2], wireM[2]);
|
||||
or o34 (Y[3], wireLA[3], wireM[3]);
|
||||
or o35 (Y[4], 1'b0, wireM[4]);
|
||||
or o36 (Y[5], 1'b0, wireM[5]);
|
||||
or o37 (Y[6], 1'b0, wireM[6]);
|
||||
or o38 (Y[7], 1'b0, wireM[7]);
|
||||
|
||||
//BinaryToBCD btod1(.binary(Y), .bcd(bcd)); // WIRE Y BINARY!!!!
|
||||
|
||||
|
||||
endmodule
|
42
spartanTest/ALUTB.v
Normal file
42
spartanTest/ALUTB.v
Normal file
@ -0,0 +1,42 @@
|
||||
module ALUTB ();
|
||||
|
||||
reg [3:0] A, B;
|
||||
reg CarryIN;
|
||||
reg [2:0] opCodeA;
|
||||
wire CarryOUT, overflow;
|
||||
wire [11:0] bcd;
|
||||
|
||||
ALU uut(
|
||||
.A(A),
|
||||
.B(B),
|
||||
.CarryIN(CarryIN),
|
||||
.opCodeA(opCodeA),
|
||||
.CarryOUT(CarryOUT),
|
||||
.bcd(bcd),
|
||||
.overflow(overflow)
|
||||
);
|
||||
|
||||
initial begin
|
||||
$dumpfile("ALU.vcd"); // GTKWAVE SIMULTAIN DATA WAVEFORM
|
||||
$dumpvars; // ICARUS VERILOG ADD ALL VARIABLES
|
||||
A = 4'b0000; B = 4'b0000; CarryIN = 1'b0; opCodeA = 3'b011; #5;
|
||||
A = 4'b0000; B = 4'b1111; CarryIN = 1'b0; opCodeA = 3'b011; #5;
|
||||
A = 4'b1111; B = 4'b0000; CarryIN = 1'b0; opCodeA = 3'b011; #5;
|
||||
A = 4'b1111; B = 4'b1111; CarryIN = 1'b1; opCodeA = 3'b011; #5;
|
||||
A = 4'b0111; B = 4'b0111; CarryIN = 1'b1; opCodeA = 3'b011; #5;
|
||||
|
||||
A = 4'b0000; B = 4'b0000; CarryIN = 1'b0; opCodeA = 3'b111; #5;
|
||||
A = 4'b0000; B = 4'b1111; CarryIN = 1'b0; opCodeA = 3'b111; #5;
|
||||
A = 4'b1111; B = 4'b0000; CarryIN = 1'b0; opCodeA = 3'b111; #5;
|
||||
A = 4'b1111; B = 4'b1111; CarryIN = 1'b1; opCodeA = 3'b111; #5;
|
||||
A = 4'b0111; B = 4'b1111; CarryIN = 1'b1; opCodeA = 3'b111; #5;
|
||||
|
||||
A = 4'b0000; B = 4'b0000; CarryIN = 1'b0; opCodeA = 3'b010; #5;
|
||||
A = 4'b0000; B = 4'b1111; CarryIN = 1'b0; opCodeA = 3'b010; #5;
|
||||
A = 4'b1111; B = 4'b0000; CarryIN = 1'b0; opCodeA = 3'b010; #5;
|
||||
A = 4'b1111; B = 4'b1111; CarryIN = 1'b1; opCodeA = 3'b010; #5;
|
||||
A = 4'b0111; B = 4'b1111; CarryIN = 1'b1; opCodeA = 3'b010; #5;
|
||||
$finish; //NOT CONTAIN CLK, BUT STILL STOPS CODE
|
||||
end
|
||||
|
||||
endmodule
|
79
spartanTest/BinaryToBCD.v
Normal file
79
spartanTest/BinaryToBCD.v
Normal file
@ -0,0 +1,79 @@
|
||||
module BinaryToBCD (
|
||||
input [7:0] binary,
|
||||
output [11:0] bcd
|
||||
);
|
||||
|
||||
wire empty1, empty2;
|
||||
wire [3:0] dab1, dab2, dab3, dab4, dab5;
|
||||
|
||||
and a111 (empty1, 1'b0, 1'b0);
|
||||
and a000 (empty2, 1'b0, 1'b0);
|
||||
and a222 (bcd[11], 1'b0, 1'b0);
|
||||
and a223 (bcd[10], 1'b0, 1'b0);
|
||||
|
||||
dabble d1t (.A((empty1)),
|
||||
.B(binary[7]),
|
||||
.C(binary[6]),
|
||||
.D(binary[5]),
|
||||
.X(dab1[0]),
|
||||
.Y(dab1[1]),
|
||||
.Z(dab1[2]),
|
||||
.E(dab1[3]));
|
||||
|
||||
dabble d2u (.A((dab1[1])),
|
||||
.B(dab1[2]),
|
||||
.C(dab1[3]),
|
||||
.D(binary[4]),
|
||||
.X(dab2[0]),
|
||||
.Y(dab2[1]),
|
||||
.Z(dab2[2]),
|
||||
.E(dab2[3]));
|
||||
|
||||
dabble d3v (.A((dab2[1])),
|
||||
.B(dab2[2]),
|
||||
.C(dab2[3]),
|
||||
.D(binary[3]),
|
||||
.X(dab3[0]),
|
||||
.Y(dab3[1]),
|
||||
.Z(dab3[2]),
|
||||
.E(dab3[3]));
|
||||
|
||||
dabble d4w (.A((empty2)),
|
||||
.B(dab1[0]),
|
||||
.C(dab2[0]),
|
||||
.D(dab3[0]),
|
||||
.X(bcd[9]),
|
||||
.Y(dab4[1]),
|
||||
.Z(dab4[2]),
|
||||
.E(dab4[3]));
|
||||
|
||||
dabble d5x (.A((dab3[1])),
|
||||
.B(dab3[2]),
|
||||
.C(dab3[3]),
|
||||
.D(binary[2]),
|
||||
.X(dab5[0]),
|
||||
.Y(dab5[1]),
|
||||
.Z(dab5[2]),
|
||||
.E(dab5[3]));
|
||||
|
||||
dabble d6y (.A((dab4[1])),
|
||||
.B(dab4[2]),
|
||||
.C(dab4[3]),
|
||||
.D(dab5[0]),
|
||||
.X(bcd[8]),
|
||||
.Y(bcd[7]),
|
||||
.Z(bcd[6]),
|
||||
.E(bcd[5]));
|
||||
|
||||
dabble d7z (.A((dab5[1])),
|
||||
.B(dab5[2]),
|
||||
.C(dab5[3]),
|
||||
.D(binary[1]),
|
||||
.X(bcd[4]),
|
||||
.Y(bcd[3]),
|
||||
.Z(bcd[2]),
|
||||
.E(bcd[1]));
|
||||
|
||||
or o1 (bcd[0], binary[0], 1'b0);
|
||||
|
||||
endmodule
|
40
spartanTest/BinaryToBCDTB.v
Normal file
40
spartanTest/BinaryToBCDTB.v
Normal file
@ -0,0 +1,40 @@
|
||||
module BinaryToBCDTB;
|
||||
// Testbench signals
|
||||
reg [7:0] binary;
|
||||
wire [11:0] bcd; // Output BCD
|
||||
|
||||
// Instantiate the BinaryToBCD module
|
||||
BinaryToBCD uut (
|
||||
.binary(binary),
|
||||
.bcd(bcd)
|
||||
);
|
||||
|
||||
// Testbench procedure
|
||||
initial begin
|
||||
$monitor("Time: %0t | Binary: %b | BCD: %b (Hundreds: %d, Tens: %d, Ones: %d)",
|
||||
$time, binary, bcd, bcd[11:8], bcd[7:4], bcd[3:0]);
|
||||
$dumpfile("BinaryToBCD.vcd");
|
||||
$dumpvars;
|
||||
// Test cases
|
||||
binary = 8'b00000000; // Decimal: 0
|
||||
#10;
|
||||
|
||||
binary = 8'b00001010; // Decimal: 10
|
||||
#10;
|
||||
|
||||
binary = 8'b00101010; // Decimal: 42
|
||||
#10;
|
||||
|
||||
binary = 8'b01100011; // Decimal: 99
|
||||
#10;
|
||||
|
||||
binary = 8'b10011001; // Decimal: 153
|
||||
#10;
|
||||
|
||||
binary = 8'b11111111; // Decimal: 255
|
||||
#10;
|
||||
|
||||
// End simulation
|
||||
$finish;
|
||||
end
|
||||
endmodule
|
20
spartanTest/addition.v
Normal file
20
spartanTest/addition.v
Normal file
@ -0,0 +1,20 @@
|
||||
module addition (
|
||||
input [3:0] A, B,
|
||||
input CarryIN,
|
||||
output [3:0] Y,
|
||||
output CarryOUT,
|
||||
output overflow
|
||||
);
|
||||
|
||||
wire [2:0] Carry4;
|
||||
|
||||
fulladder f0(.A(A[0]), .B(B[0]), .Carry(CarryIN), .Sum(Y[0]), .CarryO(Carry4[0]));
|
||||
fulladder f1(.A(A[1]), .B(B[1]), .Carry(Carry4[0]), .Sum(Y[1]), .CarryO(Carry4[1]));
|
||||
fulladder f2(.A(A[2]), .B(B[2]), .Carry(Carry4[1]), .Sum(Y[2]), .CarryO(Carry4[2]));
|
||||
fulladder f3(.A(A[3]), .B(B[3]), .Carry(Carry4[2]), .Sum(Y[3]), .CarryO(CarryOUT));
|
||||
|
||||
|
||||
//overflowDetect od1 (.opCode(2'b01), .A(A), .B(B), .Y(Y), .CarryOUT(CarryOUT), .overflowDetect(overflow)); (KULLANILMAYACAK!!!!)
|
||||
xor ov1 (overflow, Carry4[2], CarryOUT);
|
||||
|
||||
endmodule
|
9
spartanTest/aluboard.v
Normal file
9
spartanTest/aluboard.v
Normal file
@ -0,0 +1,9 @@
|
||||
module aluboard (
|
||||
input [3:0] select,
|
||||
input [7:0] Y,
|
||||
input [3:0] A, B,
|
||||
input [2:0] opCodeA,
|
||||
output [7:0] sO
|
||||
);
|
||||
|
||||
ALU alu0 ()
|
33
spartanTest/arithmeticUnit.v
Normal file
33
spartanTest/arithmeticUnit.v
Normal file
@ -0,0 +1,33 @@
|
||||
module arithmeticUnit (
|
||||
input [1:0] opCode,
|
||||
input [3:0] A, B,
|
||||
input CarryIN,
|
||||
output [3:0] add_Y, sub_Y,
|
||||
output CarryOUT,
|
||||
output overflow
|
||||
);
|
||||
|
||||
wire [3:0] addY, subY;
|
||||
wire CarryOUTADD, CarryOUTSUB, tempCAdd, tempCSub, tempoverflow;
|
||||
|
||||
addition a1(.A(A), .B(B), .CarryIN(CarryIN), .Y(addY), .CarryOUT(CarryOUTADD), .overflow(tempoverflow));
|
||||
subtraction s1(.A(A), .B(B), .BorrowIN(CarryIN), .Y(subY), .BorrowOUT(CarryOUTSUB));
|
||||
|
||||
and add1 (add_Y[0], opCode[0], addY[0]);
|
||||
and add2 (add_Y[1], opCode[0], addY[1]);
|
||||
and add3 (add_Y[2], opCode[0], addY[2]);
|
||||
and add4 (add_Y[3], opCode[0], addY[3]);
|
||||
|
||||
and sub1 (sub_Y[0], opCode[1], subY[0]);
|
||||
and sub2 (sub_Y[1], opCode[1], subY[1]);
|
||||
and sub3 (sub_Y[2], opCode[1], subY[2]);
|
||||
and sub4 (sub_Y[3], opCode[1], subY[3]);
|
||||
|
||||
// or or1 (CarryOUT, CarryOUTADD, CarryOUTSUB); (OLD!!!)
|
||||
and and10 (tempCSub, CarryOUTSUB, opCode[1]);
|
||||
and and11 (tempCAdd, CarryOUTADD, opCode[0]);
|
||||
or or4 (CarryOUT, tempCAdd, tempCSub);
|
||||
|
||||
and add12 (overflow, opCode[0], tempoverflow);
|
||||
|
||||
endmodule
|
41
spartanTest/char_mem.v
Normal file
41
spartanTest/char_mem.v
Normal file
@ -0,0 +1,41 @@
|
||||
module char_mem (
|
||||
input [4:0] addr,
|
||||
output [7:0] bus,
|
||||
input [3:0] A,
|
||||
input [3:0] B,
|
||||
input [2:0] opCode,
|
||||
input [7:0] Y
|
||||
);
|
||||
parameter LINES = 2;
|
||||
parameter CHARS_PER_LINE = 16;
|
||||
parameter BITS_PER_CHAR = 8;
|
||||
parameter STR_SIZE = LINES * CHARS_PER_LINE * BITS_PER_CHAR;
|
||||
|
||||
// Map the data into strings for display
|
||||
wire [127:0] line1 = { "A:", nibble_to_ascii(A), " B:", nibble_to_ascii(B), " " };
|
||||
wire [127:0] line2 = { "op:", nibble_to_ascii({1'b0, opCode}), " Y:", byte_to_ascii(Y) };
|
||||
|
||||
// Combine the two lines
|
||||
wire [0:STR_SIZE-1] display_data = { line1, line2 };
|
||||
|
||||
// Address selection for the LCD
|
||||
assign bus = display_data[{addr[4:0], 3'b000}+:8];
|
||||
|
||||
// Converts a 4-bit nibble to two ASCII characters
|
||||
function [15:0] nibble_to_ascii;
|
||||
input [3:0] nibble;
|
||||
begin
|
||||
nibble_to_ascii[15:8] = (nibble[3:0] >= 4'd10) ? (nibble[3:0] - 4'd10 + "A") : (nibble[3:0] + "0");
|
||||
nibble_to_ascii[7:0] = " ";
|
||||
end
|
||||
endfunction
|
||||
|
||||
// Converts an 8-bit byte to two ASCII characters
|
||||
function [15:0] byte_to_ascii;
|
||||
input [7:0] byte;
|
||||
begin
|
||||
byte_to_ascii[15:8] = ((byte >> 4) >= 4'd10) ? ((byte >> 4) - 4'd10 + "A") : ((byte >> 4) + "0");
|
||||
byte_to_ascii[7:0] = ((byte & 4'hF) >= 4'd10) ? ((byte & 4'hF) - 4'd10 + "A") : ((byte & 4'hF) + "0");
|
||||
end
|
||||
endfunction
|
||||
endmodule
|
22
spartanTest/dabble.v
Normal file
22
spartanTest/dabble.v
Normal file
@ -0,0 +1,22 @@
|
||||
module dabble (
|
||||
input A, B, C, D,
|
||||
output X, Y, Z, E
|
||||
);
|
||||
|
||||
wire xor1, nor1, xor2, nor2, nor3, or1;
|
||||
|
||||
xor xo1 (xor1, A, D);
|
||||
nor no1 (nor1, A, B);
|
||||
xor xo2 (xor2, A, C);
|
||||
|
||||
nor no2 (nor2, xor1, xor2);
|
||||
|
||||
nor no3 (nor3, nor2, nor1);
|
||||
buf bu1 (X, nor3);
|
||||
or o1 (or1, xor1, nor1);
|
||||
|
||||
nor no4 (Y, or1, C);
|
||||
and an1 (Z, or1, xor2);
|
||||
xor xo3 (E, nor3, D);
|
||||
|
||||
endmodule
|
105
spartanTest/data.jed
Normal file
105
spartanTest/data.jed
Normal file
@ -0,0 +1,105 @@
|
||||
JEDEC Programming File for /home/ise/ise/data.jed
|
||||
Date: Sat Oct 26 08:09:00 2024
|
||||
|
||||
QF25812*
|
||||
QP0*
|
||||
F0*
|
||||
X0*
|
||||
N DEVICE xc2c64a-XXXXX*
|
||||
L000000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L000274 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L000548 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L000822 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L001096 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L001370 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L001644 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L001918 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L002192 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L002466 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L002740 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L003014 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L003288 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L003562 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L003836 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L004110 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L004384 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L004658 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L004932 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L005206 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L005480 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L005754 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000001111001*
|
||||
L006028 1111100111111000000011110011111100111111000000011110011111100111111000000011110011111100111111000000011110011111100111111000000011110011111100111111000000011110011111100111111000000011110011111100111111000000011110011111100111111000000011110011111100111111000000011110011111*
|
||||
L006302 1001111110000000111100111111001111110000000111100111111001111110000000111100111111001111110000000111100111111001111110000000111100111111001111110011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110101101111111111111111111*
|
||||
L006576 1111111111111111111111111111111111111110110101111111111111111111111111101101011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L006850 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L007124 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L007398 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L007672 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L007946 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L008220 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L008494 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L008768 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L009042 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L009316 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L009590 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L009864 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L010138 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L010412 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111101110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L010686 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L010960 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L011234 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L011508 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L011782 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L012056 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L012330 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000111100111111001111110000000111100001110001111110000000111100111111001111110000000111100111111001111110000000111100111111001111110000000*
|
||||
L012604 1111001111110011111100000001111001111110011111100000001111001111110011111100000001111001111110011111100000001111001111110011111100000001111001111110011111100000001111001111100110000001000001111001111110011111100000001111001111110011111100000001111001111110011111100000001111*
|
||||
L012878 0011111100111111001111111111111111111111111111111111111111111111111111111111111111111111101111010111111111111111111111111010110111111111111111111111001110111111111111111111111111111111101101011111111111111111111111111011010111111111111111111111111111111111111111111111111111*
|
||||
L013152 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L013426 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L013700 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L013974 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101110111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L014248 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L014522 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L014796 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L015070 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L015344 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111011111101111011111111111111111111111111111111111111111111111111111111*
|
||||
L015618 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L015892 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L016166 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L016440 1111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L016714 1111111111111111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L016988 1111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L017262 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111*
|
||||
L017536 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L017810 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L018084 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L018358 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L018632 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L018906 1111110000011110011111100111111000000011110011111100111111000000011110011111100111111000000011110011111100111111000000011110011111100111111000000011110011001001110001010000011110011111100111111000000011110011111100111111000000011110011111100111111000000011110011111010110001*
|
||||
L019180 0100000111100111110101100010100000111100111110101100010100000111100111111001111110000000111100111110101100010100000111100111111001111110000000111100111111001111110011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L019454 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L019728 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L020002 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L020276 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L020550 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L020824 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L021098 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L021372 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L021646 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L021920 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L022194 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L022468 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L022742 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L023016 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L023290 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L023564 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L023838 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L024112 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L024386 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L024660 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L024934 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*
|
||||
L025208 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000111100001110001111110000000111100001110001111110000000111100111111001111110000000111100111111001111110000000111100111*
|
||||
L025482 1110011111100000001111001111110011111100000001111000011100011111100000001111001111110011111100000001111001111110011111100000001111001111110011111100000001111001111110011111100000001111001111110011111100000001111001111110011111100000001111001111110011111100000001111001111110*
|
||||
L025756 01111110000000111100111111001111110000000111111110111111*
|
||||
C2A9A*
|
||||
0296
|
12
spartanTest/fulladder.v
Normal file
12
spartanTest/fulladder.v
Normal file
@ -0,0 +1,12 @@
|
||||
module fulladder (
|
||||
input A, B, Carry,
|
||||
output Sum, CarryO
|
||||
);
|
||||
|
||||
wire xor1, and1, and2;
|
||||
|
||||
halfadder h1(.A(A), .B(B), .Sum(xor1), .Carry(and1));
|
||||
halfadder h2 (.A(xor1), .B(Carry), .Sum(Sum), .Carry(and2));
|
||||
or o1 (CarryO, and1, and2);
|
||||
|
||||
endmodule
|
12
spartanTest/fullsubtraction.v
Normal file
12
spartanTest/fullsubtraction.v
Normal file
@ -0,0 +1,12 @@
|
||||
module fullsubtraction (
|
||||
input A, B, BorrowIN,
|
||||
output Difference, BorrowOut
|
||||
);
|
||||
|
||||
wire tempD, tempB1, tempB2;
|
||||
|
||||
halfsubtraction hf1(.A(A), .B(B), .Difference(tempD), .Borrow(tempB1));
|
||||
halfsubtraction hf2(.A(tempD), .B(BorrowIN), .Difference(Difference), .Borrow(tempB2));
|
||||
or o1 (BorrowOut, tempB1, tempB2);
|
||||
|
||||
endmodule
|
9
spartanTest/halfadder.v
Normal file
9
spartanTest/halfadder.v
Normal file
@ -0,0 +1,9 @@
|
||||
module halfadder (
|
||||
input A, B,
|
||||
output Sum, Carry
|
||||
);
|
||||
|
||||
and a1 (Carry, A, B);
|
||||
xor xo1 (Sum, A, B);
|
||||
|
||||
endmodule
|
12
spartanTest/halfsubtraction.v
Normal file
12
spartanTest/halfsubtraction.v
Normal file
@ -0,0 +1,12 @@
|
||||
module halfsubtraction (
|
||||
input A, B,
|
||||
output Difference, Borrow
|
||||
);
|
||||
|
||||
wire notA;
|
||||
|
||||
xor xo1 (Difference, A, B);
|
||||
not a1 (notA, A);
|
||||
and an1 (Borrow, notA, B);
|
||||
|
||||
endmodule
|
53
spartanTest/lcd.v
Normal file
53
spartanTest/lcd.v
Normal file
@ -0,0 +1,53 @@
|
||||
module lcd (
|
||||
input clk,
|
||||
output reg lcd_rs,
|
||||
output reg lcd_rw,
|
||||
output reg lcd_e,
|
||||
output reg [7:4] lcd_d,
|
||||
output [4:0] mem_addr,
|
||||
input [7:0] mem_bus
|
||||
);
|
||||
|
||||
parameter n = 24;
|
||||
parameter j = 17; // Initialization is slow, runs at clk/2^(j+2) ~95Hz
|
||||
parameter k = 11; // Writing/seeking is fast, clk/2^(k_2) ~6KHz
|
||||
parameter noop = 6'b010000; // Allows LCD to drive lcd_d, can be safely written any time
|
||||
|
||||
reg [n:0] count = 0;
|
||||
reg [5:0] lcd_state = noop;
|
||||
reg init = 1; // Start in initialization on power on
|
||||
reg row = 0; // Writing to top or or bottom row
|
||||
|
||||
assign mem_addr = {row, count[k+6:k+3]};
|
||||
|
||||
initial count[j+7:j+2] = 11;
|
||||
|
||||
always @ (posedge clk) begin
|
||||
count <= count + 1;
|
||||
if (init) begin // initalization
|
||||
case (count[j+7:j+2])
|
||||
1: lcd_state <= 6'b000010; // function set
|
||||
2: lcd_state <= 6'b000010;
|
||||
3: lcd_state <= 6'b001000;
|
||||
4: lcd_state <= 6'b000000; // display on/off control
|
||||
5: lcd_state <= 6'b001100;
|
||||
6: lcd_state <= 6'b000000; // display clear
|
||||
7: lcd_state <= 6'b000001;
|
||||
8: lcd_state <= 6'b000000; // entry mode set
|
||||
9: lcd_state <= 6'b000110;
|
||||
10: begin init <= ~init; count <= 0; end
|
||||
endcase
|
||||
// Write lcd_state to the LCD and turn lcd_e high for the middle half of each lcd_state
|
||||
{lcd_e,lcd_rs,lcd_rw,lcd_d[7:4]} <= {^count[j+1:j+0] & ~lcd_rw,lcd_state};
|
||||
end else begin // Continuously update screen from memory
|
||||
case (count[k+7:k+2])
|
||||
32: lcd_state <= {3'b001,~row,2'b00}; // Move cursor to begining of next line
|
||||
33: lcd_state <= 6'b000000;
|
||||
34: begin count <= 0; row <= ~row; end // Restart and switch which row is being written
|
||||
default: lcd_state <= {2'b10, ~count[k+2] ? mem_bus[7:4] : mem_bus[3:0]}; // Pull characters from bus
|
||||
endcase
|
||||
// Write lcd_state to the LCD and turn lcd_e high for the middle half of each lcd_state
|
||||
{lcd_e,lcd_rs,lcd_rw,lcd_d[7:4]} <= {^count[k+1:k+0] & ~lcd_rw,lcd_state};
|
||||
end
|
||||
end
|
||||
endmodule
|
39
spartanTest/logicUnit.v
Normal file
39
spartanTest/logicUnit.v
Normal file
@ -0,0 +1,39 @@
|
||||
module logicUnit (
|
||||
input [2:0] opCode,
|
||||
input [3:0] A, B,
|
||||
output [3:0] resultA, resultO, resultX
|
||||
);
|
||||
|
||||
wire [3:0] and1, or1, xor1;
|
||||
|
||||
and a01 (and1[0], A[0], B[0]);
|
||||
and a02 (and1[1], A[1], B[1]);
|
||||
and a03 (and1[2], A[2], B[2]);
|
||||
and a04 (and1[3], A[3], B[3]);
|
||||
|
||||
or o01 (or1[0], A[0], B[0]);
|
||||
or o02 (or1[1], A[1], B[1]);
|
||||
or o03 (or1[2], A[2], B[2]);
|
||||
or o04 (or1[3], A[3], B[3]);
|
||||
|
||||
xor xor01 (xor1[0], A[0], B[0]);
|
||||
xor xor02 (xor1[1], A[1], B[1]);
|
||||
xor xor03 (xor1[2], A[2], B[2]);
|
||||
xor xor04 (xor1[3], A[3], B[3]);
|
||||
|
||||
and a_o1 (resultA[0], opCode[0], and1[0]);
|
||||
and a_o2 (resultA[1], opCode[0], and1[1]);
|
||||
and a_o3 (resultA[2], opCode[0], and1[2]);
|
||||
and a_o4 (resultA[3], opCode[0], and1[3]);
|
||||
|
||||
and o_o1 (resultO[0], opCode[1], or1[0]);
|
||||
and o_o2 (resultO[1], opCode[1], or1[1]);
|
||||
and o_o3 (resultO[2], opCode[1], or1[2]);
|
||||
and o_o4 (resultO[3], opCode[1], or1[3]);
|
||||
|
||||
and x_o1 (resultX[0], opCode[2], xor1[0]);
|
||||
and x_o2 (resultX[1], opCode[2], xor1[1]);
|
||||
and x_o3 (resultX[2], opCode[2], xor1[2]);
|
||||
and x_o4 (resultX[3], opCode[2], xor1[3]);
|
||||
|
||||
endmodule
|
37
spartanTest/logicUnitTB.v
Normal file
37
spartanTest/logicUnitTB.v
Normal file
@ -0,0 +1,37 @@
|
||||
module logicUnitTB ();
|
||||
|
||||
reg [2:0] opCode;
|
||||
reg [3:0] A, B;
|
||||
wire [3:0] resultA, resultO, resultX;
|
||||
|
||||
logicUnit uut (
|
||||
.opCode(opCode),
|
||||
.A(A),
|
||||
.B(B),
|
||||
.resultA(resultA),
|
||||
.resultO(resultO),
|
||||
.resultX(resultX)
|
||||
);
|
||||
|
||||
initial begin
|
||||
$dumpfile("logicUnit.vcd");
|
||||
$dumpvars;
|
||||
opCode = 3'b001; A = 4'b0001; B = 4'b0001; #2;
|
||||
opCode = 3'b001; A = 4'b0011; B = 4'b0001; #2;
|
||||
opCode = 3'b001; A = 4'b1001; B = 4'b1001; #2;
|
||||
opCode = 3'b001; A = 4'b1111; B = 4'b1111; #2;
|
||||
opCode = 3'b001; A = 4'b0000; B = 4'b0000; #2;
|
||||
|
||||
opCode = 3'b010; A = 4'b0001; B = 4'b0101; #2;
|
||||
opCode = 3'b010; A = 4'b1001; B = 4'b0101; #2;
|
||||
opCode = 3'b010; A = 4'b0001; B = 4'b1111; #2;
|
||||
opCode = 3'b010; A = 4'b0000; B = 4'b0101; #2;
|
||||
|
||||
opCode = 3'b100; A = 4'b0000; B = 4'b0101; #2;
|
||||
opCode = 3'b100; A = 4'b0000; B = 4'b0000; #2;
|
||||
opCode = 3'b100; A = 4'b0000; B = 4'b0101; #2;
|
||||
opCode = 3'b100; A = 4'b1111; B = 4'b1111; #2;
|
||||
$finish;
|
||||
end
|
||||
|
||||
endmodule
|
76
spartanTest/multiplier.v
Normal file
76
spartanTest/multiplier.v
Normal file
@ -0,0 +1,76 @@
|
||||
module multiplier (
|
||||
input [3:0] A, B,
|
||||
output [7:0] Y
|
||||
);
|
||||
|
||||
wire [3:0] b0, a0, a1, a2;
|
||||
wire [4:0] S0, S1, S2;
|
||||
wire carry0, carry1, carry2;
|
||||
wire overflow0, overflow1, overflow2;
|
||||
|
||||
// Partial product generation
|
||||
and (Y[0], A[0], B[0]); // LSB of the result
|
||||
|
||||
// Generate partial products for B[0] and B[1]
|
||||
and ab00 (b0[0], A[1], B[0]);
|
||||
and ab01 (b0[1], A[2], B[0]);
|
||||
and ab02 (b0[2], A[3], B[0]);
|
||||
not ab03 (b0[3], 1'b1); // Initialize b0[3] to 0
|
||||
|
||||
and aa00 (a0[0], A[0], B[1]);
|
||||
and aa01 (a0[1], A[1], B[1]);
|
||||
and aa02 (a0[2], A[2], B[1]);
|
||||
and aa03 (a0[3], A[3], B[1]);
|
||||
|
||||
// First addition
|
||||
addition add0 (
|
||||
.A(a0),
|
||||
.B(b0),
|
||||
.CarryIN(1'b0),
|
||||
.Y(S0[3:0]),
|
||||
.CarryOUT(S0[4]),
|
||||
.overflow(overflow0)
|
||||
);
|
||||
|
||||
// Generate partial products for B[2]
|
||||
and aa10 (a1[0], A[0], B[2]);
|
||||
and aa11 (a1[1], A[1], B[2]);
|
||||
and aa12 (a1[2], A[2], B[2]);
|
||||
and aa13 (a1[3], A[3], B[2]);
|
||||
|
||||
// Second addition
|
||||
addition add1 (
|
||||
.A(a1),
|
||||
.B(S0[4:1]),
|
||||
.CarryIN(1'b0),
|
||||
.Y(S1[3:0]),
|
||||
.CarryOUT(S1[4]),
|
||||
.overflow(overflow1)
|
||||
);
|
||||
|
||||
// Generate partial products for B[3]
|
||||
and aa20 (a2[0], A[0], B[3]);
|
||||
and aa21 (a2[1], A[1], B[3]);
|
||||
and aa22 (a2[2], A[2], B[3]);
|
||||
and aa23 (a2[3], A[3], B[3]);
|
||||
|
||||
// Third addition
|
||||
addition add2 (
|
||||
.A(a2),
|
||||
.B(S1[4:1]),
|
||||
.CarryIN(1'b0),
|
||||
.Y(S2[3:0]),
|
||||
.CarryOUT(S2[4]),
|
||||
.overflow(overflow2)
|
||||
);
|
||||
|
||||
// Combine results into the final output Y
|
||||
or o01 (Y[1], S0[0], 1'b0);
|
||||
or o02 (Y[2], S1[0], 1'b0);
|
||||
or o03 (Y[3], S2[0], 1'b0);
|
||||
or o04 (Y[4], S2[1], 1'b0);
|
||||
or o05 (Y[5], S2[2], 1'b0);
|
||||
or o06 (Y[6], S2[3], 1'b0);
|
||||
or o07 (Y[7], S2[4], 1'b0);
|
||||
|
||||
endmodule
|
22
spartanTest/multiplierTB.v
Normal file
22
spartanTest/multiplierTB.v
Normal file
@ -0,0 +1,22 @@
|
||||
module multiplierTB();
|
||||
reg [3:0] A, B;
|
||||
wire [7:0] Y;
|
||||
|
||||
multiplier uut(
|
||||
.A(A),
|
||||
.B(B),
|
||||
.Y(Y)
|
||||
);
|
||||
|
||||
initial begin
|
||||
$dumpfile("multiplier.vcd");
|
||||
$dumpvars;
|
||||
A = 4'b0000; B = 4'b0000; #2;
|
||||
A = 4'b0000; B = 4'b1000; #2;
|
||||
A = 4'b1000; B = 4'b1000; #2;
|
||||
A = 4'b0111; B = 4'b0111; #2;
|
||||
A = 4'b1111; B = 4'b1111; #2;
|
||||
$finish;
|
||||
end
|
||||
|
||||
endmodule
|
25
spartanTest/opCode.v
Normal file
25
spartanTest/opCode.v
Normal file
@ -0,0 +1,25 @@
|
||||
module opCode (
|
||||
input [2:0] A,
|
||||
output [7:0] opCode
|
||||
);
|
||||
wire and1, and2, and3, and4, notA, notB, notC;
|
||||
|
||||
not n1(notA, A[2]);
|
||||
not n2(notB, A[1]);
|
||||
not n3(notC, A[0]);
|
||||
|
||||
and a01(and1, A[2], A[1]);
|
||||
and a02(and2, notA, A[1]);
|
||||
and a03(and3, A[2], notB);
|
||||
and a04(and4, notA, notB);
|
||||
|
||||
and a1(opCode[0], and4, notC);
|
||||
and a2(opCode[1], and4, A[0]);
|
||||
and a3(opCode[2], and2, notC);
|
||||
and a4(opCode[3], and2, A[0]);
|
||||
and a5(opCode[4], and3, notC);
|
||||
and a6(opCode[5], and3, A[0]);
|
||||
and a7(opCode[6], and1, notC);
|
||||
and a8(opCode[7], and1, A[0]);
|
||||
|
||||
endmodule
|
26
spartanTest/opCodeTB.v
Normal file
26
spartanTest/opCodeTB.v
Normal file
@ -0,0 +1,26 @@
|
||||
module opCodeTB();
|
||||
|
||||
reg [2:0] A;
|
||||
wire [7:0] opCode;
|
||||
|
||||
opCode uut (
|
||||
.A(A),
|
||||
|
||||
.opCode(opCode)
|
||||
);
|
||||
|
||||
initial begin
|
||||
$dumpfile("opCode.vcd");
|
||||
$dumpvars;
|
||||
A = 3'b000; #3;
|
||||
A = 3'b001; #3;
|
||||
A = 3'b010; #3;
|
||||
A = 3'b011; #3;
|
||||
A = 3'b100; #3;
|
||||
A = 3'b101; #3;
|
||||
A = 3'b110; #3;
|
||||
A = 3'b111; #3;
|
||||
$finish;
|
||||
end
|
||||
|
||||
endmodule
|
26
spartanTest/selectorTB.v
Normal file
26
spartanTest/selectorTB.v
Normal file
@ -0,0 +1,26 @@
|
||||
module selectorTB();
|
||||
|
||||
reg [3:0] select, A, B;
|
||||
reg [7:0] Y;
|
||||
reg [2:0] opCodeA;
|
||||
wire [7:0] s0;
|
||||
|
||||
selector uut (
|
||||
.select(select),
|
||||
.A(A),
|
||||
.B(B),
|
||||
.opCodeA(opCodeA),
|
||||
.s0(s0)
|
||||
);
|
||||
|
||||
initial begin
|
||||
$dumpfile("selector.vcd");
|
||||
$dumpvars;
|
||||
A = 4'b0001; B = 4'b0010; opCodeA = 3'b111; Y = 8'b1111_0000; select = 4'b0010; #5;
|
||||
A = 4'b0001; B = 4'b0010; opCodeA = 3'b111; Y = 8'b1111_0000; select = 4'b0001; #5;
|
||||
A = 4'b0001; B = 4'b0010; opCodeA = 3'b111; Y = 8'b0111_0000; select = 4'b0100; #5;
|
||||
A = 4'b0001; B = 4'b0010; opCodeA = 3'b111; Y = 8'b0111_0000; select = 4'b1000; #5;
|
||||
$finish;
|
||||
end
|
||||
|
||||
endmodule
|
22
spartanTest/spartan3e.ucf
Normal file
22
spartanTest/spartan3e.ucf
Normal file
@ -0,0 +1,22 @@
|
||||
# Clock signal
|
||||
NET "clk" LOC = "C9" | IOSTANDARD = LVCMOS33 ;
|
||||
|
||||
# Slide Switches
|
||||
NET "switches<0>" LOC = "L13" | IOSTANDARD = LVCMOS33 | PULLUP ;
|
||||
NET "switches<1>" LOC = "L14" | IOSTANDARD = LVCMOS33 | PULLUP ;
|
||||
NET "switches<2>" LOC = "H18" | IOSTANDARD = LVCMOS33 | PULLUP ;
|
||||
NET "switches<3>" LOC = "N17" | IOSTANDARD = LVCMOS33 | PULLUP ;
|
||||
|
||||
# Rotary Encoder
|
||||
NET "rot_a" LOC = "K18" | IOSTANDARD = LVCMOS33 | PULLUP ;
|
||||
NET "rot_b" LOC = "G18" | IOSTANDARD = LVCMOS33 | PULLUP ;
|
||||
NET "rot_center" LOC = "V16" | IOSTANDARD = LVCMOS33 | PULLDOWN ;
|
||||
|
||||
# LCD Interface
|
||||
NET "lcd_e" LOC = "M18" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
|
||||
NET "lcd_rs" LOC = "L18" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
|
||||
NET "lcd_rw" LOC = "L17" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
|
||||
NET "lcd_d<4>" LOC = "R15" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
|
||||
NET "lcd_d<5>" LOC = "R16" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
|
||||
NET "lcd_d<6>" LOC = "P17" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
|
||||
NET "lcd_d<7>" LOC = "M15" | IOSTANDARD = LVCMOS33 | DRIVE = 4 | SLEW = SLOW ;
|
16
spartanTest/subtraction.v
Normal file
16
spartanTest/subtraction.v
Normal file
@ -0,0 +1,16 @@
|
||||
module subtraction (
|
||||
input [3:0] A, B,
|
||||
input BorrowIN,
|
||||
output [3:0] Y,
|
||||
output BorrowOUT //Overflow signal'ini yani negatif gonderecek
|
||||
);
|
||||
|
||||
wire [3:0] tempB;
|
||||
|
||||
// Full Subtraction logic for each bit (borrow-in for each subsequent bit)
|
||||
fullsubtraction f0 (.A(A[0]), .B(B[0]), .BorrowIN(BorrowIN), .Difference(Y[0]), .BorrowOut(tempB[0]));
|
||||
fullsubtraction f1 (.A(A[1]), .B(B[1]), .BorrowIN(tempB[0]), .Difference(Y[1]), .BorrowOut(tempB[1]));
|
||||
fullsubtraction f2 (.A(A[2]), .B(B[2]), .BorrowIN(tempB[1]), .Difference(Y[2]), .BorrowOut(tempB[2]));
|
||||
fullsubtraction f3 (.A(A[3]), .B(B[3]), .BorrowIN(tempB[2]), .Difference(Y[3]), .BorrowOut(BorrowOUT));
|
||||
|
||||
endmodule
|
41
spartanTest/subtractionTB.v
Normal file
41
spartanTest/subtractionTB.v
Normal file
@ -0,0 +1,41 @@
|
||||
module subtractionTB;
|
||||
|
||||
reg [3:0] A, B;
|
||||
reg BorrowIN;
|
||||
wire [3:0] Y;
|
||||
wire BorrowOUT;
|
||||
|
||||
// Instantiate the subtraction module
|
||||
subtraction uut (
|
||||
.A(A),
|
||||
.B(B),
|
||||
.BorrowIN(BorrowIN),
|
||||
.Y(Y),
|
||||
.BorrowOUT(BorrowOUT)
|
||||
);
|
||||
|
||||
initial begin
|
||||
$dumpfile("subtraction.vcd");
|
||||
$dumpvars;
|
||||
// Initialize inputs
|
||||
A = 4'b0000; // Set A to 0
|
||||
B = 4'b0000; // Set B to 0
|
||||
BorrowIN = 0; // No borrow input
|
||||
|
||||
// Apply test cases
|
||||
#10 A = 4'b0110; B = 4'b0010; BorrowIN = 0; // A = 6, B = 2
|
||||
#10 A = 4'b0010; B = 4'b0110; BorrowIN = 0; // A = 2, B = 6
|
||||
#10 A = 4'b1100; B = 4'b0100; BorrowIN = 0; // A = -4, B = 4
|
||||
#10 A = 4'b1000; B = 4'b1000; BorrowIN = 0; // A = -8, B = -8
|
||||
#10 A = 4'b1111; B = 4'b0001; BorrowIN = 1; // A = -1, B = 1, with borrow input
|
||||
|
||||
// Wait for the results
|
||||
#10 $finish;
|
||||
end
|
||||
|
||||
//initial begin
|
||||
// Monitor the values of Y and overflow
|
||||
// $monitor("At time %t: A = %b, B = %b, Y = %b, BorrowOut = %b, overflow = %b", $time, A, B, Y, BorrowOut, overflow);
|
||||
//end
|
||||
|
||||
endmodule
|
61
spartanTest/switchRotary.v
Normal file
61
spartanTest/switchRotary.v
Normal file
@ -0,0 +1,61 @@
|
||||
module switchRotary(
|
||||
input clk, // Clock signal
|
||||
input [3:0] switches, // Slide switches SW3 to SW0
|
||||
input rot_a, rot_b, // Rotary encoder signals
|
||||
input rot_center, // Rotary encoder push button
|
||||
output reg [3:0] A = 0, // Value of A
|
||||
output reg [3:0] B = 0, // Value of B
|
||||
output reg [2:0] opCode = 0 // Value of opCode
|
||||
);
|
||||
// Internal signals for rotary encoder
|
||||
reg [1:0] rot_state = 2'b00;
|
||||
reg [1:0] rot_prev = 2'b00;
|
||||
|
||||
// Selected register for modification
|
||||
reg [1:0] selected = 2'b00; // 0 = A, 1 = B, 2 = opCode
|
||||
|
||||
// Debouncing for rotary center button
|
||||
reg [15:0] debounce_counter = 0;
|
||||
reg debounce_pressed = 0;
|
||||
|
||||
// Update selected register on rotary center press
|
||||
always @(posedge clk) begin
|
||||
if (rot_center && !debounce_pressed) begin
|
||||
debounce_pressed <= 1;
|
||||
selected <= selected + 1;
|
||||
end
|
||||
if (!rot_center) begin
|
||||
debounce_pressed <= 0;
|
||||
end
|
||||
end
|
||||
|
||||
// Handle rotary encoder signals
|
||||
always @(posedge clk) begin
|
||||
rot_prev <= rot_state;
|
||||
rot_state <= {rot_a, rot_b};
|
||||
|
||||
// Detect clockwise or counterclockwise rotation
|
||||
if (rot_prev == 2'b01 && rot_state == 2'b11) begin
|
||||
case (selected)
|
||||
2'b00: if (A < 15) A <= A + 1;
|
||||
2'b01: if (B < 15) B <= B + 1;
|
||||
2'b10: if (opCode < 7) opCode <= opCode + 1;
|
||||
endcase
|
||||
end else if (rot_prev == 2'b11 && rot_state == 2'b01) begin
|
||||
case (selected)
|
||||
2'b00: if (A > 0) A <= A - 1;
|
||||
2'b01: if (B > 0) B <= B - 1;
|
||||
2'b10: if (opCode > 0) opCode <= opCode - 1;
|
||||
endcase
|
||||
end
|
||||
end
|
||||
|
||||
// Update A, B, or opCode based on switches
|
||||
always @(posedge clk) begin
|
||||
case (switches)
|
||||
4'b0001: A <= switches[3:0];
|
||||
4'b0010: B <= switches[3:0];
|
||||
4'b1000: opCode <= switches[2:0];
|
||||
endcase
|
||||
end
|
||||
endmodule
|
62
spartanTest/top.v
Normal file
62
spartanTest/top.v
Normal file
@ -0,0 +1,62 @@
|
||||
module top (
|
||||
input clk, // Clock signal
|
||||
input [3:0] switches, // Slide switches SW3 to SW0
|
||||
input rot_a, rot_b, // Rotary encoder signals
|
||||
input rot_center, // Rotary encoder push button
|
||||
output lcd_rs, // LCD Register Select
|
||||
output lcd_rw, // LCD Read/Write
|
||||
output lcd_e, // LCD Enable
|
||||
output [7:4] lcd_d // LCD Data
|
||||
);
|
||||
// Internal signals
|
||||
wire [3:0] A;
|
||||
wire [3:0] B;
|
||||
wire [2:0] opCode;
|
||||
wire [7:0] Y;
|
||||
wire [4:0] mem_addr;
|
||||
wire [7:0] mem_bus;
|
||||
|
||||
// ALU Instance
|
||||
ALU alu_inst (
|
||||
.A(A),
|
||||
.B(B),
|
||||
.CarryIN(1'b0), // No carry-in for this implementation
|
||||
.opCodeA(opCode),
|
||||
.Y(Y),
|
||||
.CarryOUT(), // Unused output
|
||||
.overflow() // Unused output
|
||||
);
|
||||
|
||||
// Switch and Rotary Controller
|
||||
switch_and_rotary switch_rotary_inst (
|
||||
.clk(clk),
|
||||
.switches(switches),
|
||||
.rot_a(rot_a),
|
||||
.rot_b(rot_b),
|
||||
.rot_center(rot_center),
|
||||
.A(A),
|
||||
.B(B),
|
||||
.opCode(opCode)
|
||||
);
|
||||
|
||||
// Character Memory
|
||||
char_mem char_mem_inst (
|
||||
.addr(mem_addr),
|
||||
.bus(mem_bus),
|
||||
.A(A),
|
||||
.B(B),
|
||||
.opCode(opCode),
|
||||
.Y(Y)
|
||||
);
|
||||
|
||||
// LCD Controller
|
||||
lcd lcd_inst (
|
||||
.clk(clk),
|
||||
.lcd_rs(lcd_rs),
|
||||
.lcd_rw(lcd_rw),
|
||||
.lcd_e(lcd_e),
|
||||
.lcd_d(lcd_d),
|
||||
.mem_addr(mem_addr),
|
||||
.mem_bus(mem_bus)
|
||||
);
|
||||
endmodule
|
Reference in New Issue
Block a user