fpga图像处理学习日记

Posted fpgamzy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了fpga图像处理学习日记相关的知识,希望对你有一定的参考价值。

这一次的学习任务主要为在vga显示屏上面显示汉字或是字母,代码的原理出现了新的知识,首先汉字或是字母在屏幕上的排列方式转化为代码使用了pctolcd2002软件来完成,在校对好对应的参数之后,就可以通过软件直接来输出代码

技术图片

例如上述汉字“嘻嘻嘻”,借助软件转化为了我们需要使用的代码

嘻(0) 嘻(1) 嘻(2)

DB 00H 40H;
DB 07H FCH;
DB F0H 40H;
DB 93H F8H;
DB 90H 00H;
DB 93H F8H;
DB 92H 08H;
DB 93H F8H;
DB 91H 10H;
DB 9FH FEH;
DB F0H 00H;
DB 93H F8H;
DB 02H 08H;
DB 02H 08H;
DB 03H F8H;
DB 02H 08H;"嘻",0

DB 00H 40H;
DB 07H FCH;
DB F0H 40H;
DB 93H F8H;
DB 90H 00H;
DB 93H F8H;
DB 92H 08H;
DB 93H F8H;
DB 91H 10H;
DB 9FH FEH;
DB F0H 00H;
DB 93H F8H;
DB 02H 08H;
DB 02H 08H;
DB 03H F8H;
DB 02H 08H;"嘻",1

DB 00H 40H;
DB 07H FCH;
DB F0H 40H;
DB 93H F8H;
DB 90H 00H;
DB 93H F8H;
DB 92H 08H;
DB 93H F8H;
DB 91H 10H;
DB 9FH FEH;
DB F0H 00H;
DB 93H F8H;
DB 02H 08H;
DB 02H 08H;
DB 03H F8H;
DB 02H 08H;"嘻",2

 

之后就只需要根据vga的扫描方式来完成显示即可,值得一提的是,汉字或是字母等等再vga上的显示过程并不是一个一个完整的,有先后的显示,而是逐行显示,根据之前学到的编辑方式,总体的设计并没有出现什么难题

代码:

module vga_3(

input clk_100mhz, //25mhz
input rst_n,

output hsync,
output vsync,
output [2:0]vga_r,
output [2:0]vga_g,
output [1:0]vga_b

);

wire clk_25m;

c100_25 u3(
.clk_100mhz(clk_100mhz),
.rst_n(rst_n),
.clk_25m(clk_25m)
);


//-------------------------------------------------------------------
reg [9:0] x_cnt;
reg [9:0] y_cnt;

[email protected](posedge clk_25m or negedge rst_n)
begin
if(!rst_n)
x_cnt <= 10‘d0;
else if(x_cnt == 10‘d799)
x_cnt <= 10‘d0;
else
x_cnt <= x_cnt + 1‘b1;
end

[email protected](posedge clk_25m or negedge rst_n)
begin
if(!rst_n)
y_cnt <= 10‘d0;
else if(y_cnt == 10‘d524)
y_cnt <= 10‘d0;
else if(x_cnt == 10‘d799)
y_cnt <= y_cnt + 1‘b1;
else
y_cnt <= y_cnt;
end
//-------------------------------------------------------------------
reg hsync_r,vsync_r;

[email protected](posedge clk_25m or negedge rst_n)
begin
if(!rst_n)
hsync_r <= 1‘b1;
else if(x_cnt == 10‘d0)
hsync_r <= 1‘b0;
else if(x_cnt == 10‘d96)
hsync_r <= 1‘b1;
else
hsync_r <= hsync_r;
end

[email protected](posedge clk_25m or negedge rst_n)
begin
if(!rst_n)
vsync_r <= 1‘b1;
else if(y_cnt == 10‘d0)
vsync_r <= 1‘b0;
else if(y_cnt == 10‘d2)
vsync_r <= 1‘b1;
else
vsync_r <= vsync_r;
end

assign hsync = hsync_r;
assign vsync = vsync_r;
//-------------------------------------------------------------------
reg valid_yr;

[email protected](posedge clk_25m or negedge rst_n)
begin
if(!rst_n)
valid_yr <= 1‘b0;
else if(y_cnt == 10‘d32)
valid_yr <= 1‘b1;
else if(y_cnt == 10‘d512)
valid_yr <= 1‘b0;
else
valid_yr <= valid_yr;
end

wire valid_y = valid_yr;

reg valid_r;

[email protected](posedge clk_25m or negedge rst_n)
begin
if(!rst_n)
valid_r <= 1‘b0;
else if( (x_cnt == 10‘d141) && valid_y )
valid_r <= 1‘b1;
else if( (x_cnt == 10‘d781) && valid_y )
valid_r <= 1‘b0;
else
valid_r <= valid_r;
end

wire valid = valid_r;

//wire [9:0] x_dis; // 横坐标显示有效区域相对坐标值0-639

wire [9:0] y_dis; // 数坐标显示有效区域相对坐标值0-479

//assign x_dis = x_cnt - 10‘d142;

assign y_dis = y_cnt - 10‘d33;

//-------------------------------------------------------------------

parameter char_line0 = 24‘h00_00_00,
char_line1 = 24‘h00_00_00,
char_line2 = 24‘h00_00_00,
char_line3 = 24‘hfc_f8_c7,
char_line4 = 24‘h42_44_62,
char_line5 = 24‘h48_42_62,
char_line6 = 24‘h48_42_52,
char_line7 = 24‘h78_42_52,
char_line8 = 24‘h48_42_4a,
char_line9 = 24‘h48_42_4a,
char_linea = 24‘h40_42_4a,
char_lineb = 24‘h42_42_46,
char_linec = 24‘h42_44_46,
char_lined = 24‘hfc_f8_e2,
char_linee = 24‘h00_00_00,
char_linef = 24‘h00_00_00;

reg [4:0]char_bit; // 显示位计算

[email protected](posedge clk_25m or negedge rst_n)
begin
if(!rst_n)
char_bit <= 5‘h1f;
else if(x_cnt == 10‘d442)
char_bit <= 5‘d23;
else if(x_cnt > 10‘d442 && x_cnt < 10‘d466)
char_bit <= char_bit - 1‘b1;
else
char_bit <= char_bit;
end

reg [7:0] vga_rgb; // 色彩显示寄存器

[email protected](posedge clk_25m )
begin
if(!valid)
vga_rgb <= 8‘d0;
else if(x_cnt > 10‘d442 && x_cnt < 10‘d466)
begin
case(y_dis)
10‘d231:
if(char_line0[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d232:
if(char_line1[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d233:
if(char_line2[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d234:
if(char_line3[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d235:
if(char_line4[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d236:
if(char_line5[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d237:
if(char_line6[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d238:
if(char_line7[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d239:
if(char_line8[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d240:
if(char_line9[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d241:
if(char_linea[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d242:
if(char_lineb[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d243:
if(char_linec[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d244:
if(char_lined[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d245:
if(char_linee[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
10‘d246:
if(char_linef[char_bit])
vga_rgb <= 8‘b111_000_00;
else
vga_rgb <= 8‘b000_111_00;
default: vga_rgb <= 8‘h00;
endcase
end
else
vga_rgb <= 8‘h00;
end

assign vga_r = vga_rgb[7:5];
assign vga_g = vga_rgb[4:2];
assign vga_b = vga_rgb[1:0];



endmodule

 






























































































































































































































































































以上是关于fpga图像处理学习日记的主要内容,如果未能解决你的问题,请参考以下文章

fpga图像处理学习日记

学习日记-2016.3.31

python学习日记——常见环境问题及处理

SSH学习日记之Struts

Linux学习日记(常用命令)

学习日记(字符串处理函数小知识strxxx)