文档详情

数字电子技术基础.ppt

发布:2017-09-25约字共106页下载文档
文本预览下载声明
作者:信息与电子工程系 屈民军 学时分配:共8学时 教学目标:通过本章的学习,掌握Verilog HDL硬件描述语言。 二 initial过程块 7.8.3 while和forever语句 第七章 用Verilog HDL设计数字电路 7.9 常用组合电路的设计 7.9.2译码器、编码器 7.9.3 数据选择器 7.9.4 奇偶校验器 7. 9 .5 :BCD码-七段 译码器(共阴) 7.9.6 运算电路(补充) 一、加法器: 二、比较器 7.10 常用时序电路模块的设计 7.10.1 D触发器 7.10.2 数据锁存器(latch) 7.10.3 数据寄存器 7.10.4 移位寄存器(单向) 7.10.5 计数器 一、可预置的n位二进制计数器(带异步清0) 二、任意进制计数器(带异步清0) 三、可预置的加减计数器 四、BCD码计数器 习题: 例. 8位数据寄存器 module reg8(out_data,in_data,clk,clr); output[7:0] out_data; input clk,clr; input[7:0] in_data; reg[7:0] out_data; always @ (posedge clk or posedge clr) begin if(clr) out_data =0; else out_data = in_data; end endmodule C1 1D out_data in_data clk 8 8 clr R 数据锁存器与数据寄存器的差别? 电平触发 边沿触发 module shifter(din , clk , clr ,dout); parameter n=8; input din , clk , clr; output[8:1] dout ; reg[8:1] dout; always @(posedge clk) begin if (clr) dout = 0; // 同步清0,高电平有效 else begin dout = dout 1;//输出信号左移一位 dout[1] = din; //输入信号补充到输出信号的最低位 end end endmodule SRG8 1R C1/ 1D clr clk din dout1 dout8 注意:左移定义 Verilog HDL:低位移向高位 数字电路: 高位移向低位 a a * b a左移2位 + a左移4位 + a左移7位 乘法方法: 例7.11 8位二进制乘法器 module mult_for (outcome,a,b); parameter size=8 ; output[2*size:1] outcome; input[size:1] a,b; //乘数 reg[2*size:1] outcome; //积 integer i; always @(a or b) begin outcome=0; for (i=1;i=size;i=i+1) if(b[i]) outcome=outcome+( a(i-1) ) ; end endmodule for 语句 为0时:左移i-1位 1. 语法: repeat (循环次数表达式 ) 循环体语句或语句块; 2. 例7.11 用 repeat语句实现8位乘法器 module mult_repeat(outcome,a,b); parameter size=8 ; output[2*size:1] outcome; input[size:1] a,b; reg[2*size:1] outcome,temp_a; reg[size:1] temp_b; always @(a or b) begin outcome=0; temp_a=a; temp_b=b; repeat(size) begin if(temp_b[1]) outcome=outcome+temp_a ; temp_a=temp_a 1;// temp_b=temp_b 1;// end end endmodule 循环体语句块; 注意: MAX+P
显示全部
相似文档