您好,欢迎访问三七文档
//2位数据选择器modulemux(clk_25m,rst_n,hsync,vsync,vga_r,vga_g,vga_b,sw_02,sw_12,sw_22,sw_3,buttom,ps2k_clk,ps2k_data,/*sel_1*/sm_db1,sm_db2,sm_db3,sm_db4);inputclk_25m;//时钟信号inputrst_n;//低电平复位inputbuttom;//大小转换按钮inputsw_3;//控制方式转换开关inputsw_02;//按钮控制颜色redinputsw_12;//greeninputsw_22;//blueinputps2k_clk;////PS2转换输入信号inputps2k_data;//output[1:0]sel_1;//FPGA与VGA接口信号outputhsync;//行同步信号outputvsync;//场同步信号output[2:0]vga_r;output[2:0]vga_g;output[1:0]vga_b;regihsync;//行同步信号regivsync;//场同步信号reg[2:0]ivga_r;reg[2:0]ivga_g;//颜色控制参数reg[1:0]ivga_b;output[6:0]sm_db1;//数码管输出变量output[6:0]sm_db2;output[6:0]sm_db3;output[6:0]sm_db4;Segments(.clk(clk_25m),.rst_n(rst_n),.sm_db1(sm_db1),.sm_db2(sm_db2),.sm_db3(sm_db3),.sm_db4(sm_db4),);//小regsw_0;regsw_1;regsw_2;wirehsync1,vsync1,vga_r1,vga_g1,vga_b1;vga_charxiao(.clk_25m(clk_25m),.rst_n(rst_n),.hsync(hsync1),.vsync(vsync1),.vga_r(vga_r1),.vga_g(vga_g1),.vga_b(vga_b1),.sw_0(sw_0),.sw_1(sw_1),.sw_2(sw_2),);wirehsync2,vsync2,vga_r2,vga_g2,vga_b2;//中vga_charzhongzhong(.clk_25m(clk_25m),.rst_n(rst_n),.hsync(hsync2),.vsync(vsync2),.vga_r(vga_r2),.vga_g(vga_g2),.vga_b(vga_b2),.sw_0(sw_0),.sw_1(sw_1),.sw_2(sw_2),);//大wirehsync3,vsync3,vga_r3,vga_g3,vga_b3;vga_chardada(.clk_25m(clk_25m),.rst_n(rst_n),.hsync(hsync3),.vsync(vsync3),.vga_r(vga_r3),.vga_g(vga_g3),.vga_b(vga_b3),.sw_0(sw_0),.sw_1(sw_1),.sw_2(sw_2),);//按钮控制wire[1:0]sel_2;sel_binst1(.rst_n(rst_n),.buttom(buttom),.cnt(sel_2),);//键盘控制wire[1:0]sel_1;wiresw_k0;wiresw_k1;wiresw_k2;sel_ksel_key(.clk(clk_25m),.ps2k_clk(ps2k_clk),.ps2k_data(ps2k_data),.cnt_1(sel_1),.rst_n(rst_n),.sw_k0(sw_k0),.sw_k1(sw_k1),.sw_k2(sw_k2),);/*outputregsw_10;//颜色控制outputregsw_11;outputregsw_12;*/reg[1:0]sel;always@(negedgeclk_25m)if(sw_3==1'd1)beginsel=sel_1;//键盘控制sw_0=sw_k0;sw_1=sw_k1;sw_2=sw_k2;endelsebeginsel=sel_2;//按钮控制sw_0=sw_02;sw_1=sw_12;sw_2=sw_22;end//大小选择模块always@(posedgeclk_25m,negedgerst_n)case(sel)2'b00:begin//小ihsync=hsync1;ivsync=vsync1;ivga_r=vga_r1;ivga_g=vga_g1;ivga_b=vga_b1;end2'b01:begin//中ihsync=hsync2;ivsync=vsync2;ivga_r=vga_r2;ivga_g=vga_g2;ivga_b=vga_b2;end//大2'b10:beginihsync=hsync3;ivsync=vsync3;ivga_r=vga_r3;ivga_g=vga_g3;ivga_b=vga_b3;end2'd11:beginihsync=hsync2;ivsync=vsync2;ivga_r=vga_r2;ivga_g=vga_g2;ivga_b=vga_b2;endendcaseassignhsync=ihsync,vsync=ivsync,vga_r=ivga_r,vga_g=ivga_g,vga_b=ivga_b;endmodulemodulevga_charda(clk_25m,rst_n,//系统控制hsync,vsync,vga_r,vga_g,vga_b,sw_0,sw_1,sw_2//VGA控制);inputclk_25m;//25MHzinputrst_n;//低电平复位inputsw_0;//按钮控制颜色inputsw_1;inputsw_2;//FPGA与VGA接口信号outputhsync;//行同步信号outputvsync;//场同步信号output[2:0]vga_r;output[2:0]vga_g;output[1:0]vga_b;//--------------------------------------------------//坐标计数reg[10:0]x_cnt;//行坐标reg[9:0]y_cnt;//列坐标always@(posedgeclk_25mornegedgerst_n)if(!rst_n)x_cnt=11'd0;elseif(x_cnt==11'd1039)x_cnt=11'd0;elsex_cnt=x_cnt+1'b1;always@(posedgeclk_25mornegedgerst_n)if(!rst_n)y_cnt=10'd0;elseif(y_cnt==10'd665)y_cnt=10'd0;elseif(x_cnt==11'd1039)y_cnt=y_cnt+1'b1;//--------------------------------------------------//VGA场同步,行同步信号reghsync_r,vsync_r;//同步信号always@(posedgeclk_25mornegedgerst_n)if(!rst_n)hsync_r=1'b1;elseif(x_cnt==11'd0)hsync_r=1'b0;//产生hsync信号elseif(x_cnt==11'd72)hsync_r=1'b1;always@(posedgeclk_25mornegedgerst_n)if(!rst_n)vsync_r=1'b1;elseif(y_cnt==10'd0)vsync_r=1'b0;//产生vsync信号elseif(y_cnt==10'd1)vsync_r=1'b1;assignhsync=hsync_r;assignvsync=vsync_r;//--------------------------------------------------//有效显示标志位产生regvalid_yr;//行显示有效信号always@(posedgeclk_25mornegedgerst_n)if(!rst_n)valid_yr=1'b0;elseif(y_cnt==10'd21)valid_yr=1'b1;elseif(y_cnt==10'd621)valid_yr=1'b0;wirevalid_y=valid_yr;regvalid_r;//VGA有效显示区标志位always@(posedgeclk_25mornegedgerst_n)if(!rst_n)valid_r=1'b0;elseif((x_cnt==11'd197)&&valid_y)valid_r=1'b1;elseif((x_cnt==11'd997)&&valid_y)valid_r=1'b0;wirevalid=valid_r;//wire[10:0]x_dis;//横坐标显示有效区域相对坐标值0-639wire[9:0]y_dis;//竖坐标显示有效区域相对坐标值0-479//assignx_dis=x_cnt-11'd197;assigny_dis=y_cnt-10'd21;//--------------------------------------------------reg[9:0]X_ORGIN;reg[9:0]Y_ORGIN;parameterX_SIZE=10'd400;parameterY_SIZE=10'd16;parameterMOVING_SPEED=10'd2;wire[9:0]UP_Knock;wire[9:0]DOWN_Knock;wire[9:0]RIGHT_Knock;wire[9:0]LEFT_Knock;reg[9:0]Last_X;reg[9:0]Last_Y;assignUP_Knock=Y_ORGIN-MOVING_SPEED;assignDOWN_Knock=Y_ORGIN+MOVING_SPEED+Y_SIZE;assignRIGHT_Knock=X_ORGIN+MOVING_SPEED+X_SIZE;assignLEFT_Knock=X_ORGIN-MOVING_SPEED;reg[3:0]MOVING_Cont;reg[2:0]RADOM_CONTROL;reg[3:0]MOVING_Step;initialbeginX_ORGIN=10'd197;Y_ORGIN=10'd29;MOVING_Cont=0;MOVING_Step=0;RADOM_CONTROL=3'b001;Last_X=10'd38;Last_Y=10'd28;end//movingcontrolalways@(negedgevsyncornegedgerst_n)beginif(!rst_n)beginendelseif(vsync==0)beginif(DOWN_Knock10'd597)beginif(Last_XX_ORGIN)RADOM_CONTROL=3'b000;elseRADOM_CONTROL=3'b100;endelseif(UP_Knock10'd3)beginif(Last_XX_ORGIN)RADOM_CONTROL=3'b001;elseRADOM_CONTROL=3'b101;endelseif(LEFT_Knock10'd197)beginif(Last_YY_ORGIN)RADOM_CONTROL=3'b011;elseRADOM_CONTROL=3'b111;endelseif(RIGHT_Knock10'd997)beginif(Last_YY_ORGIN)RAD
本文标题:VGA显示
链接地址:https://www.777doc.com/doc-2866343 .html