数字电路 用verilog hdl语言 语言 Quartus ll程序 完成二十四进制加减法计算器(代码 波形图 引脚分配)

当前位置: >>
4―2线优先编码器和十进制加减计数器
Verilog4―2 线优先编码器和十进制加减计数器4―2 线优先编码器:根据 4 线―2 线优先编码器的逻辑表:输入 I0 1 × × × I1 0 1 × × I2 0 0 1 × I3 0 0 0 1 Y1 0 0 1 1 输出 Y2 0 1 0 1可以得出输入与输出的逻辑表达式为: Y0=I2+I3 Y1=I1(~I2)+I3 根据此逻辑关系,写出 verilog 代码: module _4to2(I,Y0,Y1); input [3:0]I; output Y0,Y1; wire no1,no2; not (no1,I[2]); //对 I2 取反 and (no2,I[1],no1); // I1&&(~I2) assign Y1=(no2|I[3]); // Y1=I1(~I2)+I3 assign Y0=(I[2]|I[3]); // Y0=I2+I3 endmodule 仿真波形:十进制加减计数器:代码: module ten_2(rst,initial_value,clk,choose,oSEG,count); input clk,rst, //50MHZ,复位按钮,加减选择档 input[3:0]initial_ //初值置数 output[7:0]oSEG //数码管显示; output[3:0] //LED 灯显示 wire[3:0]count1; //1HZ devide_f u1(cp,rst,clk); //分频 ADD_SUB u2( cp,rst,choose,initial_value,count); //加减计数 display_LUT u3(oSEG,count1); //数码管译码显示 assign count1=count; endmodulemodule display_LUT (oSEG,count1); input [3:0]count1; output[7:0]oSEG; reg [7:0]oSEG1; always @(count1) begin case(count1) 4'h0: oSEG1 = 8'b; //对应译码 4'h1: oSEG1= 8'b'h2: oSEG1 = 8'b'h3: oSEG1 = 8'b'h4: oSEG1 = 8'b'h5: oSEG1 = 8'b'h6: oSEG1 = 8'b'h7: oSEG1 = 8'b'h8: oSEG1 = 8'b'h9: oSEG1 = 8'b'ha: oSEG1 = 8'b'hb: oSEG1 = 8'b'hc: oSEG1 = 8'b'hd: oSEG1 = 8'b'he: oSEG1 = 8'b'hf: oSEG1 = 8'b; endcase end assign oSEG=~oSEG1; //低电平显示有效,所以取反 endmodule module ADD_SUB( cp,rst,choose,initial_value,count); input [3:0]initial_ //初值置数,通过拨码开关得到 input cp,rst, output[3:0] reg [3:0] always@(posedge cp or negedge rst )begin //检测时钟或者是否复位 if(~rst)begin if(choose) count&=4'b0000; //加计数复位为 0 else count&=initial_end //减计数复位为初值 else begin if(choose)begin if(count==initial_value) count&=4'b0000; //加计数到置数后, 0 开始 从 else count&=count+4'b0001; end else begin if(count==4'b0000) count&=initial_ else count&=count-4'b0001;end end end endmodule//减计数从置数值减到 0module devide_f(_1HZ,nCR,_50MHZ); input _50MHZ,nCR; output _1HZ; reg _1HZ; reg[31:0]Q; always@(posedge _50MHZ )begin//分频函数if(~nCR)Q=32'd0; if(Q&=32'd)begin // 加到 24 999999 后取反一次,这样每 5M 刚好为 1HZ Q&=32'd0; _1HZ=~_1HZ;end else Q&=Q+1'd1; end endmodule

我要回帖

更多关于 verilog语言入门教程 的文章

 

随机推荐