名称:随机方向的弹球运动图像VGA显示DE1-SoC开发板(代码在文末下载)
软件:Quartus II
语言:Verilog
代码功能:
VGA弹球图案。
创建一个分辨率为640x480的VGA显示器的弹球图案。弹球开始并将沿随机方向移动。块有8个移动方向。
本代码已在DE1-SOC开发板验证,其他开发板可以修改管脚适配,开发板如下:
FPGA代码Verilog/VHDL代码资源下载:www.hdlcode.com
部分代码展示:
`timescale 1ns / 1ps //产生方块和运行方向 module graphic_generator(clk, rst, pixel_x, pixel_y, r, g, b); input clk, rst; input [9:0] pixel_x, pixel_y; //像素坐标 output [7:0] r, g, b; reg [11:0] rgb; wire refr_tick; // refr-tick: 1-clock tick asserted at st art of v-sync // i.e.. when the screen is refreshed (60 Hz) assign refr_tick = (pixel_y==479) && (pixel_x==1); // ========================== // object output signals // ========================== // //m序列 reg [5:0] ddout=6'b000001; always@(posedge clk) begin ddout[0] <=ddout[1];//移位 ddout[1] <=ddout[2];//移位 ddout[2] <=ddout[3];//移位 ddout[3] <=ddout[4];//移位 ddout[4] <=ddout[3]^ddout[0];//本源多项式为x5+x2+1 end // wire ball_on; wire [11:0] ball_rgb; reg [9:0] dir_x=2; reg [9:0] dir_y=2; always@(*) case(ddout[2:0]) 3'd0: begin dir_x=2; dir_y=2; end 3'd1: begin dir_x=2; dir_y=-2; end 3'd2: begin dir_x=-2; dir_y=2; end 3'd3: begin dir_x=-2; dir_y=-2; end 3'd4: begin dir_x=0; dir_y=2; end 3'd5: begin dir_x=0; dir_y=-2; end 3'd6: begin dir_x=2; dir_y=0; end 3'd7: begin dir_x=-2; dir_y=0; end endcase // =============== // 球 // =============== // ball left, right boundary wire [9:0] ball_x_l, ball_x_r; // ball tob, bottom boundary wire [9:0] ball_y_t, ball_y_b; // reg to track left , top position reg [9:0] ball_x_reg , ball_y_reg ; wire [9:0] ball_x_next , ball_y_next ;
点击链接获取代码文件:http://www.hdlcode.com/index.php?m=home&c=View&a=index&aid=235
阅读全文
663