找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3905|回复: 0
收起左侧

FPGA VGA显示 verilog源码仿真与资料分享

[复制链接]
ID:240399 发表于 2018-9-27 19:24 | 显示全部楼层 |阅读模式
FPGA 驱动vga显示源码仿真与资料都有
0.png 0.png 0.png

  1. `timescale 1ns / 1ps
  2. /*==============================================================================
  3. Engineer            : a fei
  4. Module Hierarchy    : top function module
  5. Design Name         : vga_module.v
  6. Module Name         : vga_module
  7. Project Name        : test_project_top.qsf
  8. Target Devices      : Altera
  9. Tool versions       : QUARTUSII11.0/Windows XP
  10. Description         : 显示“囧”字,绿背景,蓝框,800*600@60Hz
  11. Dependencies        :                       
  12. Revision            : 0.01 - File Created
  13. Additional Comments : modify the pixer to 800X600@72Hz
  14. ==============================================================================*/
  15. module vga_module(
  16.         input                 i_fpga_clk        ,        //50MHz
  17.         input                 i_rst_n                        ,        //低电平复位
  18.                        
  19.         output                 o_vga_red                ,
  20.         output                 o_vga_green        ,
  21.         output                 o_vga_blue        ,
  22.         output                 o_vga_hsync        ,        //行同步信号
  23.         output                 o_vga_vsync                //场同步信号
  24. );

  25. //================================================================================
  26. // 4、Wire and reg declaration
  27. //================================================================================
  28.         reg[9:0] r_x_cnt;        //行坐标(这里包括了行同步、后沿、有效数据区、前沿)
  29.         reg[9:0] r_y_cnt;        //列坐标(这里包括了场同步、后沿、有效数据区、前沿)
  30. always @ (posedge i_fpga_clk or negedge i_rst_n)
  31.         if(!i_rst_n)
  32.                 r_x_cnt <= 10'd0;
  33.         else if(r_x_cnt == 10'd1000)
  34.                 r_x_cnt <= 10'd0;                //行计数只记到1000
  35.         else
  36.                 r_x_cnt <= r_x_cnt+1'b1;

  37. always @ (posedge i_fpga_clk or negedge i_rst_n)
  38.         if(!i_rst_n)
  39.                 r_y_cnt <= 10'd0;
  40.         else if(r_y_cnt == 10'd665)
  41.                 r_y_cnt <= 10'd0;                //场同步只记到665
  42.         else if(r_x_cnt == 10'd1000)
  43.                 r_y_cnt <= r_y_cnt+1'b1;//每计数完一行,场同步就加一
  44.         else
  45.                 r_y_cnt <= r_y_cnt;
  46.                
  47. //================================================================================
  48. // 4、Wire and reg declaration
  49. //================================================================================
  50.         wire w_vga_valid;        //有效数据显示区标志,当坐标不处于有效显示区时,R、G、B三原色信号接的电平都必须拉底(0)*/
  51. assign w_vga_valid = (r_x_cnt > 10'd180) && (r_x_cnt < 10'd980) //800*600
  52.                                         && (r_y_cnt > 10'd35) && (r_y_cnt < 10'd635);

  53.         wire        [9:0] w_x_pos;
  54.         wire        [9:0]        w_y_pos;        //有效显示区坐标
  55. assign w_x_pos = r_x_cnt-10'd180;//
  56. assign w_y_pos = r_y_cnt-10'd35;//

  57.         reg         r_vga_hsync;
  58.         reg                r_vga_vsync;
  59. always @ (posedge i_fpga_clk or negedge i_rst_n)
  60.   if (!i_rst_n)
  61.           begin
  62.                         r_vga_hsync <= 1'b0;
  63.              r_vga_vsync <= 1'b0;
  64.      end
  65.   else
  66.           begin
  67.              r_vga_hsync <= r_x_cnt <= 10'd50;  //产生hsync信号(行同步)0-50
  68.              r_vga_vsync <= r_y_cnt <= 10'd6;   //产生vsync信号(场同步)0-6
  69.     end

  70. //================================================================================
  71. // 4、Wire and reg declaration
  72. //================================================================================
  73.         //显示一个矩形框
  74.         wire a_dis,b_dis,c_dis,d_dis;        //矩形框显示区域定位
  75. assign a_dis = ( (w_x_pos>=200) && (w_x_pos<=220) )
  76.                                 &&        ( (w_y_pos>=140) && (w_y_pos<=460) );                               
  77. assign b_dis = ( (w_x_pos>=580) && (w_x_pos<=600) )
  78.                                 && ( (w_y_pos>=140) && (w_y_pos<=460) );
  79. assign c_dis = ( (w_x_pos>=220) && (w_x_pos<=580) )
  80.                                 &&        ( (w_y_pos>140)  && (w_y_pos<=160) );                               
  81. assign d_dis = ( (w_x_pos>=220) && (w_x_pos<=580) )
  82.                                 && ( (w_y_pos>=440) && (w_y_pos<=460) );

  83.         wire e_dis,f_dis,g_dis,h_dis;        //矩形框显示区域定位
  84. assign e_dis = ( (w_x_pos>=320) && (w_x_pos<=340) )
  85.                                 &&        ( (w_y_pos>=320) && (w_y_pos<=410) );                               
  86. assign f_dis = ( (w_x_pos>=460) && (w_x_pos<=480) )
  87.                                 && ( (w_y_pos>=320) && (w_y_pos<=410) );
  88. assign g_dis = ( (w_x_pos>=340) && (w_x_pos<=460) )
  89.                                 &&        ( (w_y_pos>320)  && (w_y_pos<=340) );                               
  90. assign h_dis = ( (w_x_pos>=340) && (w_x_pos<=460) )
  91.                                 && ( (w_y_pos>=390) && (w_y_pos<=410) );

  92.         wire i_dis,j_dis,k_dis,l_dis;
  93. assign i_dis = ( (w_x_pos>=320) && (w_x_pos<=340) )
  94.                                 &&        ( (w_y_pos>=210) && (w_y_pos<=290) );                               
  95. assign j_dis = ( (w_x_pos>=460) && (w_x_pos<=480) )
  96.                                 && ( (w_y_pos>=210) && (w_y_pos<=290) );
  97. assign k_dis = ( (w_x_pos>=270) && (w_x_pos<=320) )
  98.                                 &&        ( (w_y_pos>270)  && (w_y_pos<=290) );                               
  99. assign l_dis = ( (w_x_pos>=480) && (w_x_pos<=530) )
  100.                                 && ( (w_y_pos>=270) && (w_y_pos<=290) );

  101. //================================================================================
  102. // 2、output                                                                  
  103. //================================================================================

  104.         assign o_vga_red = w_vga_valid ?        (i_dis | j_dis | k_dis | l_dis): 1'b0;
  105.         assign o_vga_blue = w_vga_valid ?  (a_dis | b_dis | c_dis | d_dis | e_dis | f_dis | g_dis | h_dis ) : 1'b0;
  106.         assign o_vga_green = w_vga_valid ? ~(a_dis | b_dis | c_dis | d_dis | e_dis | f_dis | g_dis | h_dis | i_dis | j_dis | k_dis | l_dis) : 1'b0;          
  107.         assign o_vga_vsync = r_vga_vsync ;
  108.         assign o_vga_hsync = r_vga_hsync ;
  109.        
  110. //================================================================================
  111. endmodule
复制代码

全部资料51hei下载地址:
M20_VGA display.zip (4.48 MB, 下载次数: 64)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表