【国产FPGA高云GW1N-4系列开发板测评】动态数码管之时间显示
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">一、目标</font></span></span></span></span></p><p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">1</font><font face="宋体">、显示时钟;数码管显示分钟和秒;使用开发板上</font><font face="Calibri">LED</font><font face="宋体">显示小时和分钟的十分位</font></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">二、实现方法</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">1</font><font face="宋体">、基于秒表工程的分频以及</font><font face="Calibri">LED</font><font face="宋体">的驱动;注意LED是低电平点亮。</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">2</font><font face="宋体">、基于数码管动态扫描的方式进行数码管驱动。</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">3</font><font face="宋体">、开发板上左边一排</font><font face="Calibri">LED</font><font face="宋体">,对应的管脚号</font><font face="Calibri">114,116,118,120,122,124,128,130</font><font face="宋体">,对应</font><font face="Calibri">8</font><font face="宋体">位</font><font face="Calibri">bit-0-7;</font><font face="宋体">右边一排</font><font face="Calibri">LED</font><font face="宋体">对应的管脚为:</font><font face="Calibri">113,115,117,119,121,123,126,129.</font><font face="宋体">对应</font><font face="Calibri">8</font><font face="宋体">位</font><font face="Calibri">bit-0-7;</font><font face="宋体">并且都是使用</font><font face="Calibri">8421BCD</font><font face="宋体">码表示十进制的小时和分钟。</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"></p>
<p style="text-indent:21.0000pt; text-align:justify"> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">三、代码</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">主要看代码:</font></span></span></span></span></p>
<p style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">1、主要显示部分</font></span></span></span></span></p>
<pre>
<code>/*
数码管时钟显示实验
4个数码管
*/
`define UD #1//延时1个时间单位
module watch(
inputsys_clk,//系统时钟
inputsys_rst_n,
output dig,//位选
output regsmg,//数码管段码
output regHour_led,//用于显示小时的led控制管脚
output regMinute_led//用于显示分钟的led控制管脚
);
wire clk_1hz;//变量
wire clk_1ms;
div_clk u_div_clk
(
.sys_clk(sys_clk),
.clk_1hz(clk_1hz),
.clk_1ms(clk_1ms)
);
reg second_counter_ge = 5;//秒个位计时
reg second_counter_shi = 3;//秒十位计时
reg minute_counter = 6;//分计时个位
reg minute_counter_shi = 5;//分计时十位
reg hour_counter = 8;
reg num = 0;//要显示的数字
always @(posedge clk_1hz)
begin
if(second_counter_ge == 4'd9) //秒个位加到9进位(使用除法,比较耗费资源)
begin
second_counter_ge <= `UD 4'd0;
second_counter_shi <= `UD second_counter_shi + 1'b1;
if(second_counter_shi == 4'd5) //秒十位加到5,并且个位到9,分钟加1
begin
second_counter_shi <= `UD 4'd0;
minute_counter <= `UD minute_counter + 1'b1;
if(minute_counter == 4'd9)
begin
// second_counter_shi <= 0;
minute_counter <= 0;
//second_counter_ge<= 0;
minute_counter_shi <= `UD minute_counter_shi + 1'b1;
if(minute_counter_shi == 4'd5)
begin
hour_counter <= `UD hour_counter + 1'b1;
minute_counter_shi <= 0;
if(hour_counter == 4'd11)
hour_counter <= 0;
end
end
end
end
else
second_counter_ge <= `UD second_counter_ge + 1'b1;
end
parameter smg_one = 4'b1110;
parameter smg_two = 4'b1101;
parameter smg_three = 4'b1011;
parameter smg_four= 4'b0111;
reg sel ;
reg disp_sel;
//使用状态机进行数码管扫描
always @(posedge clk_1ms or negedge sys_rst_n)
begin
if(!sys_rst_n)
begin
sel <= smg_one;
disp_sel = 4'b1110;
end
else
begin
case(sel)
smg_one:
begin
disp_sel <= 4'b1110;sel <= smg_two;num <= second_counter_ge;
end
smg_two:
begin
disp_sel <= 4'b1101;sel <= smg_three;num <= second_counter_shi;
end
smg_three:
begin
disp_sel <= 4'b1011;sel <= smg_four;num <= 4'd10;
end
smg_four:
begin
disp_sel <= 4'b0111;sel <= smg_one;num <= minute_counter;
end
default :sel <= smg_one;
endcase
end
end
//共阳极
assign dig = disp_sel; //显示一位
//0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80,0x90
//显示部分 共阳极,为0有效
always @(*)
begin
case(num)
4'd0:smg = 8'hc0;//数字0
4'd1:smg = 8'hf9;//数字1
4'd2:smg = 8'ha4;//数字2
4'd3:smg = 8'hb0;//数字3
4'd4:smg = 8'h99;//数字4
4'd5:smg = 8'h92;//数字5
4'd6:smg = 8'h82;//数字6
4'd7:smg = 8'hf8;//数字7
4'd8:smg = 8'h80;//数字8
4'd9:smg = 8'h90;//数字9
4'd10:smg = 8'hBF;//符号-
default:smg = 8'hc0;//数字0
endcase
end
//用于分钟LED显示
always @(*)
begin
case(minute_counter_shi)
4'd0:Minute_led = 8'hFF;//数字0
4'd1:Minute_led = 8'hFE;//数字1
4'd2:Minute_led = 8'hFD;//数字2
4'd3:Minute_led = 8'hFC;//数字3
4'd4:Minute_led = 8'hFB;//数字4
4'd5:Minute_led= 8'hFA;//数字5
default:Minute_led = 8'hFF;//数字0
endcase
end
//用于小时LED显示
always @(*)
begin
case(hour_counter)
4'd0:Hour_led = 8'hFF;//数字0
4'd1:Hour_led = 8'hFE;//数字1
4'd2:Hour_led = 8'hFD;//数字2
4'd3:Hour_led = 8'hFC;//数字3
4'd4:Hour_led = 8'hFB;//数字4
4'd5:Hour_led = 8'hFA;//数字5
4'd6:Hour_led = 8'hF9;//数字6
4'd7:Hour_led = 8'hF8;//数字7
4'd8:Hour_led = 8'hF7;//数字8
4'd9:Hour_led = 8'hF6;//数字9
4'd10:Hour_led = 8'hF5;//符号-
4'd11:Hour_led = 8'hF4;//符号-
default:Hour_led = 8'hFF;//数字0
endcase
end
endmodule
</code></pre>
<p style="text-align:justify"> </p>
<p style="text-align:justify">2、时钟分频部分</p>
<pre>
<code>`define UD #1//在引用已定义的宏名时,必须在宏名的前面加上符号“`”,表示该名字是一个经过宏定义的名字.
//宏定义不是Verilog HDL语句,不必在行末加分号。如果加了分号会连分号一起进行置换
//宏名和宏内容必须在同一行中进行声明。如果在宏内容中包含有注释行,注释行不会作为被置换的内容
module div_clk(
inputsys_clk,//系统时钟 50Mhz
output clk_1hz,//1Hz时钟
output clk_1ms//1ms时钟
);
reg time_cnt = 0;//用于保存分频计数值
reg ms_cnt = 0; //用于保存分频计数值
reg flag = 0;//用于产生正负信号标志
reg ms_flag = 0;//用于产生正负信号标志
always @(posedge sys_clk)
begin
if(time_cnt == 26'h2faf080-1'b1)
time_cnt <= `UD 26'd0;
else
time_cnt <= `UD time_cnt + 1'b1;
end
always @(posedge sys_clk)
begin
if(ms_cnt == 16'hc350-1'b1)
ms_cnt <= `UD 16'd0;
else
ms_cnt <= `UD ms_cnt + 1'b1;
end
//分频,产生1Hz时钟
always @(posedge sys_clk)
begin
if(time_cnt == 26'h2faf080/2-1'b1)
flag <= `UD 1'b1;
else if(time_cnt == 26'h2faf080-1'b1)
flag <= `UD 1'b0;
end
//分频,产生1000Hz时钟
always @(posedge sys_clk)
begin
if(ms_cnt == 16'hc350/2-1'b1)
ms_flag <= `UD 1'b1;
else if(ms_cnt == 16'hc350-1'b1)
ms_flag <= `UD 1'b0;
end
assign clk_1ms = ms_flag;
assign clk_1hz = flag;
endmodule</code></pre>
<p style="text-align:justify">四、实验现象</p>
<p style="text-align:justify">数码管显示6分-秒</p>
<p style="text-align:justify">左边LED显示 8、右边显示5。和程序中设定的初始值一样。</p>
<p style="text-align:justify"></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"> </p>
<p>感谢分享。</p>
<p></p>
littleshrimp 发表于 2021-12-17 16:24
感谢分享。
<p>期待你下一篇精彩的测评</p>
怀揣少年梦 发表于 2021-12-17 18:08
期待你下一篇精彩的测评
<p>正在弄,我是FPGA新手,写程序速度有些慢。</p>
littleshrimp 发表于 2021-12-17 19:39
正在弄,我是FPGA新手,写程序速度有些慢。
<p>我也是小白一枚<img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/handshake.gif" width="48" /></p>
<p>感谢分享1</p>
页:
[1]