FPGA27 VGA display string

I design ideas

Four Chinese characters are displayed in the center of the screen. The
driving method is the same as the previous two sections, only the displayed content is different.

II Chinese character modulus

To display Chinese characters, you need to perform modulo operation of Chinese characters. The size of Chinese characters is 16x16
modulo software: https://download.csdn.net/download/helloworld573/12336962 The
steps are as follows:

Insert picture description here

III Code Part

module vga_display(
    input             vga_clk,                  //VGA驱动时钟
    input             sys_rst_n,                //复位信号
    
    input      [ 9:0] pixel_xpos,               //像素点横坐标
    input      [ 9:0] pixel_ypos,               //像素点纵坐标    
    output reg [15:0] pixel_data                //像素点数据,
    );    

//parameter define    
parameter  H_DISP = 10'd640;                    //分辨率——行
parameter  V_DISP = 10'd480;                    //分辨率——列

localparam POS_X  = 10'd288;                    //字符区域起始点横坐标
localparam POS_Y  = 10'd232;                    //字符区域起始点纵坐标
localparam WIDTH  = 10'd64;                     //字符区域宽度
localparam HEIGHT = 10'd16;                     //字符区域高度
localparam RED    = 16'b11111_000000_00000;     //字符颜色
localparam BLUE   = 16'b00000_000000_11111;     //字符区域背景色
localparam BLACK  = 16'b00000_000000_00000;     //屏幕背景色

//reg define
reg  [63:0] char[15:0];                         //字符数组
//数组中有十六个元素每个元素都是六十四位的
//类似于二维数组

//wire define   
wire [ 9:0] x_cnt;
wire [ 9:0] y_cnt;


assign x_cnt = pixel_xpos - POS_X;              //像素点相对于字符区域起始点水平坐标
assign y_cnt = pixel_ypos - POS_Y;              //像素点相对于字符区域起始点竖直坐标

//给字符数组赋值,显示四个汉字,汉字大小为16*16
always @(posedge vga_clk) begin
//char[0][0] 是指char[0]的最低位
//char[0][63] 是指char[0]的最高位 这是和4二维数组有所区别的
char[0] <= 64'h2090020000800000;
char[1] <= 64'h2090020800807FF8;
char[2] <= 64'h27FE3FD008800010;
char[3] <= 64'hA890022004800020;
char[4] <= 64'h73FC024024800040;
char[5] <= 64'h2294FFFE10800180;
char[6] <= 64'hFBFC010010800100;
char[7] <= 64'h229402000080FFFE;
char[8] <= 64'h73FC0C10FFFE0100;
char[9] <= 64'h680018E001000100;
char[10] <= 64'hA9F82F0001400100;
char[11] <= 64'h2108480802200100;
char[12] <= 64'h21F8880804100100;
char[13] <= 64'h2108080808080100;
char[14] <= 64'h21F807F830040500;
char[15] <= 64'h21080000C0040200;
end

//给不同的区域绘制不同的颜色
always @(posedge vga_clk or negedge sys_rst_n) begin         
    if (!sys_rst_n) 
        pixel_data <= BLACK;
    else begin
        if((pixel_xpos >= POS_X) && (pixel_xpos < POS_X + WIDTH)
          && (pixel_ypos >= POS_Y) && (pixel_ypos < POS_Y + HEIGHT)) begin
             //这个大if圈定了字符的区域
             
            if(char[y_cnt][10'd63 - x_cnt])     
                //这样才能从char[y_cnt]的高位向低位读
                pixel_data <= RED;              
                //绘制字符为红色
            else
                pixel_data <= BLUE;             //绘制字符区域背景为蓝色
        end
        else
            pixel_data <= BLACK;                //绘制屏幕背景为黑色
    end
end

endmodule 

IV Three questions

1 How to determine the center position of the screen

Insert picture description here

2 How to scan to the central character area

Insert picture description here

3 Define the array used to store fonts

Insert picture description here

V final effect

Insert picture description here

Guess you like

Origin blog.csdn.net/helloworld573/article/details/105597775