📄 leddisp.v
字号:
//LEDDisp.v v0.93 2006-04-24
//八位数码管动态译码显示,与FPGA母板配套
//时钟:clk用M为单位输入
//扫描频率:约122Hz
//闪烁频率:约1.6Hz
//data:8×4位输入BCD数据
//mode:8*4位显示模式。每位4比特,其中最高位灭灯(1有效),次高位为闪烁位(1有效)
// 低位为显示扩展位(1有效),次低位为小数点显示位(1有效)
//8段输出segout和8位输出posout均带锁存
//segdir、posdir分别为段码、位码输出的245方向控制位
//引脚连接说明:
//时钟引脚 Clk-PIN17;
//位码引脚 posout[0]/PIN119/LCS8(右)-posout[1]/PIN112/LCS7-posout[2]/PIN110/LCS6-posout[3]/PIN108/LCS5;
//位码引脚 posout[4]/PIN106/LCS4-posout[5]/PIN104/LCS3-posout[6]/PIN100/LCS2-posout[7]/PIN98/LCS1(左);
//段码引脚 segout[0]/PIN132/SEGA-segout[1]/PIN134/SEGB-segout[2]/PIN140/SEGC-segout[3]/PIN142/SEGD;
//段码引脚 segout[4]/PIN144/SEGE-segout[5]/PIN3/SEGF-segout[6]/PIN6/SEGG-segout[7]/PIN10/SEGH;
//245方向引脚 posdir-PIN35;segdir-PIN41
module LEDDisp(clk,data,mode,segout,posout,segdir,posdir);
input clk;
input [31:0] data;
input [31:0] mode;
parameter CLKxM = 10;
output segdir,posdir;
output [7:0] segout;
output [7:0] posout;
reg [7:0] segout;
reg [7:0] posout;
integer i,j;
assign segdir = 1'b1;
assign posdir = 1'b1;
always @(posedge clk)
begin
i = i + 1;
if((i>>10)==CLKxM)
begin
case(posout)
8'b11111110: begin posout=8'b11111101;segout=codelist({mode[7:4],data[7:4]}); end
8'b11111101: begin posout=8'b11111011;segout=codelist({mode[11:8],data[11:8]}); end
8'b11111011: begin posout=8'b11110111;segout=codelist({mode[15:12],data[15:12]}); end
8'b11110111: begin posout=8'b11101111;segout=codelist({mode[19:16],data[19:16]}); end
8'b11101111: begin posout=8'b11011111;segout=codelist({mode[23:20],data[23:20]}); end
8'b11011111: begin posout=8'b10111111;segout=codelist({mode[27:24],data[27:24]}); end
8'b10111111: begin posout=8'b01111111;segout=codelist({mode[31:28],data[31:28]}); end
default: begin posout=8'b11111110;segout=codelist({mode[3:0],data[3:0]}); end
endcase
i = 0;
j = j + 1;
end
end
function [7:0] codelist;
input [7:0] codeno;
begin
case(codeno&8'hbf)
8'h00: codelist=8'h3f;//0
8'h01: codelist=8'h06;//1
8'h02: codelist=8'h5b;//2
8'h03: codelist=8'h4f;//3
8'h04: codelist=8'h66;//4
8'h05: codelist=8'h6d;//5
8'h06: codelist=8'h7d;//6
8'h07: codelist=8'h07;//7
8'h08: codelist=8'h7f;//8
8'h09: codelist=8'h6f;//9
8'h0a: codelist=8'h77;//A
8'h0b: codelist=8'h7c;//b
8'h0c: codelist=8'h39;//C
8'h0d: codelist=8'h5e;//d
8'h0e: codelist=8'h79;//E
8'h0f: codelist=8'h71;//F
8'h10: codelist=8'h00;//全灭
8'h11: codelist=8'h80;//小数点
8'h12: codelist=8'h40;//减号
8'h1f: codelist=8'h06;//全亮
8'h20: codelist=8'hbf;//0.
8'h21: codelist=8'h86;//1.
8'h22: codelist=8'hdb;//2.
8'h23: codelist=8'hcf;//3.
8'h24: codelist=8'he6;//4.
8'h25: codelist=8'hed;//5.
8'h26: codelist=8'hfd;//6.
8'h27: codelist=8'h87;//7.
8'h28: codelist=8'hef;//8.
8'h29: codelist=8'hef;//9.
8'h2a: codelist=8'hf7;//A.
8'h2b: codelist=8'hfc;//b.
8'h2c: codelist=8'hb9;//C.
8'h2d: codelist=8'hde;//d.
8'h2e: codelist=8'hf9;//E.
8'h2f: codelist=8'hf1;//F.
default: codelist=8'h00;//全灭
endcase
if(j==600)
j = 0;
else if(((codeno&8'h40)!=8'h00)&&(j<=300))
codelist=8'h00;//闪烁控制
end
endfunction
endmodule
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -