hellok FPGA DIY进程贴
//*********************************************************
//文件名称: led.v
//说明: LED闪烁
//版本号: V0.0 2012.10.19
//*********************************************************
module led (led,clk_50M,rst_n);
output[10:0] led;
input clk_50M;
input rst_n;
reg[10:0] mled;
reg[23:0] cnt;
always @(posedge clk_50M, negedge rst_n)
begin
if (!rst_n)
mled <= 11'b01010101010;
else
begin
cnt <= cnt + 1;
if (cnt == 23'd2500000)
mled <= ~mled;
end
end
assign led = mled;
endmodule
//*********************************************************
//文件名称: huayang.v
//说明: 手把手教你学习FPGA—LED篇 实验五?
//版本号: V0.0 2012.10.24
//*********************************************************
module huayang (clk, rst_n, led);
input clk, rst_n;
output [10:0] led;
reg [10:0] mled;
reg [24:0] delay_cnt;
reg [1:0] state;
reg [1:0] shs_cnt;
always @ (posedge clk or negedge rst_n)
begin
if (!rst_n)
delay_cnt <= 25'd0;
else
begin
if (delay_cnt == 25'd24999999)
delay_cnt <= 25'd0;
else
delay_cnt <= delay_cnt + 1'd1;
end
end
always @ (posedge clk or negedge rst_n)
begin
if (!rst_n)
begin
mled <= 11'b111_1111_1110;
state <= 2'd0;
shs_cnt <= 2'd0;
end
else
begin
if (delay_cnt == 25'd24999999)
begin
case (state)
2'd0: //跑马灯
begin
mled <= {mled[9:0], led[10]};
if ( mled == 11'b011_1111_1111)
begin
mled <= 11'b111_1111_1111;
state <= 2'd1;
end
end
2'd1: //流水灯
begin
mled <= mled << 1;
if (mled == 11'b000_0000_0000)
begin
mled <= 11'b111_1111_1111;
state <= 2'd2;
end
end
2'd2: //流水灯从右到左
begin
mled <= mled >> 1;
if (mled == 11'b000_0000_0000)
begin
mled <= 11'b111_1111_1111;
state <= 2'd3;
end
end
2'd3: //闪烁灯
begin
mled <= ~mled;
shs_cnt <= shs_cnt + 1'd1;
if (shs_cnt == 2'd3)
begin
shs_cnt <= 1'd0;
mled <= 11'b111_1111_1110;
state <= 2'd0;
end
end
default:
mled <= 11'b010_1100_1100;
endcase
end
end
end
assign led = mled;
endmodule
//*********************************************************
//文件名称: seg_sta.v
//说明: 手把手教你学习FPGA—数码管篇 实验一 数码管静态显示
// 拨动拨码开关控制数码管显示
//版本号: V0.0 2012.11.20
//*********************************************************
module seg_sta (sys_clk, rst_n, led_seg, led_bit, sw_dip);
input sys_clk, rst_n;
input [7:0] sw_dip;
output [7:0] led_seg;
output [7:0] led_bit;
reg [7:0] sw_buf;
reg [7:0] led_seg;
wire [7:0] led_bit;
//reg [3:0] disp_dat; //显示数据寄存器;
reg [25:0] delay_cnt;
always @ (posedge sys_clk or negedge rst_n)
begin
if (!rst_n)
delay_cnt <= 26'd0;
else
begin
if (delay_cnt == 26'd49999999)
delay_cnt <= 26'd0;
else
delay_cnt <= delay_cnt + 1'b1;
end
end
/*always @ (posedge sys_clk or negedge rst_n)
begin
if (!rst_n)
disp_dat <= 4'd0;
else
begin
if (delay_cnt == 26'd49999999)
disp_dat <= disp_dat + 1'b1;
else
disp_dat <= disp_dat;
end
end*/
always @ (sw_dip)
begin
sw_buf = sw_dip;
case (sw_buf)
8'b11111110: led_seg = 8'hf9;
8'b11111101: led_seg = 8'ha4;
8'b11111011: led_seg = 8'hb0;
8'b11110111: led_seg = 8'h99;
8'b11101111: led_seg = 8'h92;
8'b11011111: led_seg = 8'h82;
8'b10111111: led_seg = 8'hf8;
8'b01111111: led_seg = 8'h80;
default: led_seg = 8'h86;
endcase
end
/*always @ (disp_dat)
begin
case (disp_dat)
4'h0 : led_seg = 8'hc0;
4'h1 : led_seg = 8'hf9;
4'h2 : led_seg = 8'ha4;
4'h3 : led_seg = 8'hb0;
4'h4 : led_seg = 8'h99;
4'h5 : led_seg = 8'h92;
4'h6 : led_seg = 8'h82;
4'h7 : led_seg = 8'hf8;
4'h8 : led_seg = 8'h80;
4'h9 : led_seg = 8'h90;
4'ha : led_seg = 8'h88;
4'hb : led_seg = 8'h83;
4'hc : led_seg = 8'hc6;
4'hd : led_seg = 8'ha1;
4'he : led_seg = 8'h86;
4'hf : led_seg = 8'h8e;
endcase
end*/
assign led_bit = 8'b00000000;
endmodule
//*********************************************************
//文件名称: shansh.v
//说明: 手把手教你学习FPGA—数码管篇 实验二 数码管动态显示
// 数码管动态显示0-7例程,直接在上面更改增加模60计数功能
//版本号: V0.0 2012.11.26
//*********************************************************
module seg_dyn (sys_clk, rst_n, led_seg, led_bit);
input sys_clk;
input rst_n;
output [7:0] led_seg;
output [7:0] led_bit;
reg [7:0] led_seg;
reg [7:0] led_bit;
reg [4:0] dataout_buf;
reg [2:0] disp_dat;
reg [15:0] delay_cnt;
reg [25:0] delay_1s;
reg [5:0] count60;
reg [3:0] count60_ge, count60_shi;
always @ (posedge sys_clk or negedge rst_n)
begin
if (!rst_n)
delay_cnt <= 16'd0;
else
begin
if (delay_cnt == 16'd49999)
delay_cnt <= 16'd0;
else
delay_cnt <= delay_cnt + 1'b1;
end
end
always @ (posedge sys_clk or negedge rst_n)
begin
if (!rst_n)
disp_dat <= 4'd0;
else
begin
if (delay_cnt == 16'd49999)
disp_dat <= disp_dat + 1'b1;
else
disp_dat <= disp_dat;
end
end
always @ (posedge sys_clk or negedge rst_n) //1秒计数
begin
if (!rst_n)
delay_1s <= 26'd0;
else
begin
if (delay_1s == 26'd49999999)
delay_1s <= 26'd0;
else
delay_1s <= delay_1s + 1'b1;
end
end
always @ (posedge sys_clk or negedge rst_n) //模60计数;
begin
if (!rst_n)
count60 <= 6'd0;
else
begin
if (count60 == 6'd60)
count60 <= 0;
else
begin
if (delay_1s == 26'd49999999)
count60 <= count60 + 1'b1;
else
count60 <= count60;
end
end
end
always @ (disp_dat)
begin
case (disp_dat)
3'b000: led_bit = 8'b1111_1110;
3'b001: led_bit = 8'b1111_1101;
3'b010: led_bit = 8'b1111_1011;
3'b011: led_bit = 8'b1111_0111;
3'b100: led_bit = 8'b1110_1111;
3'b101: led_bit = 8'b1101_1111;
3'b110: led_bit = 8'b1011_1111;
3'b111: led_bit = 8'b0111_1111;
default: led_bit = 8'b1111_1110;
endcase
end
always @ (led_bit)
begin
count60_ge <= count60 % 10;
count60_shi <= count60 / 10;
case (led_bit)
8'b1111_1110: dataout_buf = count60_ge;//0; //模60计数的个位;
8'b1111_1101: dataout_buf = count60_shi;//1;
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 = 8;
endcase
end
always @ (dataout_buf)
begin
case (dataout_buf)
4'h0: led_seg = 8'hc0;
4'h1: led_seg = 8'hf9;
4'h2: led_seg = 8'ha4;
4'h3: led_seg = 8'hb0;
4'h4: led_seg = 8'h99;
4'h5: led_seg = 8'h92;
4'h6: led_seg = 8'h82;
4'h7: led_seg = 8'hf8;
4'h8: led_seg = 8'h80;
4'h9: led_seg = 8'h90;
4'ha: led_seg = 8'h88;
4'hb: led_seg = 8'h83;
4'hc: led_seg = 8'hc6;
4'hd: led_seg = 8'ha1;
4'he: led_seg = 8'h86;
4'hf: led_seg = 8'h8e;
default: led_seg = 8'hc0;
endcase
end
endmodule
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图二被打赏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分 | |
【FRDM-MCXN947评测】核间通信MUTEX被打赏50分 |