10.18数码管静态显示
数码管以静态方式显示,循环0-f计数,每个循环完成后显示位数循环增加一位,效果演示:
代码:
module seg (rstn,clk,dig,seg);
input rstn,clk;
output[7:0] dig;
output[7:0] seg;
reg[25:0] count;
always @(posedge clk or negedge rstn)
if(~rstn) count<=1'b0;
else if(count==26'd25_000_000)
count<=1'b0;
else
count<=count+1'b1;
reg[3:0] num_d; //number
always @(posedge clk or negedge rstn)
if(~rstn) num_d<=4'h0;
else if(count==26'd25_000_000)
if(num_d==4'hf) num_d<=4'h0;
else num_d<=num_d+4'h1;
reg[2:0] num_s; //seg_sel
always @(posedge clk or negedge rstn)
if(~rstn) num_s<=3'd0;
else if(count==26'd25_000_000 && num_d==4'hf)
if(num_s==3'd7) num_s<=3'd0;
else num_s<=num_s+3'd1;
reg[7:0] seg_r;
always @(posedge clk or negedge rstn)
if(~rstn) seg_r<=8'h0;
else
case(num_d)
4'h0: seg_r<=8'h3f;
4'h1: seg_r<=8'h06;
4'h2: seg_r<=8'h5b;
4'h3: seg_r<=8'h4f;
4'h4: seg_r<=8'h66;
4'h5: seg_r<=8'h6d;
4'h6: seg_r<=8'h7d;
4'h7: seg_r<=8'h07;
4'h8: seg_r<=8'h7f;
4'h9: seg_r<=8'h6f;
4'ha: seg_r<=8'h77;
4'hb: seg_r<=8'h7c;
4'hc: seg_r<=8'h39;
4'hd: seg_r<=8'h5e;
4'he: seg_r<=8'h79;
4'hf: seg_r<=8'h71;
default: seg_r<=8'h0;
endcase
reg[7:0] dig_r;
always @(posedge clk or negedge rstn)
if(~rstn) dig_r<=8'b1111_1111;
else
case(num_s)
3'd0: dig_r<=8'b1111_1110;
3'd1: dig_r<=8'b1111_1100;
3'd2: dig_r<=8'b1111_1000;
3'd3: dig_r<=8'b1111_0000;
3'd4: dig_r<=8'b1110_0000;
3'd5: dig_r<=8'b1100_0000;
3'd6: dig_r<=8'b1000_0000;
3'd7: dig_r<=8'b0000_0000;
default: dig_r<=8'b1111_1111;
endcase
assign dig=dig_r;
assign seg=~seg_r;
endmodule
10.19 数码管动态显示
八段数码段显示不同数字,并且不断加1,效果:
代码:
module seg(clk,rstn,seg,dig);
input clk,rstn;
output[7:0] seg;
output[7:0] dig;
reg[25:0] count;
always @(posedge clk or negedge rstn)
if(~rstn) count<=26'd0;
else if(count==26'd50_000_000)
count<=26'd0;
else count<=count+26'd1;
reg[3:0] seg_num;
always @(posedge clk or negedge rstn)
if(~rstn) seg_num<=4'h0;
else if(count==26'd50_000_000)
if(seg_num==4'hf)
seg_num<=4'h0;
else seg_num<=seg_num+4'h1;
reg[2:0] dig_num;
always @(posedge clk or negedge rstn)
if(~rstn) dig_num<=3'd0;
else if(count%17'd100_000 == 1'd0)
if(dig_num==3'd7)
dig_num<=3'd0;
else dig_num<=dig_num+3'd1;
reg[7:0] dig_f;
always @(dig_num)
case(dig_num)
3'd0: dig_f<=8'b1111_1110;
3'd1: dig_f<=8'b1111_1101;
3'd2: dig_f<=8'b1111_1011;
3'd3: dig_f<=8'b1111_0111;
3'd4: dig_f<=8'b1110_1111;
3'd5: dig_f<=8'b1101_1111;
3'd6: dig_f<=8'b1011_1111;
3'd7: dig_f<=8'b0111_1111;
default: dig_f<=8'b1111_1111;
endcase
reg[3:0] seg_num1;
always @(dig_num)
case(dig_num)
3'd0: seg_num1<=seg_num;
3'd1: seg_num1<=seg_num+4'h1;
3'd2: seg_num1<=seg_num+4'h2;
3'd3: seg_num1<=seg_num+4'h3;
3'd4: seg_num1<=seg_num+4'h4;
3'd5: seg_num1<=seg_num+4'h5;
3'd6: seg_num1<=seg_num+4'h6;
3'd7: seg_num1<=seg_num+4'h7;
default: seg_num1<=seg_num;
endcase
reg[7:0] seg_f;
always @(seg_num1)
case(seg_num1)
4'h0: seg_f<=8'h3f;
4'h1: seg_f<=8'h06;
4'h2: seg_f<=8'h5b;
4'h3: seg_f<=8'h4f;
4'h4: seg_f<=8'h66;
4'h5: seg_f<=8'h6d;
4'h6: seg_f<=8'h7d;
4'h7: seg_f<=8'h07;
4'h8: seg_f<=8'h7f;
4'h9: seg_f<=8'h6f;
4'ha: seg_f<=8'h77;
4'hb: seg_f<=8'h7c;
4'hc: seg_f<=8'h39;
4'hd: seg_f<=8'h5e;
4'he: seg_f<=8'h79;
4'hf: seg_f<=8'h71;
default: seg_f<=8'h0;
endcase
assign seg=~seg_f;
assign dig=dig_f;
endmodule
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图四被打赏50分 | |
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 |