完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
小弟刚学FPGA用的是EP4CE6 现在想写一个60进制的计数器 然后在数码管上显示出来 用verilog写 但想了好几天没想出来 去大侠指导下 或给个程序看看 小弟感激不尽。。。。。拜托了
|
|
相关推荐
20个回答
|
|
好吧 自己的事自己解决 我参照别人的程序已经弄好了 贴程序 附加一句 永远别指望别人 能靠的住的只有自己
|
|
|
|
顶层模块 产生0~59数字 并例化下面的exp07_top模块
module exp07_demo ( CLK, RSTn, Row_Scan_Sig, Column_Scan_Sig ); input CLK; input RSTn; output [7:0]Row_Scan_Sig; output [1:0]Column_Scan_Sig; /************************************/ parameter T1S = 26'd49_999_999; /************************************/ reg [26:0]Count1; always @ ( posedge CLK or negedge RSTn ) if( !RSTn ) Count1 <= 26'd0; else if( Count1 == T1S ) Count1 <= 26'd0; else Count1 <= Count1 + 1'b1; /***************************************/ reg [7:0]Counter_Sec; always @ ( posedge CLK or negedge RSTn ) if( !RSTn ) begin Counter_Sec <= 8'd0; end else if( Count1 == T1S ) begin if( Counter_Sec < 8'd59 ) Counter_Sec <= Counter_Sec + 1'b1; else Counter_Sec <= 8'd0; end /****************************************/ exp07_top U1 ( .CLK( CLK ), .RSTn( RSTn ), .Number_Data( Counter_Sec ), .Row_Scan_Sig( Row_Scan_Sig ), .Column_Scan_Sig( Column_Scan_Sig ) ); /******************************************/ endmodule |
|
|
|
第二顶层模块 例化下面的模块
module exp07_top ( CLK, RSTn, Number_Data, Row_Scan_Sig, Column_Scan_Sig ); input CLK; input RSTn; input [7:0]Number_Data; output [7:0]Row_Scan_Sig; output [1:0]Column_Scan_Sig; /**************************************/ wire [3:0]Ten_Data; wire [3:0]One_Data; number_mod_module U1 ( .CLK( CLK ), .RSTn( RSTn ), .Number_Data( Number_Data ), // input - form top .Ten_Data( Ten_Data ), // output - to U2 .One_Data( One_Data ) // output - to u2\U2 ); /****************************************/ wire [7:0]Ten_SMG_Data; wire [7:0]One_SMG_Data; smg_encoder_module U2 ( .CLK( CLK ), .RSTn( RSTn ), .Ten_Data( Ten_Data ), // input - from U1 .One_Data( One_Data ), // input - from U1 .Ten_SMG_Data( Ten_SMG_Data ), // output - to U3 .One_SMG_Data( One_SMG_Data ) // output - to U3 ); /*****************************************/ smg_scan_module U3 ( .CLK( CLK ), .RSTn( RSTn ), .Ten_SMG_Data( Ten_SMG_Data ), // input - from U2 .One_SMG_Data( One_SMG_Data ), // input - from U2 .Row_Scan_Sig( Row_Scan_Sig ), // output - to top .Column_Scan_Sig( Column_Scan_Sig ) // output - to top ); /******************************************/ endmodule |
|
|
|
十位取位模块
module exp07_top ( CLK, RSTn, Number_Data, Row_Scan_Sig, Column_Scan_Sig ); input CLK; input RSTn; input [7:0]Number_Data; output [7:0]Row_Scan_Sig; output [1:0]Column_Scan_Sig; /**************************************/ wire [3:0]Ten_Data; wire [3:0]One_Data; number_mod_module U1 ( .CLK( CLK ), .RSTn( RSTn ), .Number_Data( Number_Data ), // input - form top .Ten_Data( Ten_Data ), // output - to U2 .One_Data( One_Data ) // output - to u2\U2 ); /****************************************/ wire [7:0]Ten_SMG_Data; wire [7:0]One_SMG_Data; smg_encoder_module U2 ( .CLK( CLK ), .RSTn( RSTn ), .Ten_Data( Ten_Data ), // input - from U1 .One_Data( One_Data ), // input - from U1 .Ten_SMG_Data( Ten_SMG_Data ), // output - to U3 .One_SMG_Data( One_SMG_Data ) // output - to U3 ); /*****************************************/ smg_scan_module U3 ( .CLK( CLK ), .RSTn( RSTn ), .Ten_SMG_Data( Ten_SMG_Data ), // input - from U2 .One_SMG_Data( One_SMG_Data ), // input - from U2 .Row_Scan_Sig( Row_Scan_Sig ), // output - to top .Column_Scan_Sig( Column_Scan_Sig ) // output - to top ); /******************************************/ endmodule |
|
|
|
上面的错了 这个是十位取位模块
module number_mod_module ( CLK, RSTn, Number_Data, Ten_Data, One_Data ); input CLK; input RSTn; input [7:0]Number_Data; output [3:0]Ten_Data; output [3:0]One_Data; /*********************************/ reg [31:0]rTen; reg [31:0]rOne; always @ ( posedge CLK or negedge RSTn ) if( !RSTn ) begin rTen <= 32'd0; rOne <= 32'd0; end else begin rTen <= Number_Data / 10; rOne <= Number_Data % 10; end /***********************************/ assign Ten_Data = rTen[3:0]; assign One_Data = rOne[3:0]; /***********************************/ endmodule |
|
|
|
数码管加码模块
module smg_encoder_module ( CLK, RSTn, Ten_Data, One_Data, Ten_SMG_Data, One_SMG_Data ); input CLK; input RSTn; input [3:0]Ten_Data; input [3:0]One_Data; output [7:0]Ten_SMG_Data; output [7:0]One_SMG_Data; /***************************************/ parameter _0 = 8'b1100_0000, _1 = 8'b1111_1001, _2 = 8'b1010_0100, _3 = 8'b1011_0000, _4 = 8'b1001_1001, _5 = 8'b1001_0010, _6 = 8'b1000_0010, _7 = 8'b1111_1000, _8 = 8'b1000_0000, _9 = 8'b1001_0000; /***************************************/ reg [7:0]rTen_SMG_Data; always @ ( posedge CLK or negedge RSTn ) if( !RSTn ) begin rTen_SMG_Data <= 8'b1111_1111; end else case( Ten_Data ) 4'd0 : rTen_SMG_Data <= _0; 4'd1 : rTen_SMG_Data <= _1; 4'd2 : rTen_SMG_Data <= _2; 4'd3 : rTen_SMG_Data <= _3; 4'd4 : rTen_SMG_Data <= _4; 4'd5 : rTen_SMG_Data <= _5; 4'd6 : rTen_SMG_Data <= _6; 4'd7 : rTen_SMG_Data <= _7; 4'd8 : rTen_SMG_Data <= _8; 4'd9 : rTen_SMG_Data <= _9; endcase /***************************************/ reg [7:0]rOne_SMG_Data; always @ ( posedge CLK or negedge RSTn ) if( !RSTn ) begin rOne_SMG_Data <= 8'b1111_1111; end else case( One_Data ) 4'd0 : rOne_SMG_Data <= _0; 4'd1 : rOne_SMG_Data <= _1; 4'd2 : rOne_SMG_Data <= _2; 4'd3 : rOne_SMG_Data <= _3; 4'd4 : rOne_SMG_Data <= _4; 4'd5 : rOne_SMG_Data <= _5; 4'd6 : rOne_SMG_Data <= _6; 4'd7 : rOne_SMG_Data <= _7; 4'd8 : rOne_SMG_Data <= _8; 4'd9 : rOne_SMG_Data <= _9; endcase /***************************************/ assign Ten_SMG_Data = rTen_SMG_Data; assign One_SMG_Data = rOne_SMG_Data; /***************************************/ endmodule |
|
|
|
数码挂扫描顶层模块
module smg_scan_module ( CLK, RSTn, Ten_SMG_Data, One_SMG_Data, Row_Scan_Sig, Column_Scan_Sig ); input CLK; input RSTn; input [7:0]Ten_SMG_Data; input [7:0]One_SMG_Data; output [7:0]Row_Scan_Sig; output [1:0]Column_Scan_Sig; /*****************************/ row_scan_module U1 ( .CLK( CLK ), .RSTn( RSTn ), .Ten_SMG_Data( Ten_SMG_Data ), // input - from top .One_SMG_Data( One_SMG_Data ), // input - from top .Row_Scan_Sig( Row_Scan_Sig ) // output - to top ); column_scan_module U2 ( .CLK( CLK ), .RSTn( RSTn ), .Column_Scan_Sig( Column_Scan_Sig ) // output - to top ); /********************************/ endmodule |
|
|
|
列扫描模块
module column_scan_module ( CLK, RSTn, Column_Scan_Sig ); input CLK; input RSTn; output [1:0]Column_Scan_Sig; /*****************************/ parameter T10MS = 18'd199_999; /*****************************/ reg [17:0]Count1; always @ ( posedge CLK or negedge RSTn ) if( !RSTn ) Count1 <= 18'd0; else if( Count1 == T10MS ) Count1 <= 18'd0; else Count1 <= Count1 + 18'b1; /*******************************/ reg [1:0]t; always @ ( posedge CLK or negedge RSTn ) if( !RSTn ) t <= 2'd0; else if( t == 2'd2 ) t <= 2'd0; else if( Count1 == T10MS ) t <= t + 1'b1; /*********************************/ reg [1:0]rColumn_Scan; always @ ( posedge CLK or negedge RSTn ) if( !RSTn ) rColumn_Scan <= 2'b10; else if( Count1 == T10MS ) case( t ) 2'd0 : rColumn_Scan <= 2'b10; 2'd1 : rColumn_Scan <= 2'b01; endcase /******************************/ assign Column_Scan_Sig = rColumn_Scan; /******************************/ endmodule |
|
|
|
行扫描模块
module row_scan_module ( CLK, RSTn, Ten_SMG_Data, One_SMG_Data, Row_Scan_Sig ); input CLK; input RSTn; input [7:0]Ten_SMG_Data; input [7:0]One_SMG_Data; output [7:0]Row_Scan_Sig; /*******************************/ parameter T10MS = 18'd199_999; /*******************************/ reg [17:0]Count1; always @ ( posedge CLK or negedge RSTn ) if( !RSTn ) Count1 <= 18'd0; else if( Count1 == T10MS ) Count1 <= 18'd0; else Count1 <= Count1 + 18'b1; /*******************************/ reg [1:0]t; always @ ( posedge CLK or negedge RSTn ) if( !RSTn ) t <= 2'd0; else if( t == 2'd2 ) t <= 2'd0; else if( Count1 == T10MS ) t <= t + 1'b1; /**********************************/ reg [7:0]rData; always @ ( posedge CLK or negedge RSTn ) if( !RSTn ) rData <= 8'd0; else if( Count1 == T10MS ) case( t ) 2'd0 : rData <= Ten_SMG_Data; 2'd1 : rData <= One_SMG_Data; endcase /***********************************/ assign Row_Scan_Sig = rData; /***********************************/ endmodule |
|
|
|
完了 大家多多支持
|
|
|
|
楼主你真是太伟大了,你真应该送佛送到西,顺便解释一下
|
|
|
|
我是一个菜鸟,请多指教
|
|
|
|
module scan_led (sys_clk ,
sys_rstn , sm_seg , sm_bit ); input sys_clk ; input sys_rstn ; output [7:0] sm_seg ; output [7:0] sm_bit ; reg [7:0] sm_seg ; reg [7:0] sm_bit ; reg [4:0] dataout_buf ; reg [3:0] shi ; reg [3:0] ge ; reg [5:0] count ; reg [1:0] disp_dat ; reg [15:0] delay_cnt ; reg [25:0] delay_cnt_1hz ; always@(posedge sys_clk or negedge sys_rstn) begin if(!sys_rstn) delay_cnt<=16'd0; else if(delay_cnt==16'd49999) delay_cnt<=16'd0; else delay_cnt<=delay_cnt+1'b1; end always@(posedge sys_clk or negedge sys_rstn) begin if(!sys_rstn) delay_cnt_1hz<=26'd0; else if(delay_cnt_1hz==26'd49999999) delay_cnt_1hz<=26'd0; else delay_cnt_1hz<=delay_cnt_1hz+1'b1; end always@(posedge sys_clk or negedge sys_rstn) begin if(!sys_rstn) disp_dat<=4'd0; else if(delay_cnt==16'd49999) disp_dat<=disp_dat+1'b1; else disp_dat<=disp_dat; end always@(posedge sys_clk or negedge sys_rstn) begin if(!sys_rstn) count<=6'd0; else if(delay_cnt_1hz==26'd49999999) count<=count+1'b1; else if(count==60) count<=6'd0; else count<=count; end always@(posedge sys_clk or negedge sys_rstn) begin if(!sys_rstn) shi<=4'd0; else shi<=count/10; end always@(posedge sys_clk or negedge sys_rstn) begin if(!sys_rstn) ge<=4'd0; else ge<=count%10; end always @(disp_dat) begin case(disp_dat) 2'b00 : sm_bit = 8'b1111_1110; 2'b01 : sm_bit = 8'b1111_1101; /* 2'b10 : sm_bit = 8'b1111_1110; 2'b11 : sm_bit = 8'b1111_1101;*/ default : sm_bit = 8'b1111_1110; endcase end always@(sm_bit) begin case(sm_bit) 8'b1111_1110: dataout_buf<=ge; 8'b1111_1101: dataout_buf<=shi; /*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=0; endcase end always@(dataout_buf) begin case(dataout_buf) 4'h0 : sm_seg = 8'hc0; // "0" 4'h1 : sm_seg = 8'hf9; // "1" 4'h2 : sm_seg = 8'ha4; // "2" 4'h3 : sm_seg = 8'hb0; // "3" 4'h4 : sm_seg = 8'h99; // "4" 4'h5 : sm_seg = 8'h92; // "5" 4'h6 : sm_seg = 8'h82; // "6" 4'h7 : sm_seg = 8'hf8; // "7" 4'h8 : sm_seg = 8'h80; // "8" 4'h9 : sm_seg = 8'h90; // "9" 4'ha : sm_seg = 8'h88; // "a" 4'hb : sm_seg = 8'h83; // "b" 4'hc : sm_seg = 8'hc6; // "c" 4'hd : sm_seg = 8'ha1; // "d" 4'he : sm_seg = 8'h86; // "e" 4'hf : sm_seg = 8'h8e; // "f" default : sm_seg = 8'hc0; // "0" endcase end endmodule |
|
|
|
好麻烦,六个十进制计数器就ok了
|
|
|
|
写点注释给看看呗
|
|
|
|
楼主 你好,我看了你的 十位和各位取模,直接用的 /和% ,这样不是说不能综合吗?
|
|
|
|
可以综合,包括( initial; $readmemb; $readmemh; $signed * / %) 等语句,在一定的用法下都可以综合。 综合工具一直在更新,语法并不是一成不变的。 |
|
|
|
本帖最后由 xqandwn 于 2015-10-18 22:26 编辑
用systemverilog写的,相比于Verilog就多了个logic 变量,其它与Verilog一致。 顶层模块: `timescale 1ns/1ps //模块说明:7段数码管显示,一共有8个数码管 //共阳模式,低电平点亮,数码管采用3-8 译码器——74HC138芯片, module cnt_60 ( input logic CLK , //输入时钟,频率: input logic RST_n , //复位端口,低电平复位 output logic [3:0] DSEL , //7段数码管【8--1】对应选择 output logic DEN , //数码管使能,高电平有效 output logic [7:0] led7_out //数据输出,最低位为小数点 ); logic [26:0] num; //待显示的数字 logic [2:0] dot; //待显示数字的小数点位置 always@(posedge CLK,negedge RST_n) begin if(!RST_n) num <= 27'd0; else num = (num != 59)? (num + 27'd1) : num; end LED_7 U_LED_7 ( .CLK (CLK ), //输入时钟 .RST_n (RST_n ), //复位端口,低电平复位 .data_num (num ), //待显示的数据 .data_dot (dot ), //输入数据小数点位置 .DSEL (DSEL ), //7段数码管【8--1】对应选择 .DEN (DEN ), //数码管使能,高电平有效 .led7_out (led7_out ) //数据输出,最低位为小数点 ); endmodule |
|
|
|
本帖最后由 xqandwn 于 2015-10-18 22:23 编辑
汗!!回帖后代码格式变乱了…… 下面是底层模块,显示电路自动忽略高位多余的0,自动添加小数点后的0: module LED_7 ( input logic CLK , //输入时钟,频率: input logic RST_n , //复位端口,低电平复位 input logic [26:0] data_num , //待显示的数据 input logic [2:0] data_dot , //输入数据小数点位置 output logic [3:0] DSEL , //7段数码管【8--1】对应选择 output logic DEN , //数码管使能,高电平有效 output logic [7:0] led7_out //数据输出,最低位为小数点 ); parameter led0 = 0, led1 = 1, led2 = 2, led3 = 3, led4 = 4, led5 = 5, led6 = 6, led7 = 7; logic DEN_reg ; logic [2:0] DSEL_cnt ; logic [2:0] DSEL_cnt_reg ; logic [7:0] led7_out_reg ; logic [2:0] data_dot_reg ; logic [26:0] data_num_reg ; always@(posedge CLK,negedge Rst_n) begin if(!RST_n) begin DSEL_cnt <= 3'b000; led7_out_reg <= 8'hFF; end else begin data_dot_reg <= data_dot; data_num_reg <= data_num; DSEL_cnt <= DSEL_cnt + 3'd1; DSEL_cnt_reg <= DSEL_cnt; //case(DSEL_cnt)相对DSEL_cnt会有一周期延时 case(DSEL_cnt) led0: begin led7_decoder((data_num_reg)%10,led7_out_reg[7:1]); led7_out_reg[0] <= (data_dot_reg != 0); DEN_reg <= 1; end led1: begin led7_decoder((data_num_reg/10)%10,led7_out_reg[7:1]); led7_out_reg[0] <= (data_dot_reg != 1); DEN_reg <= (data_num_reg >= 10)||(data_dot_reg >= 1); end led2: begin led7_decoder((data_num_reg/100)%10,led7_out_reg[7:1]); led7_out_reg[0] <= (data_dot_reg != 2); DEN_reg <= (data_num_reg >= 100)||(data_dot_reg >= 2); end led3: begin led7_decoder((data_num_reg/1000)%10,led7_out_reg[7:1]); led7_out_reg[0] <= (data_dot_reg != 3); DEN_reg <= (data_num_reg >= 1000)||(data_dot_reg >= 3); end led4: begin led7_decoder((data_num_reg/10000)%10,led7_out_reg[7:1]); led7_out_reg[0] <= (data_dot_reg != 4); DEN_reg <= (data_num_reg >= 10000)||(data_dot_reg >= 4); end led5: begin led7_decoder((data_num_reg/100000)%10,led7_out_reg[7:1]); led7_out_reg[0] <= (data_dot_reg != 5); DEN_reg <= (data_num_reg >= 100000)||(data_dot_reg >= 5); end led6: begin led7_decoder((data_num_reg/1000000)%10,led7_out_reg[7:1]); led7_out_reg[0] <= (data_dot_reg != 6); DEN_reg <= (data_num_reg >= 1000000)||(data_dot_reg >= 6); end led7: begin led7_decoder((data_num_reg/10000000)%10,led7_out_reg[7:1]); led7_out_reg[0] <= (data_dot_reg != 7); DEN_reg <= (data_num_reg >= 10000000)||(data_dot_reg >= 7); end endcase end end assign DSEL = DSEL_cnt_reg; assign DEN = DEN_reg; assign led7_out = led7_out_reg; task led7_decoder //7段数码管 译码电路 ( input logic [3:0] data, output logic [6:0] data_decoder ); case(data) 0: data_decoder = 7'b1000000; 1: data_decoder = 7'b1111001; 2: data_decoder = 7'b0100100; 3: data_decoder = 7'b0110000; 4: data_decoder = 7'b0011001; 5: data_decoder = 7'b0010010; 6: data_decoder = 7'b0000010; 7: data_decoder = 7'b1111000; 8: data_decoder = 7'b0000000; 9: data_decoder = 7'b0010000; default: data_decoder = 7'b0110110; endcase endtask endmodule |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1526 浏览 1 评论
助力AIoT应用:在米尔FPGA开发板上实现Tiny YOLO V4
1073 浏览 0 评论
2606 浏览 1 评论
2293 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
2563 浏览 0 评论
2030 浏览 55 评论
6038 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-28 22:07 , Processed in 0.861822 second(s), Total 76, Slave 69 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号