|
- module cd4070( //四组二输入一输出端异或门 VCC:Pin14 GND:Pin7
- input A1, //异或输入 Pin1
- input B1, //异或输入 Pin2
- output Y1, //异或输出 Pin3
- input A2, //Pin5
- input B2, //Pin6
- output Y2, //Pin4
-
- input A3, //Pin8
- input B3, //Pin9
- output Y3, //Pin10
-
- input A4, //Pin12
- input B4, //Pin13
- output Y4 //Pin11
- );
- assign {Y1,Y2,Y3,Y4} = {A1,A2,A3,A4} ^ {B1,B2,B3,B4};
- endmodule
- module main(
- input clk, //时钟输入
- output reg led //低电平(计算正确)点亮
- );
- reg [3:0] A;
- reg [3:0] B;
- wire [3:0] Y;
- cd4070 U1(
- .A1(A[0]),
- .B1(B[0]),
- .Y1(Y[0]),
- .A2(A[1]),
- .B2(B[1]),
- .Y2(Y[1]),
- .A3(A[2]),
- .B3(B[2]),
- .Y3(Y[2]),
- .A4(A[3]),
- .B4(B[3]),
- .Y4(Y[3])
- );
- always @(posedge clk) begin
- {A,B} <= {A,B} + 4'd1;
- if(A^B == Y) begin
- led <= 1'b0;
- end else begin
- led <= 1'b1;
- end
- end
- endmodule
复制代码
|
|