热度 21
2013-4-28 08:31
3457 次阅读|
0 个评论
液晶显示图片: 好奇妙的图片,这个图片是怎么来的,奥秘就在下面: module TFT_HVGen(CLK,DCLK,LCDHS,LCDVS,LCDUD,LCDLR,LCDDITHB,LCDPWM,LCDR,LCDG,LCDB); input CLK54; output DCLK; output LCDHS; output LCDVS; output LCDUD; output LCDLR; output LCDDITHB; output LCDPWM; output LCDR; output LCDG; output LCDB; reg DCLK; reg LCDHS; reg LCDVS; reg hcnt; reg vcnt; wire LCDDATA; assign LCDDITHB = 1'b0; assign LCDPWM = 1'b0; assign LCDUD = 1'b0; assign LCDLR = 1'b1; always@(posedge CLK) begin DCLK = ~DCLK ; end always@(posedge DCLK) begin if(hcnt == 10'd861) hcnt = 10'd1; else hcnt = hcnt + 1'b1; if(hcnt == 10'd815) begin if(vcnt 9'd509) vcnt = vcnt + 9'd1; else vcnt = 9'd0; end end always@(posedge DCLK) begin if(hcnt == 10'd815) LCDHS = 1'b0; if(hcnt == 10'd818) LCDHS = 1'b1; if(vcnt == 9'd486) LCDVS = 1'b0; if(vcnt == 9'd487) LCDVS = 1'b1; end reg Hactive; reg Vactive; wire DE= HactiveVactive; always@* begin if(hcnt = 10'd799) Hactive = 1'b1; else Hactive = 1'b0; end always@* begin if(vcnt = 10'd479) Vactive = 1'b1; else Vactive = 1'b0; end assign LCDDATA = hcnt*vcnt ; assign {LCDR,LCDG,LCDB} = DE? LCDDATA : 16'b0; endmodule ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 上面一个问题被修正了Hactive Vactive 原来用时序DCLK逻辑判断,改成组合逻辑 要不然点会对不上,与2012/12/15日18:28分修正,之前下载代码的朋友请注意。 不过还有个问题大家兴趣可以自己试下,我就不说了,很多东西多要自己发现,手册也 不一定全对。 上面的 hcnt*vcnt 就是奥秘,吧 hcnt*vcnt 乘积赋值给像素点 就得到奇妙的图片,电子世界真是奇妙无穷啊,另外通过改变 LCDDATA ,LCDDATA 会看到更细的。 最后来一张rotozoom 图片,算法是参考 fpga4fun网站上的 parameter ScreenWidth = 10'd800; parameter ScreenHeight = 9'd480; wire CounterXmaxed = (hcnt==ScreenWidth-1); wire CounterYmaxed = (vcnt==ScreenHeight-1); reg HSync, VSync; always @(posedge DCLK) begin HSync = CounterXmaxed; VSync = CounterYmaxed; end reg X0, Y0, X1, Y1; always @(posedge DCLK) if(VSync) begin X0 = 0; Y0 = 0; X1 = 0; Y1 = 0; end else if(HSync) begin X0 = X1 - 100; Y0 = Y1 + 400; X1 = X1 - 100; Y1 = Y1 + 400; end else begin X0 = X0 + 400; Y0 = Y0 + 100; end assign {LCDR,LCDG,LCDB} = (X0 ^ Y0 ) ? 16'h5aab:16'h9534; assign {LCDR,LCDG,LCDB} = (X0 ^ Y0 ) ? 16'hffff:16'h0000;