1 | LED闪烁灯——作业 | 2楼 |
2 | LED流水灯——作业 | 3楼 |
3 | LED花样流水灯——作业 | 4楼 |
4 | 数码管静态显示——作业 | 5楼 |
5 | 动态数码管显示——作业 | 6楼 |
6 | 按键(未消抖)——作业 | 8楼 |
7 | 按键(消抖)——作业 | 9楼 |
8 | 蜂鸣器——报警声 | 10楼 |
9 | lcd1602— —作业 | 11楼 |
10 |
jinruichao的进程贴
关键词: jinruichao 进程
动态数码管显示——作业
sof文件:
dt_smg.rar
源代码:
module dt_smg
(
clk,
rstn,
dig,
seg
);
input clk;
input rstn;
output dig;
output seg;
reg[7:0] dig;
reg[7:0] seg;
reg[25:0] cnt;
reg[15:0] cnt1;
reg[3:0] gewei;
reg[3:0] shiwei;
reg[3:0] disp_dat;
reg[7:0] seg_gewei;
reg[7:0] seg_shiwei;
always @ (posedge clk or negedge rstn) //1秒延时
begin
if(!rstn) cnt <= 26'd0;
else if(cnt==26'd49999999) cnt<=26'd0;
else cnt<=cnt+1'd1;
end
always @ (posedge clk or negedge rstn) //个位
begin
if(!rstn) gewei <= 4'd0;
else
begin
if(cnt==26'd49999999)
begin
if (gewei==4'd9) gewei<=4'd0;
else gewei<=gewei+1'd1;
end
else gewei<=gewei;
end
end
always @ (posedge clk or negedge rstn) //十位
begin
if(!rstn) shiwei <= 4'd0;
else
begin
if (cnt==26'd49999999)
begin
if(gewei==4'd9)
begin
if (shiwei==4'd5) shiwei<=4'd0;
else shiwei<=shiwei+1'd1;
end
else shiwei<=shiwei;
end
end
end
always @ (gewei)
begin
case (gewei)
4'b0000: seg_gewei <= 8'hc0; // 0
4'b0001: seg_gewei <= 8'hf9; // 1
4'b0010: seg_gewei <= 8'ha4; // 2
4'b0011: seg_gewei <= 8'hb0; // 3
4'b0100: seg_gewei <= 8'h99; // 4
4'b0101: seg_gewei <= 8'h92; // 5
4'b0110: seg_gewei <= 8'h82; // 6
4'b0111: seg_gewei <= 8'hf8; // 7
4'b1000: seg_gewei <= 8'h80; // 8
4'b1001: seg_gewei <= 8'h98; // 9
default:seg_gewei <= 8'hff;
endcase
end
always @ (shiwei)
begin
case (shiwei)
4'b0000: seg_shiwei <= 8'hc0; // 0
4'b0001: seg_shiwei <= 8'hf9; // 1
4'b0010: seg_shiwei <= 8'ha4; // 2
4'b0011: seg_shiwei <= 8'hb0; // 3
4'b0100: seg_shiwei <= 8'h99; // 4
4'b0101: seg_shiwei <= 8'h92; // 5
default:seg_shiwei <= 8'hff;
endcase
end
always @ (posedge clk or negedge rstn)
begin
if(!rstn) cnt1 <= 16'd0;
else if(cnt1==16'd4999) cnt1<=16'd0;
else cnt1<=cnt1+1'd1;
end
always @ (posedge clk or negedge rstn)
begin
if(!rstn) disp_dat <= 4'd0;
else
begin
if(cnt1==16'd4999) disp_dat<=disp_dat+1'd1;
else disp_dat<=disp_dat;
end
end
always @ (disp_dat)
case (disp_dat)
4'd0: dig <= 8'b11111110;
4'd1: dig <= 8'b11111101;
default:dig <= 8'hff;
endcase
always @ (dig)
case (dig)
8'b11111110: seg <= seg_gewei;
8'b11111101: seg <= seg_shiwei;
default:seg <= 8'hff;
endcase
endmodule
蜂鸣器作业——警报声
源代码:
module beep(clk,rstn,beep);
input clk; //时钟
input rstn; //复位
output beep; //蜂鸣器
reg beep;
reg[22:0] div_cnt;
reg[14:0] dey_cnt;
wire [6:0] dey_temp = (div_cnt[22] ? div_cnt[21:15]:~div_cnt[21:15]);
wire [14:0] dey_end = {2'b01,dey_temp,6'b000000};
always @(posedge clk or negedge rstn)
begin
if(!rstn) div_cnt <= 23'd0;
else div_cnt<=div_cnt+1'd1;
end
always @(posedge clk or negedge rstn)
begin
if(!rstn) dey_cnt<=dey_end;
else if(dey_cnt==15'd0)
begin
beep<=~beep;
dey_cnt<=dey_end;
end
else dey_cnt<=dey_cnt-1'd1;
end
endmodule
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |