FPGA:图形 LCD 面板- 图形

2024-01-15  

图形 LCD 面板 3 - 图形

让我们研究一下生成图形视频数据的 3 种方法。

本文引用地址:

栅格化位图

在 LCD 上显示图形的经典(且简单)方法是将光栅化位图数据保存到 RAM 中。
我们将在这里使用一个 blockram。

我们在这里显示一个 128x32 像素的小位图(非常适合 4Kbits 块内存):

// Use a blockram to hold the graphical data
wire [7:0] BitmapData;
blockram_8x512 RAM_bitmap(.clk(clk), .rd_adr({CounterY[4:0],CounterX[4:1]}), .data_out(BitmapData));

// Let's say we need 4 bits at a time
wire [3:0] LCD_Bitmap4 = CounterX[0] ? BitmapData[3:0] : BitmapData[7:4];

// Display the data into a chessboard pattern
wire [3:0] LCD_BitmapChessboard = (CounterY[5] ^ CounterX[5]) ? 4'b000 : LCD_Bitmap4 ^ {4{CounterY[5]}};

上面未显示RAM的写入方式。最简单的方法是将其视为ROM(RAM内容是配置的一部分,在运行时不会改变)。

下面是一个微距镜头:

光栅化位图的缺点是需要足够大的 RAM 来保存位图的每个像素的状态。 使用内部 RAM的成本很高,因此通常使用外部RAM。

现在,让我们探索更多创建图形的原始方法。

曲线 y=F(x)

假设我们想要显示一个 y=F(x) 波形,就像正弦波一样。
这出乎意料地容易做到。 我们将“Y”值保存到一个块函数中,并通过读取RAM并将这些值与“CounterY”(当前行号)进行比较来逐行生成图片。
// We assume CounterX and CounterY are available:
//  CounterX is the pixel number of the current line
//  CounterY is the line number

// We use a RAM to hold the "Y" values
// Y=F(CounterX)
wire [7:0] RAM_Y_value;
blockram_8x512 RAM_FXY(.clk(clk), .rd_adr(CounterX), .data_out(RAM_Y_value));

// check for equality between the "Y" values and "CounterY"
reg grcpeq1;  
always @(posedge clk) grcpeq1 <= (RAM_Y_value==CounterY);
reg grcpeq2;  always @(posedge clk) grcpeq2 <= grcpeq1;

// check for "greater-than" between the "Y" values and "CounterY"
reg grcp1;  always @(posedge clk) grcp1 <= (RAM_Y_value>CounterY);
reg grcp2;  always @(posedge clk) grcp2 <= grcp1;

// display a pixel if equality, or if "CounterY" is between 2 successive "Y" values
wire FXpix= grcpeq2 | (grcp1 ^ grcp2);

以下是使用 F(x)=cos(x*2*pi/480)*sin(x*2*pi/480*4) 的结果:

旋转缩放

Rotozoom 是显示具有线性几何变形的位图的有效方法。 特别是,这允许轻松旋转和缩放图片。
在下面的实现中,我们在屏幕上显示一个旋转的棋盘图案。
reg [15:0] X0, Y0, X1, Y1;always @(posedge clk)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
    elsebegin
    X0 <= X0 + 400;
    Y0 <= Y0 + 100;end
    // Display a chessboard pattern by XOR'ing the MSB of X and Y counters
// You could also display a rotozoomed bitmap by feeding X and Y to a bitmap in a RAM
wire rotozoom_pix = X0[15] ^ Y0[15];

这被简化了,因为增量值是固定的(400 和 100 以上)。 您可能希望在实际实现中改变它们。 通过改变系数,您可以旋转和缩放棋盘。

这是与上一个波形混合的结果:

然后,您可以将其与一些文本混合在一起......

文章来源于:电子产品世界    原文链接
本站所有转载文章系出于传递更多信息之目的,且明确注明来源,不希望被转载的媒体或个人可与我们联系,我们将立即进行删除处理。