赞
踩
【2022.04西南交大数电实验】
【本代码及波形已通过老师验收。仅供参考。】
与实验3大同小异,仅有两处不同:
1)用数码管显示计数值, 数码管位选信号 seg0固定为 1 seg[7..1]固定为0
2)clkin锁定到 CLK1 PIN_89
顶层设计 :
- module yck_1716_4_1(codeout, Q, clkin, clr, CO, upd, en, load, seg, data);
- input clkin, clr, upd, en, load;
- input [3: 0] data;
- output [6: 0] codeout;
- output [3: 0] Q;
- output [7: 0]seg;
- output CO;
- yck_1716_4_2(clkin, clr, Q, CO, upd, en, load, data);
- yck_1716_4_3(codeout, Q, seg);
- endmodule
子模块:
- module yck_1716_4_2(clkin, clr, Q, CO, upd, en, load, data); //十进制计数器
- input clkin, clr, upd, en, load;
- input [3: 0] data;
- output [3: 0] Q;
- reg [3: 0] Q;
- output wire CO;
- always@(posedge clkin, negedge clr)
- if(!clr) //异步清零
- Q <= 4'd0;
- else if(!load) //同步置数(若为低电平则直接赋值,数码管显示本时刻数值)
- Q <= data;
- else if(en) //使能(en高电平)
- begin
- if(upd) //同步置数,加法计数(upd=1)
- begin
- if(Q == 4'd9)
- Q <= 4'd0;
- else
- Q <= Q + 4'd1;
- end
- else //同步置数,减法计数(upd=0)
- begin
- if(Q == 4'd0)
- Q <= 4'd9;
- else
- Q <= Q - 4'd1;
- end
- end
- assign CO = (upd & (Q == 4'd9)) | (~upd & (Q == 4'd0) & clr); //(upd为高电平且Q为9)或者(upd为低电平且Q为0且clk为0)
- endmodule
- module yck_1716_4_3(codeout, Indec, seg); //译码器
- input [3: 0] Indec;
- output [6: 0] codeout;
- reg [6: 0] codeout;
- output [7: 0]seg;
- assign seg[0] = 1;
- assign seg[7: 1] = 0;
- always@(Indec)
- begin
- case(Indec)
- 4'b0000: codeout = 7'b1111110;
- 4'b0001: codeout = 7'b0110000;
- 4'b0010: codeout = 7'b1101101;
- 4'b0011: codeout = 7'b1111001;
- 4'b0100: codeout = 7'b0110011;
- 4'b0101: codeout = 7'b1011011;
- 4'b0110: codeout = 7'b1011111;
- 4'b0111: codeout = 7'b1110000;
- 4'b1000: codeout = 7'b1111111;
- 4'b1001: codeout = 7'b1111011;
- default: codeout = 7'bx;
- endcase
- end
- endmodule
信号名 | 主板器件 | PIN | 信号名 | 主板器件 | PIN | |
clr | SW0 | PIN_24 | codeout[3] | d | PIN_111 | |
en | SW1 | PIN_31 | codeout[4] | c | PIN_104 | |
upd | SW2 | PIN_30 | codeout[5] | b | PIN_100 | |
load | SW3 | PIN_33 | codeout[6] | a | PIN_112 | |
CO | IO4/LED4 | PIN_58 | clkin | CLK1/IO28 | PIN_89 | |
q[0] | IO0/LED0 | PIN_46 | data[3] | SW7 | PIN_44 | |
q[1] | IO1/LED1 | PIN_50 | data[2] | SW6 | PIN_39 | |
q[2] | IO2/LED2 | PIN_52 | data[1] | SW5 | PIN_42 | |
q[3] | IO3/LED3 | PIN_54 | data[0] | SW4 | PIN_32 | |
codeout[0] | g | PIN_103 | seg0 | SEG0 | PIN_119 | |
codeout[1] | f | PIN_110 | seg1 | SEG1 | PIN_126 | |
codeout[2] | e | PIN_106 | seg2 | SEG2 | PIN_115 | |
信号名 | 主板器件 | PIN | ||||
seg3 | SEG3 | PIN_125 | ||||
seg4 | SEG4 | PIN_114 | ||||
seg5 | SEG5 | PIN_121 | ||||
seg6 | SEG6 | PIN_113 | ||||
seg7 | SEG7 | PIN_120 |
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。