Structural Counter 8
Structural Counter 8
module Counter8_tp(
input CLK100MHZ, BTNR, BTNL, BTND, [15:0] SW,
output CA, CB, CC, CD, CE, CF, CG, DP, [7:0] AN );
endmodule
//////////////////////////////////////////////////////////////////////////////////
//
// Create Date: 23:23:54 04/21/2012
// Author: Roman Lysecky
//
// modified by SJKranock 2019/12/25
// parameter DivVal = xxxxxxxxxxxxxxxxxxxxxxxx
//
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
// Create Date: 23:23:54 04/21/2012
// Author: Roman Lysecky
//
// modified by SJKranock 2019/12/25
// parameter DivVal = xxxxxxxxxxxxxxxxxxxxxxxx
//
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// Engineer: Kranock
// Create Date: 2017/10/07
// Description: Inverts 8 discrete inputs
//////////////////////////////////////////////////////////////////////////////////
module Invert8( input In0, In1, In2, In3, In4, In5, In6, In7,
output reg Out0, Out1, Out2, Out3, Out4, Out5, Out6, Out7 );
always @ ( In0, In1, In2, In3, In4, In5, In6, In7 ) begin
Out0 = ~In0;
Out1 = ~In1;
Out2 = ~In2;
Out3 = ~In3;
Out4 = ~In4;
Out5 = ~In5;
Out6 = ~In6;
Out7 = ~In7;
end
endmodule
if ( ClkOut ) begin
Mux[0] = Count[4];
Mux[1] = Count[5];
Mux[2] = Count[6];
Mux[3] = Count[7];
end
else begin
Mux[0] = Count[0];
Mux[1] = Count[1];
Mux[2] = Count[2];
Mux[3] = Count[3];
end
end
endmodule
module SSD(
input In3, In2, In1, In0,
output reg SegA, SegB, SegC, SegD, SegE, SegF, SegG );
SegA = (~In3&~In2&~In1&~In0)|(~In3&~In2&In1&~In0)|(~In3&~In2&In1&In0)|
(~In3&In2&~In1&In0)|(~In3&In2&In1&~In0)|(~In3&In2&In1&In0)|(In3&~In2&~In1&~In0)|
(In3&~In2&~In1&In0)|(In3&~In2&In1&~In0)|(In3&In2&~In1&~In0)|(In3&In2&In1&~In0)|
(In3&In2&In1&In0);
SegB = (~In3&~In2&~In1&~In0)|(~In3&~In2&~In1&In0)|(~In3&~In2&In1&~In0)|
(~In3&~In2&In1&In0)|(~In3&In2&~In1&~In0)|(~In3&In2&In1&In0)|(In3&~In2&~In1&~In0)|
(In3&~In2&~In1&In0)|(In3&~In2&In1&~In0)|(In3&In2&~In1&In0);
SegC = (~In3&~In2&~In1&~In0)|(~In3&~In2&~In1&In0)|(~In3&~In2&In1&In0)|
(~In3&In2&~In1&~In0)|(~In3&In2&~In1&In0)|(~In3&In2&In1&~In0)|(~In3&In2&In1&In0)|
(In3&~In2&~In1&~In0)|(In3&~In2&~In1&In0)|(In3&~In2&In1&~In0)|(In3&~In2&In1&In0)|
(In3&In2&~In1&In0);
SegD = (~In3&~In2&~In1&~In0)|(~In3&~In2&In1&~In0)|(~In3&~In2&In1&In0)|
(~In3&In2&~In1&In0)|(~In3&In2&In1&~In0)|(In3&~In2&~In1&~In0)|(In3&~In2&In1&In0)|
(In3&In2&~In1&In0)|(In3&In2&In1&~In0)|(In3&In2&~In1&~In0);
SegE = (~In3&~In2&~In1&~In0)|(~In3&~In2&In1&~In0)|(~In3&In2&In1&~In0)|
(In3&~In2&~In1&~In0)|(In3&~In2&In1&~In0)|(In3&~In2&In1&In0)|(In3&In2&~In1&~In0)|
(In3&In2&~In1&In0)|(In3&In2&In1&~In0)|(In3&In2&In1&In0);
SegF = (~In3&~In2&~In1&~In0)|(~In3&In2&~In1&~In0)|(~In3&In2&~In1&In0)|
(~In3&In2&In1&~In0)|(In3&~In2&~In1&~In0)|(In3&~In2&~In1&In0)|(In3&~In2&In1&~In0)|
(In3&~In2&In1&In0)|(In3&In2&~In1&~In0)|(In3&In2&In1&~In0)|(In3&In2&In1&In0);
SegG = (~In3&~In2&In1&~In0)|(~In3&~In2&In1&In0)|(~In3&In2&~In1&~In0)|
(~In3&In2&~In1&In0)|(~In3&In2&In1&~In0)|(In3&~In2&~In1&~In0)|(In3&~In2&~In1&In0)|
(In3&~In2&In1&~In0)|(In3&~In2&In1&In0)|(In3&In2&~In1&In0)|(In3&In2&In1&~In0)|
(In3&In2&In1&In0);
end
endmodule
module Counter8(
input Clock,
input Reset,
input Pause,
input Up,
output reg [7:0] Count);
wire [7:0]CountNext;
wire [7:0]Answer;
wire [7:0]CountPlus;
wire [7:0]CountMinus;
wire eq_27;
wire eq_0;
wire [7:0]Increasing;
wire [7:0]Decreasing;
//Incrementer-Decrementer
Incrementer Audi(Count, 1, CountPlus);
Decrementer Subaru( Count, 1, 1, CountMinus);
//Comparators
Comparator_8 NissanMaxima(Count, 39, eq_27, lt_27, gt_27);
Comparator_8 MiniCooper(Count, 0, eq_0, lt_0, gt_0);
//Muxes
Mux_16x8 Lamborghini(eq_27, CountPlus, 0, Increasing);
Mux_16x8 Ferrari(eq_0, CountMinus, 39, Decreasing);
Mux_16x8 Dealership(Up, Decreasing, Increasing , Answer);
// Register
Register Registration(Clock, Reset, ~Pause, Answer, CountNext);
endmodule
module Incrementer(
input [7:0]A, B,
output reg [7:0]S);
wire c0, c1, c2, c3, c4, c5, c6, c7, s0, s1, s2, s3, s4, s5, s6, s7;
always @(s0, s1, s2, s3, s4, s5, s6, s7) begin
S[0] = s0;
S[1] = s1;
S[2] = s2;
S[3] = s3;
S[4] = s4;
S[5] = s5;
S[6] = s6;
S[7] = s7;
end
endmodule
module Decrementer(
input [7:0]A, [7:0]B, C,
output reg [7:0]D);
wire c0, c1, c2, c3, c4, c5, c6, c7, s0, s1, s2, s3, s4, s5, s6, s7, y0, y1,
y2, y3, y4, y5, y6, y7, x0, x1, x2, x3, x4, x5, x6, x7;
always @(x0, x1, x2, x3, x4, x5, x6, x7) begin
D[0] = x0;
D[1] = x1;
D[2] = x2;
D[3] = x3;
D[4] = x4;
D[5] = x5;
D[6] = x6;
D[7] = x7;
end
endmodule
module Full_Adder(
input A, B, cin,
output reg co, reg S);
wire F, G, H, W, X, Y, Z, M, N;
AND_2x1(A, B, F);
AND_2x1(A, cin, G);
AND_2x1(B, cin, H);
OR_3x1(F, G, H, M);
endmodule
module Half_Adder(
input A, B,
output reg co, reg S);
wire W, X, Y, Z;
AND_2x1(A, B, W);
AND_2x1(A, ~B, X);
AND_2x1(~A, B, Y);
OR_2x1(X, Y, Z);
endmodule
module Comparator_8(
input [7:0]A, [7:0]B,
output reg eqo, reg lto, reg gto);
wire eq0, eq1, eq2, eq3, eq4, eq5, eq6, eq7, lt0, lt1, lt2, lt3, lt4, lt5, lt6,
lt7, gt0, gt1, gt2, gt3, gt4, gt5, gt6, gt7;
endmodule
module Comparator(
input A, B, eqi, lti, gti,
output reg eq, reg lt, reg gt);
wire W, X, Y, Z, F, L, E, G;
AND_2x1(A, B, Y);
AND_2x1(~A, ~B, Z);
OR_2x1(Y, Z, F);
AND_2x1(eqi, F, E);
endmodule
module Mux_16x8(
input S, [7:0]A, [7:0]B,
output reg [7:0]Y);
always @(y0, y1, y2, y3, y4, y5, y6, y7) begin
Y[7] = y7;
Y[6] = y6;
Y[5] = y5;
Y[4] = y4;
Y[3] = y3;
Y[2] = y2;
Y[1] = y1;
Y[0] = y0;
end
endmodule
module Mux_2x1(
input S, A, B,
output reg Z);
wire X, Y;
AND_2x1(S, B, W);
AND_2x1(~S, B, X);
OR_2x1(W, X, Y);
endmodule
module Register(
input clk, clr, id, [7:0]D,
output reg [7:0]Q);
wire y7, y6, y5, y4, y3, y2, y1, y0, x0, x1, x2, x3, x4, x5, x6, x7;
always @(x0, x1, x2, x3, x4, x5, x6, x7) begin
Q[7] = x7;
Q[6] = x6;
Q[5] = x5;
Q[4] = x4;
Q[3] = x3;
Q[2] = x2;
Q[1] = x1;
Q[0] = x0;
end
endmodule
module Mux_4x1(
input s1, s0, i3, i2, i1, i0,
output reg Y);
wire A, B, C, D;
endmodule
module DFlipFlop(
input clk, d,
output reg q);
DLatch(~clk, d, q1);
DLatch(clk, q1, q0);
endmodule
module DLatch(
input e, d,
output reg q);
endmodule
endmodule
endmodule
`timescale 1ns / 1ps
endmodule
endmodule
endmodule
endmodule