完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
本人菜鸟,写了一个FPGA的时钟,但是不知道为什么秒上从0变为1 又变为0.。。。分跟时就根本没变化。。。不知道为什么啊。。。求指教
//分频子模块 module fenpin (clk,rst_n,en_1s,en_1ms); //产生1s,1ms的分频 input clk; input rst_n; output en_1s; output en_1ms; reg[31:0] jishu_1s; reg[15:0] jishu_1ms; parameter cnt_1s =49999999; parameter cnt_1ms =49999; always@(posedge clk or negedge rst_n) begin if(!rst_n) jishu_1s<=32'b0; else if(jishu_1s else jishu_1s<=32'b0; end always@(posedge clk or negedge rst_n) begin if(!rst_n) jishu_1ms<=16'b0; else if(jishu_1ms else jishu_1ms<=16'b0; end assign en_1s=(jishu_1s==cnt_1s)? 1'b1 : 1'b0; //1s assign en_1ms=(jishu_1ms==cnt_1ms)? 1'b1 : 1'b0; //1ms endmodule //时、分、秒 module shijian(clk,rst_n,en_1s,shi,fen,miao); input clk; input rst_n; input en_1s; output[5:0] shi; output[5:0] fen; output[5:0] miao; reg [5:0] shi; reg [5:0] fen; reg [5:0] miao; always@(posedge clk or negedge rst_n) begin if(!rst_n) begin shi<=6'b0; fen<=6'b0; miao<=6'b0; end else if(en_1s) begin //if(miao<60) miao<=miao+1'b1; if(miao==60) begin miao<=0; //if(fen<60) fen<=fen+1'b1; if(fen==60) begin fen<=0; //if(shi<24) shi<=shi+1'b1; if(shi==24) shi<=0; end end end else begin shi<=shi; fen<=fen; miao<=miao; end end endmodule //显示部分 module xianshi(clk,rst_n,en_1ms,shi,fen,miao,led_bit,dataout); input clk; input rst_n; input en_1ms; input shi; input fen; input miao; output[7:0] led_bit; //位选 output[7:0] dataout; //段选 //数码管显示 0~9 对应段选输出 parameter num0 = 8'b11000000, num1 = 8'b11111001, num2 = 8'b10100100, num3 = 8'b10110000, num4 = 8'b10011001, num5 = 8'b10010010, num6 = 8'b10000010, num7 = 8'b11111000, num8 = 8'b10000000, num9 = 8'b10010000; reg[3:0] shi1,shi2,fen1,fen2,miao1,miao2; reg[7:0] led_bit; //位选 reg[7:0] dataout; //段选 reg[2:0] state; //状态寄存器 always@(posedge clk or negedge rst_n) if(!rst_n) begin led_bit<=8'b1; state<=3'b0; end else if(en_1ms) begin state<=state+1'b1; shi1=shi/10; shi2=shi%10; fen1=fen/10; fen2=fen%10; miao1=miao/10; miao2=miao%10; if(state==3'b000) begin //state<=3'b001; led_bit=8'b11111110; case(miao2) 0: dataout<=num0; 1: dataout<=num1; 2: dataout<=num2; 3: dataout<=num3; 4: dataout<=num4; 5: dataout<=num5; 6: dataout<=num6; 7: dataout<=num7; 8: dataout<=num8; 9: dataout<=num9; default :dataout<=num0; endcase end else if(state==3'b001) begin //state<=3'b010; led_bit=8'b11111101; case(miao1) 0: dataout<=num0; 1: dataout<=num1; 2: dataout<=num2; 3: dataout<=num3; 4: dataout<=num4; 5: dataout<=num5; // 6: dataout<=num6; // 7: dataout<=num7; // 8: dataout<=num8; // 9: dataout<=num9; default :dataout<=num0; endcase end else if(state==3'b010) begin //state<=3'b011; led_bit=8'b11110111; case(fen2) 0: dataout<=num0; 1: dataout<=num1; 2: dataout<=num2; 3: dataout<=num3; 4: dataout<=num4; 5: dataout<=num5; 6: dataout<=num6; 7: dataout<=num7; 8: dataout<=num8; 9: dataout<=num9; default :dataout<=num0; endcase end else if(state==3'b011) begin //state<=3'b100; led_bit=8'b11101111; case(fen1) 0: dataout<=num0; 1: dataout<=num1; 2: dataout<=num2; 3: dataout<=num3; 4: dataout<=num4; 5: dataout<=num5; // 6: dataout<=num6; // 7: dataout<=num7; // 8: dataout<=num8; // 9: dataout<=num9; endcase end else if(state==3'b100) begin //state<=3'b101; led_bit=8'b10111111; case(shi2) 0: dataout<=num0; 1: dataout<=num1; 2: dataout<=num2; 3: dataout<=num3; 4: dataout<=num4; // 5: dataout<=num5; // 6: dataout<=num6; // 7: dataout<=num7; // 8: dataout<=num8; // 9: dataout<=num9; default :dataout<=num0; endcase end else if(state==3'b101) begin //state<=3'b110; led_bit=8'b01111111; case(shi1) 0: dataout<=num0; 1: dataout<=num1; 2: dataout<=num2; 3: dataout<=num3; // 4: dataout<=num4; // 5: dataout<=num5; // 6: dataout<=num6; // 7: dataout<=num7; // 8: dataout<=num8; // 9: dataout<=num9; endcase end else if(state==3'b110) begin //state<=3'b000; led_bit=8'b11011011; dataout<=8'b10111111; end end else begin dataout<=dataout; led_bit<=led_bit; end endmodule //顶层模块 module Shizhong(clk,rst_n,led_bit,dataout); input clk; input rst_n; output[7:0] led_bit; output[7:0] dataout; wire en_1s; wire en_1ms; fenpin fenpin_int(.clk(clk), .rst_n(rst_n), .en_1s(en_1s), .en_1ms(en_1ms) ); wire shi,fen,miao; shijian shijian_int(.clk(clk), .rst_n(rst_n), .en_1s(en_1s), .shi(shi), .fen(fen), .miao(miao) ); xianshi xianshi_int(.clk(clk), .rst_n(rst_n), .en_1ms(en_1ms), .shi(shi), .fen(fen), .miao(miao), .led_bit(led_bit), .dataout(dataout) ); endmodule |
|
相关推荐
6个回答
|
|
|
|
哪位大侠救救我啊。。。。。。啊。。。。。 。嗄。
|
|
|
|
程序太长了,自己命出来一块一块的测试,
|
|
|
|
这个最好一块块的测试,这题看起来太麻烦
|
|
|
|
应该规范代码
|
|
|
|
你的代码看起来头大啊 同意楼上的 一块一块测试
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1333 浏览 1 评论
助力AIoT应用:在米尔FPGA开发板上实现Tiny YOLO V4
1041 浏览 0 评论
2408 浏览 1 评论
2113 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
2376 浏览 0 评论
1878 浏览 49 评论
6017 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 03:01 , Processed in 0.583910 second(s), Total 51, Slave 44 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号