2017.8.28 编码器,半加器,全加器,led related
今天的任务:
1.基于Cyclone IV的EP4CE6E22C8N芯片的编码器;试验成功;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 module encoder(I,O,enable); 2 input [3:0] I; 3 input enable; 4 output [1:0] O; 5 reg [1:0] O; 6 7 always@(I,enable) 8 begin 9 if(enable) O=4'b11; 10 else 11 case(I) 12 4'b1110: O=2'b11; 13 4'b1101: O=2'b10; 14 4'b1011: O=2'b01; 15 4'b0111: O=2'b00; 16 default: O=2'b11; 17 endcase 18 end 19 endmodule
2.半加器;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 module half_adder(a,b,c,Co); 2 input a,b; 3 output c,Co; 4 assign c=a^b; 5 assign Co=a*b; 6 endmodule
3.全加器;
1 module all_adder(a,b,Ci,c,Co); 2 input a,b,Ci; 3 output c,Co; 4 assign c=a^b^Ci; 5 assign Co=a*b+a*Ci+b*Ci; 6 endmodule
4.全加器(模块法);
1 module all_adder(a,b,Ci,c,Co); 2 input a,b,Ci; 3 output c,Co; 4 wire C1,C2; 5 assign Co=C1|C2; 6 half adder half adder0(.a(a), .b(b), .c(A0), .Co(C1)); 7 half adder half adder1(.a(A0), .b(Ci), .c(c), .Co(C2)); 8 endmodule