一、字模显示原理
字模数据:将这个0/1矩阵按照屏幕扫描的顺序以字节的形式体现。
取模软件设计:
点阵数要按照实际情况填写
二、实验任务
本节的实验任务是通过开发板上的RGB TFT-LCD接口,在RGB LCD液晶屏的左上角位置从上到下依次显示图片以及汉字“你好,FPGA”。其中每个汉字的大小为32*32,图片的大小为770*306。
三、程序设计
1、lcd_display框架:
`timescale 1ns / 1ps
module lcd_display(
input sys_clk ,
input sys_rst_n ,
input [10:0] pixel_xpos , //像素点横坐标
input [10:0] pixel_ypos , //像素点纵坐标
output reg [23:0] pixel_data //像素点数据
);
localparam PIC_X_START = 11'd15; //图片起始点横坐标
localparam PIC_Y_START = 11'd15; //图片起始点纵坐标
localparam PIC_WIDTH = 11'd164; //图片宽度
localparam PIC_HEIGHT = 11'd57; //图片高度
localparam CHAR_X_START = 11'd15; //字符起始点横坐标
localparam CHAR_Y_START = 11'd75; //字符起始点纵坐标
localparam CHAR_WIDTH = 11'd160; //字符宽度
localparam CHAR_HEIGHT = 11'd32; //字符高度
localparam BACK_COLOR = 24'hE0FFFF; //背景颜色 浅蓝色
localparam CHAR_COLOR = 24'hff0000; //字体颜色,红色
reg [160:0] char[31:0] ; //二维寄存器
reg [13:0] rom_addr ; //ROM地址
wire [10:0] x_cnt ;
wire [10:0] y_cnt ;
wire rom_rd_en ;
wire [23:0] rom_rd_data ;
assign rom_rd_en = 1'b1; //始终使能
assign x_cnt = pixel_xpos + 1'b1 - CHAR_X_START;
assign y_cnt = pixel_ypos - CHAR_Y_START;
//给二维寄存器写入字符信息 你好,FPGA
always @(posedge sys_clk) begin
char[0 ] <= 160'h0000000000000000000000000000000000000000;
char[1 ] <= 160'h0000000000000000000000000000000000000000;
char[2 ] <= 160'h0000000000000000000000000040000001000000;
char[3 ] <= 160'h0000000000000000000000000070600001C00000;
char[4 ] <= 160'h0000000000000000000000000060E00001800020;
char[5 ] <= 160'h00000000000000000000000000E0C0000181FFF0;
char[6 ] <= 160'h7FFC7FF003C003800000000000C0C00001800070;
char[7 ] <= 160'h181C18180C3003800000000000C18000010000C0;
char[8 ] <= 160'h1804180C08100380000000000181801803080080;
char[9 ] <= 160'h1802180618180380000000000103FFFC3FFC0100;
char[10] <= 160'h18021806300804C0000000000303001803080600;
char[11] <= 160'h18001806300804C0000000000386103003080600;
char[12] <= 160'h18001806200004C00000000007840C2002180600;
char[13] <= 160'h18101806600004C0000000000D8C084006180600;
char[14] <= 160'h1810180660000C40000000000988080006180600;
char[15] <= 160'h1830180C60000860000000001190080004180618;
char[16] <= 160'h1FF018186000086000000000118188000417FFFC;
char[17] <= 160'h18301FE06000086000000000218388800C300600;
char[18] <= 160'h18101800607E182000000000018308400C300600;
char[19] <= 160'h1810180060181FF0000000000183082008300600;
char[20] <= 160'h1810180060181030070000000186083008600600;
char[21] <= 160'h18001800201810300F800000018608180E600600;
char[22] <= 160'h18001800301810300F800000018C081C01C00600;
char[23] <= 160'h1800180030182018078000000188080C00F00600;
char[24] <= 160'h1800180010182018018000000190080C00BC0600;
char[25] <= 160'h1800180018182018030000000190080C018C0600;
char[26] <= 160'h180018000C20601C0200000001A0080003040600;
char[27] <= 160'h7E007E0007C0F83E040000000180080004000600;
char[28] <= 160'h0000000000000000180000000180F8000800FC00;
char[29] <= 160'h0000000000000000000000000180380030001C00;
char[30] <= 160'h0000000000000000000000000100100000000800;
char[31] <= 160'h0000000000000000000000000000000000000000;/*"D:\开发素材\FPGA文本\FPGA你好.BMP",0*/
end
//为LCD不同区域显示绘制图片、字符和背景颜色
always @(posedge sys_clk or negedge sys_rst_n ) begin
if (!sys_rst_n) begin
pixel_data <= 24'h0;
end
else if((pixel_xpos >= PIC_X_START - 1'b1) && (pixel_xpos < PIC_X_START + PIC_WIDTH - 1'b1)
&& (pixel_ypos >= PIC_Y_START) && (pixel_ypos < PIC_Y_START + PIC_HEIGHT))begin
pixel_data <= rom_rd_data;
end
else if ((pixel_xpos >= CHAR_X_START - 1'b1) && (pixel_xpos < CHAR_X_START + CHAR_WIDTH - 1'b1)
&& (pixel_ypos >= CHAR_Y_START) && (pixel_ypos < CHAR_Y_START + CHAR_HEIGHT)) begin
if (char[y_cnt][CHAR_WIDTH -1'b1 - x_cnt] == 1'b1) begin
pixel_data <= CHAR_COLOR;
end
else begin
pixel_data <= BACK_COLOR;
end
end
else begin
pixel_data <= BACK_COLOR;
end
end
//根据当前扫描点的横纵坐标为ROM地址赋值
always @(posedge sys_clk or negedge sys_rst_n ) begin
if (!sys_rst_n) begin
rom_addr <= 14'd0;
end
//当位于图片显示区域的时候ROM地址进行累加
else if((pixel_ypos >= PIC_Y_START) && (pixel_ypos < PIC_Y_START + PIC_HEIGHT) && (pixel_xpos >= PIC_X_START - 2'd2)
&& (pixel_xpos < PIC_X_START + PIC_WIDTH - 2'd2))begin
rom_addr <= rom_addr + 1'b1;
end
//当横坐标位于图片最后一个像素点时,ROM地址清零
else if (pixel_ypos >= PIC_Y_START + PIC_HEIGHT) begin
rom_addr <= 18'd0;
end
else begin
rom_addr <= rom_addr;
end
end
RGB_LCD u_RGB_LCD (
.clka(sys_clk), // input wire clka
.ena(rom_rd_en), // input wire ena
.addra(rom_addr), // input wire [13 : 0] addra
.douta(rom_rd_data) // output wire [23 : 0] douta
);
endmodule
其他部分均沿用上期博客LCD彩条显示——FPGA学习笔记10-CSDN博客的代码
文件结构如图所示:
2、ROM IP核
3、仿真
字符显示:
图片显示: