此帖出自FPGA/CPLD论坛
最新回复
闲来无事,分析一下你的程序
module dig_show(clk,rst,csm_1,csm_2,db); // 定义总端口input clk; //时钟(50MHz)input rst; //复位output csm_1,csm_2; //数码管的位选output [7:0] db; //数码管的段选parameter //数码管显示数字对应的段选 seg0 = 7'h3f, seg1 = 7'h06, seg2 = 7'h5b, seg3 = 7'h4f, seg4 = 7'h66, seg5 = 7'h6d, seg6 = 7'h7d, seg7 = 7'h07, seg8 = 7'h7f, seg9 = 7'h6f, sega = 7'h77, segb = 7'h7c, segc = 7'h39, segd = 7'h5e, sege = 7'h79, segf = 7'h71;//-------------------------------------------reg [7:0]flag; //要在两个数码管上显示的数(从0-99),以cnt计数,cnt满后flag加一
// 意思是20NSX2(23次方)的时间 加一个1always @ (posedge clk or negedge rst)beginif(!rst) flag<=0;else if(cnt==24'hffffff&&flag<=8'd99) flag<=flag+1'b1;
else if(flag>8'd99)flag<=0;end
wire[3:0] num; //以cnt【23】为标志位,将flag的高四位和低四位分别赋给numassign num=cnt[23]? flag[7:4]:flag[3:0];//------------------------------------------------------------reg[7:0] sm_dbr;always @(posedge clk)case (num) 4'h0: sm_dbr <= seg0; 4'h1: sm_dbr <= seg1; 4'h2: sm_dbr <= seg2; 4'h3: sm_dbr <= seg3; 4'h4: sm_dbr <= seg4; 4'h5: sm_dbr <= seg5; 4'h6: sm_dbr <= seg6; 4'h7: sm_dbr <= seg7; 4'h8: sm_dbr <= seg8; 4'h9: sm_dbr <= seg9; 4'ha: sm_dbr <= sega; 4'hb: sm_dbr <= segb; 4'hc: sm_dbr <= segc; 4'hd: sm_dbr <= segd; 4'he: sm_dbr <= sege; 4'hf: sm_dbr <= segf; default: ; endcaseassign db=sm_dbr; //把段选址赋给数码管的段选 //-----------------------------------------------reg [23:0] cnt; //计数器always @(posedge clk or negedge rst)if(!rst) cnt<=24'd0;else cnt<=cnt+1'b1;
assign csm_1=cnt[23]; //以cnt[23]为标志位,分别打开数码管1、2的位选assign csm_2=~cnt[23];
endmodule
module dig_show(clk,rst,csm_1,csm_2,db);input clk; //时钟(50MHz)input rst; //复位output csm_1,csm_2; //数码管的位选output [7:0] db; //数码管的段选parameter //数码管显示数字对应的段选 seg0 = 7'h3f, seg1 = 7'h06, seg2 = 7'h5b, seg3 = 7'h4f, seg4 = 7'h66, seg5 = 7'h6d, seg6 = 7'h7d, seg7 = 7'h07, seg8 = 7'h7f, seg9 = 7'h6f, sega = 7'h77, segb = 7'h7c, segc = 7'h39, segd = 7'h5e, sege = 7'h79, segf = 7'h71;//-------------------------------------------reg [7:0]flag; //要在两个数码管上显示的数(从0-99),以cnt计数,cnt满后flag加一always @ (posedge clk or negedge rst)beginif(!rst) flag<=0;else if(cnt==24'hffffff&&flag<=8'd99) flag<=flag+1'b1;else if(flag>8'd99)flag<=0;end
wire[3:0] num; //以cnt【23】为标志位,将flag的高四位和低四位分别赋给numassign num=cnt[23]? flag[7:4]:flag[3:0];//------------------------------------------------------------reg[7:0] sm_dbr;always @(posedge clk)case (num) 4'h0: sm_dbr <= seg0; 4'h1: sm_dbr <= seg1; 4'h2: sm_dbr <= seg2; 4'h3: sm_dbr <= seg3; 4'h4: sm_dbr <= seg4; 4'h5: sm_dbr <= seg5; 4'h6: sm_dbr <= seg6; 4'h7: sm_dbr <= seg7; 4'h8: sm_dbr <= seg8; 4'h9: sm_dbr <= seg9; 4'ha: sm_dbr <= sega; 4'hb: sm_dbr <= segb; 4'hc: sm_dbr <= segc; 4'hd: sm_dbr <= segd; 4'he: sm_dbr <= sege; 4'hf: sm_dbr <= segf; default: ; endcaseassign db=sm_dbr; //把段选址赋给数码管的段选 //-----------------------------------------------reg [23:0] cnt; //计数器always @(posedge clk or negedge rst)if(!rst) cnt<=24'd0;else cnt<=cnt+1'b1;
assign csm_1=cnt[23]; //以cnt[23]为标志位,分别打开数码管1、2的位选assign csm_2=~cnt[23];
endmodule
从程序看,你的程序设计上我没有找到啥问题,我估计是不是你的硬件设计上有问题啊,LZ!
EEWORLD FPGA/CPLD 斑竹阅!
详情
回复
发表于 2011-5-24 09:41
| ||
|
||
此帖出自FPGA/CPLD论坛
| ||
|
||
此帖出自FPGA/CPLD论坛
| ||
|
||
| |
个人签名一个为理想不懈前进的人,一个永不言败人!
http://shop57496282.taobao.com/ 欢迎光临网上店铺! |
|
此帖出自FPGA/CPLD论坛
| ||
个人签名一个为理想不懈前进的人,一个永不言败人!
http://shop57496282.taobao.com/ 欢迎光临网上店铺! |
||
EEWorld Datasheet 技术支持