VGA接口时序练习之图像动态显示

该博客介绍了如何使用FPGA实现VGA接口动态显示图像,包括全红、全白、2*2和3*3颜色分区以及150*100矩形边框的循环变换。内容涵盖VGA接口时序、颜色显示原理及代码实现,分辨率为600*480,以3秒为周期进行图像变化。
摘要由CSDN通过智能技术生成

Vga练习之动态显示图案

Vga接口应用,并在电脑显示屏上显示

功能:每隔3s变化一次,a~e循环变换

a.全红

b.全白

c.2*2  4部分,分别是:红,蓝,绿,黄

d.3*3  9部分,分别是:红黄蓝绿黑紫白青粉

e.150*100矩形边框,边缘是20宽度的绿色框,其他为白色

 

分辨率:600*480

 

VGA支持的规格:

1.水平时序:

分辨率

刷新速率

像素频率

同步脉冲

后沿

有效时间

前沿

帧长

640/480

60

25

96

45

646

13

800

640/480

72

31

40

125

646

21

832

800/600

60

40

128

85

806

37

1056

800/600

56

36

72

125

806

21

1024

800/600

72

50

120

611

806

53

1040

 

2.垂直时序:

分辨率

刷新速率

像素频率

同步脉冲

后沿

有效时间

前沿

帧长

640/480

60

31

2

30

484

9

525

640/480

72

26

3

26

484

7

520

800/600

56

28

1

20

604

-1

625

800/600

60

26

4

21

604

-1

628

800/600

72

20

6

21

604

35

666

 

VGA行时序:

VGA场时序:


VGA颜色显示原理:

         通过三基色r,g,b的不同组合,显示出不同的颜色。


三基色示意图如下:


三基色颜色编码:

颜色

绿

R

0

0

1

1

0

0

1

1

G

0

0

0

0

1

1

1

1

B

0

1

0

1

0

1

0

1

 

代码部分:

/******************************

分辨率:600*480

功能:每隔3s变化一次,a~e循环变换

a.全红

b.全白

c.2*2  4部分,分别是:红,蓝,绿,黄

d.3*3  9部分,分别是:红黄蓝绿黑紫白青粉

e.150*100矩形边框,边缘是20宽度的绿色框,其他为白色

********************************/

 

module VGA_test4(clk,rst_n,lcd_data,lcd_hs,lcd_vs);

 

input clk;   //25mhz

input rst_n;

output lcd_vs;//场同步信号

output lcd_hs;//行同步信号

output [7:0]lcd_data;//lcd_data[1:0]B,

//lcd_data[4:2]G,lcd_data[7:5]R

 

parameter LCD_HS_CNT = 799,

              LCD_VS_CNT = 524;

 

reg [9:0] lcd_hs_cnt;//行同步计数

always@(posedge clk or negedge rst_n)

    if(!rst_n)

        lcd_hs_cnt <= 10'd0;

    else if(lcd_hs_cnt==LCD_HS_CNT)

        lcd_hs_cnt <= 10'd0;

    else

        lcd_hs_cnt <= lcd_hs_cnt + 1'b1;

       

reg lcd_hs;    

always@(posedge clk or negedge rst_n)

    if(!rst_n)

        lcd_hs <= 1'b0;

    else if(lcd_hs_cnt<96)

        lcd_hs <= 1&#

Bmp To Mif 转换器 // (karimov 2005) // This program was originnaly written by one of the ECE241 students to convert an image // supplied in a BMP file into an MIF file format for use with Quartus II. // // This program has recently been modified to work with the new VGA controller used with the DE2 // board. // // What to do: // 1. Create an image in Microsoft paint (or other program). The image must be 160 pixels wide, 120 pixels high and // use 24-bits to represent colour information. // 2. Once you create the image you need, flip it up-side down. Then save the BMP file. (example: foo.bmp) // 3. Run this converter in command prompt using the name of the BMP file you created as a command-line parameter. // For example: // bmp2mif foo.bmp // 4. The program generates two files: // image.colour.mif - an MIF file with 3 bits colour information obtained from the BMP file you supplied // image.mono.mif - an MIF file containing 1 bit of colour for every pixel on the screen. The dot will either be // black or white. // You can change the file names once they are created, but they should still have the .mif extension. // // 5. Copy the proper MIF file to the directory where your design is located and include it in your project. // 6. Change the BACKGROUND_IMAGE parameter of the VgaAdapter to indicate your MIF file. // 7. The COLOR_CHANNEL_DEPTH parameter must be set to 1 to work with the image.colour.mif file. #include #include #define FLIP_INT(c) ((c >> 24) & 0x000000FF) | ((c & 0x00FF0000) >> 8) | ((c & 0x0000FF00) << 8) | ((c & 0x000000FF) <> 8) | ((c & 0x00FF) << 8) typedef struct s_header { unsigned short bfType; unsigned int bfSize; unsigned short reserved1; unsigned short reserved2; unsigned int offset; } t_bmp_header; typedef struct s_bmp_info { unsigned int biSize; unsigned int biWidth; unsigned int biHeight; unsigned short biPlanes; unsigned short biBitCount; unsigned int biCompression; unsigned int biSizeImage; unsigned int biXPelsPerMeter; unsigned int biYPelsPerMeter; unsigned int biClrUsed; unsigned int biClrImportant; } t_bmp_info; int faprint(FILE *fcol, FILE *fm, const char *pattern) { fprintf(fcol, pattern); return fprintf(fm, pattern); } int main(int argc, char* argv[]) { FILE *f, *fcol, *fm; int y; unsigned int x, c, r, g, b; unsigned int width, height; if (argc != 2) { printf("Usage: bmp2mif \n"); return 0; } else { printf("Input file is: %s\n", argv[1]); } printf("This program converts n x m 24-bit .BMP image to MIF file\n"); printf("There are 2 files produced:\n"); printf("\timage.colour.mif - 8-colour channel, n x m x 3\n"); printf("\timage.mono.mif - black and white image, n x m x 1\n\n"); f = fopen(argv[1], "rb"); fcol = fopen("image.colour.mif", "wb"); fm = fopen("image.mono.mif", "wb"); if (f) { t_bmp_header header; t_bmp_info info; fread(&header, 14, 1, f); /* sizeof(t_bmp_header) returns 16 instead of 14. Should be 14. */ fread(&info, sizeof(t_bmp_info), 1, f); #if !defined (WIN32) header.bfSize = FLIP_INT(header.bfSize); header.bfType = FLIP_SHORT(header.bfType); header.offset = FLIP_INT(header.offset); header.reserved1 = FLIP_SHORT(header.reserved1); header.reserved2 = FLIP_SHORT(header.reserved2); info.biSize = FLIP_INT(info.biSize); info.biWidth = FLIP_INT(info.biWidth); info.biHeight = FLIP_INT(info.biHeight); info.biPlanes = FLIP_SHORT(info.biPlanes); info.biBitCount = FLIP_SHORT(info.biBitCount); info.biCompression = FLIP_INT(info.biCompression); info.biSizeImage = FLIP_INT(info.biSizeImage); info.biXPelsPerMeter = FLIP_INT(info.biXPelsPerMeter); info.biYPelsPerMeter = FLIP_INT(info.biYPelsPerMeter); info.biClrUsed = FLIP_INT(info.biClrUsed); info.biClrImportant = FLIP_INT(info.biClrImportant); #endif printf("Input file is %ix%i %i-bit depth\n", info.biWidth, info.biHeight, info.biBitCount); if (info.biBitCount == 24) { char temp[100]; width = info.biWidth; height = info.biHeight; printf("Converting...\n"); sprintf(temp, "Depth = %i;\r\n",width*height); faprint(fcol, fm, temp); fprintf(fcol, "Width = 3;\r\n"); fprintf(fm, "Width = 1;\r\n"); faprint(fcol, fm, "Address_radix=dec;\r\n"); faprint(fcol, fm, "Data_radix=bin;\r\n"); faprint(fcol, fm, "Content\r\n"); faprint(fcol, fm, "BEGIN\r\n"); sprintf(temp, "\t[0..%i] : 000;\r\n", width*height - 1); fprintf(fcol, temp); sprintf(temp, "\t[0..%i] : 0;\r\n", width*height - 1); fprintf(fm, temp); fseek(f, 54, SEEK_SET); for(y=height-1; y >=0; y--) { x = 0; fprintf(fcol, "\t%i :", y*width+x); fprintf(fm, "\t%i :", y*width+x); for(x=0; x 0) && ((x % 40) == 0)) { fprintf(fcol, ";\r\n\t%i :", y*width + x); fprintf(fm, ";\r\n\t%i :", y*width + x); } #if defined (WIN32) c = ((c >> 24) & 0x000000FF) | ((c & 0x00FF0000) >> 8) | ((c & 0x0000FF00) << 8) | ((c & 0x000000FF) <>= 8; b = (c & 0xFF0000) >> 16; g = (c & 0x00FF00) >> 8; r = (c & 0x0000FF); c = r + g + b; c /= 3; r = (r >= 128 ? 1 : 0); g = (g >= 128 ? 1 : 0); b = (b >= 128 ? 1 : 0); c = (c >= 128 ? 1 : 0); fprintf(fcol, " %i%i%i", r, g, b); fprintf(fm, " %i", c); } faprint(fcol, fm, ";\r\n"); if ((x*3) % 4 != 0) { fread(&c, 4-((x*3) % 4), 1, f); } } faprint(fcol, fm, "End;\r\n"); } else printf("Input file image.bmp is not in a 24-bit colour format!\n"); fclose(fm); fclose(fcol); fclose(f); printf("All done.\n"); } else printf("Cannot open input file. Check for input.bmp\n"); }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值