verilog HDL基础程序(6)

2019-04-09 20:32

8'h33: seg_data=8'b10110000; 8'h34: seg_data=8'b10011001; 8'h35: seg_data=8'b10010010; 8'h36: seg_data=8'b10000010; 8'h37: seg_data=8'b11111000; 8'h38: seg_data=8'b10000000; 8'h39: seg_data=8'b10010000; 8'h41: seg_data=8'b10001000;//a 8'h42: seg_data=8'b10000011; 8'h43: seg_data=8'b11000110; 8'h44: seg_data=8'b10100001; 8'h45: seg_data=8'b10000110; 8'h46: seg_data=8'b10001110; default: seg_data=8'b11111111; endcase end

endmodule

点阵显示爱心形

//本实验学习点阵模块的使用

//其实原理和使用动态数码管的原理一样的 //在点阵上面显示一个爱心

//视频教程适合我们21EDA电子的所有学习板 module led_0_7 (clk,rst,dataout,en);

input clk,rst; //系统时钟50M输入 从12脚输入。 output[7:0] dataout; //数码管的段码输出 output[7:0] en; //数码管的位选使能输出 reg[7:0] dataout; reg[7:0] en;

reg[15:0] cnt_scan;//扫描频率计数器 reg[4:0] dataout_buf;

always@(posedge clk or negedge rst) begin if(!rst) begin cnt_scan<=0; end else begin cnt_scan<=cnt_scan+1; end end

always @(cnt_scan) begin

case(cnt_scan[15:13]) 3'b000 :

en = 8'b1111_1110; 3'b001 :

en = 8'b1111_1101; 3'b010 :

en = 8'b1111_1011; 3'b011 :

en = 8'b1111_0111; 3'b100 :

en = 8'b1110_1111; 3'b101 :

en = 8'b1101_1111; 3'b110 :

en = 8'b1011_1111; 3'b111 :

en = 8'b0111_1111; default :

en = 8'b1111_1110; endcase end

always@(en) //对应COM信号给出各段数据 begin case(en) 8'b1111_1110: dataout_buf=0; 8'b1111_1101: dataout_buf=1; 8'b1111_1011: dataout_buf=2; 8'b1111_0111:

dataout_buf=3; 8'b1110_1111: dataout_buf=4; 8'b1101_1111: dataout_buf=5; 8'b1011_1111: dataout_buf=6; 8'b0111_1111: dataout_buf=7; default: dataout_buf=8; endcase end

always@(dataout_buf) begin

//在点阵上面显示一个爱心需要的点阵代码 case(dataout_buf) 4'b0000: dataout=8'b11111111; 4'b0001: dataout=8'b11111111; 4'b0010: dataout=8'b10011001; 4'b0011: dataout=8'b01100110; 4'b0100: dataout=8'b01111110; 4'b0101: dataout=8'b10111101; 4'b0110: dataout=8'b11011011; 4'b0111: dataout=8'b11100111; endcase end

endmodule 多路选择器

//学习多路选择器的原理,

//拨码开关的 4 作为A的输入

//多路选择器,a为1则选择b,为0则选择c, //拨码开关的 1 2 3 作为B的输入 //拨码开关的 6 7 8 作为C的输入 //结果输出到数码管显示

//当然如果你的学习板没有拨码开关,可以用key1 key2 key3 key4 作为输入。

//视频教程适合我们21EDA电子的所有学习板 module mux(a,b,c,d,en);

input a; //拨码开关的 4 作为A的输入

//多路选择器,a为1则选择b,为0则选择c input[2:0]b; //拨码开关的 1 2 3 作为B的输入 input[2:0]c; //拨码开关的 6 7 8 作为C的输入 output[7:0] d; //7段码显示的段码 reg[7:0] d; output en;

wire[3:0] d_tmp; assign en=0;

assign d_tmp=a? b:c; always@(d_tmp) begin

//下面是7段码显示的段码 case(d_tmp) 4'b0000: d=8'b11000000; 4'b0001: d=8'b11111001; 4'b0010: d=8'b10100100; 4'b0011: d=8'b10110000; 4'b0100: d=8'b10011001; 4'b0101: d=8'b10010010; 4'b0110: d=8'b10000010; 4'b0111: d=8'b11111000; 4'b1000: d=8'b10000000; 4'b1001: d=8'b10010000; 4'b1010: d=8'b10001000; 4'b1011: d=8'b10000011; 4'b1100: d=8'b11000110; 4'b1101: d=8'b10100001;

4'b1110: d=8'b10000110; 4'b1111: d=8'b10001110; endcase end

endmodule // 没弄明白

二进制转BCD码

4位二进制数转BCD码,由键盘输入,结果由数码管显示 module bcd (clk,a,c,en ) input clk; input [3:0] a ; output[7:0] c ; reg [7:0] c ; output[1:0] en ; reg[1:0] en;

reg[7:0] code_data; reg[3:0] c_tmp; reg[19:0] cnt;

always@(posedge clk ) begin

if(cnt!=20'h5ffff) cnt<=cnt+1; else cnt<=0; end

always@(posedge clk ) begin if(cnt==20'h5ffff) en<=~en; end always@(en) begin case(en) 2'b01: c_tmp=code_data[3:0]; 2'b10: c_tmp=code_data[7:4]; default: c_tmp=0; endcase end


verilog HDL基础程序(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:冲孔灌注桩专项施工方案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: