有效区内自动调整后右边还有一小部分没有显示正常颜 {MOD},而是像灰 {MOD}线条一样的边框,是什么原因??还有最左边怎么会多出一点点不一样的颜 {MOD}??
module VGA_ROM(clk_50M,res_n,hs,vs,r,g,b);
input clk_50M; //系统时钟50M
input res_n; // 复位
output hs,vs; //行、场信号
output r,g,b; //r,g,b信号各一位
wire hs;
wire vs;
wire CLK_65M;
pll_65 u1(
.inclk0(clk_50M),
.c0(CLK_65M), //1024*768,1344*806*60=65M
);
reg [15:0]h_cnt; //行计数器
reg [15:0]v_cnt; //列计数器
always@(posedge CLK_65M or negedge res_n)
begin
if(!res_n) h_cnt<=16'd0;
else if(h_cnt==16'd1344)
h_cnt<=16'd0;
else
h_cnt<=h_cnt+1'b1;
end
always@(posedge CLK_65M or negedge res_n)
begin
if(!res_n) v_cnt<=16'd0;
else if(v_cnt==16'd806)
v_cnt<=16'd0;
else if(h_cnt==16'd1344)
v_cnt<=v_cnt+1'b1;
end
wire flag; //有效区域标识
assign flag=((v_cnt>=16'd35)&&(v_cnt<16'd803))&&((h_cnt>=16'd296)&&(h_cnt<16'd1320));
reg hs_r;
reg vs_r;
always@(posedge CLK_65M or negedge res_n)
begin
if(!res_n) hs_r<=1'b0;
else if(h_cnt<16'd136) hs_r<=1'b0; //行同步负极性
else hs_r<=1'b1;
end
always@(posedge CLK_65M or negedge res_n)
begin
if(!res_n) vs_r<=1'b0;
else if(v_cnt<16'd6) vs_r<=1'b0; //场同步负极性
else vs_r<=1'b1;
end
assign vs=vs_r;
assign hs=hs_r;
parameter Left=296, //行同步+行后消隐
PixelWidth=128, //行分8个块
PixelWidth1=192, //列分4个块
TOP=35; //场同步+场后消隐
reg [4:0]Xcoloradd;
reg [2:0]Ycoloradd;
always@(posedge CLK_65M or negedge res_n) //产生行地址(ROM水平地址)
begin
if(!res_n) Xcoloradd<=5'b00000;
else if(h_cnt>=Left&&h_cnt<Left+PixelWidth) Xcoloradd<=5'b00000;
else if(h_cnt>=Left+PixelWidth&&h_cnt<Left+2*PixelWidth) Xcoloradd<=5'b00010;
else if(h_cnt>=Left+2*PixelWidth&&h_cnt<Left+3*PixelWidth) Xcoloradd<=5'b00011;
else if(h_cnt>=Left+3*PixelWidth&&h_cnt<Left+4*PixelWidth) Xcoloradd<=5'b00100;
else if(h_cnt>=Left+4*PixelWidth&&h_cnt<Left+5*PixelWidth) Xcoloradd<=5'b00101;
else if(h_cnt>=Left+5*PixelWidth&&h_cnt<Left+6*PixelWidth) Xcoloradd<=5'b00110;
else if(h_cnt>=Left+6*PixelWidth&&h_cnt<Left+7*PixelWidth) Xcoloradd<=5'b00111;
else if(h_cnt>=Left+7*PixelWidth&&h_cnt<Left+8*PixelWidth) Xcoloradd<=5'b01000;
else Xcoloradd<=5'b11000;
end
always@(posedge CLK_65M or negedge res_n) //列地址(ROM垂直地址)
begin
if(!res_n) Ycoloradd<=3'b000;
else if(v_cnt>=TOP&&v_cnt<TOP+PixelWidth1) Ycoloradd<=3'b000;
else if(v_cnt>=TOP+PixelWidth1&&v_cnt<TOP+2*PixelWidth1) Ycoloradd<=3'b010;
else if(v_cnt>=TOP+2*PixelWidth1&&v_cnt<TOP+3*PixelWidth1) Ycoloradd<=3'b011;
else if(v_cnt>=TOP+3*PixelWidth1&&v_cnt<TOP+4*PixelWidth1) Ycoloradd<=3'b100;
else Ycoloradd<=3'b110;
end
wire [4:0]coloradd;
wire [2:0]color;
assign coloradd=Xcoloradd|{Ycoloradd,2'b00}; //将水平地址和垂直地址合成ROM实际地址
rom_data u2( // 调用一个单口ROM
.address(coloradd),
.clock(CLK_65M),
.q(color)
);
assign {r,g,b}=(flag==1)?color:0;
endmodule
C:UsersxzqDesktop
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>