Advertisement
dar-io-g

VGA_TEXT.v

Oct 19th, 2017
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `define SPACE 0
  2. `define DOT 1
  3. `define SCORE 2
  4. `define UNDERSCORE 3
  5. `define COLON 4
  6. `define A 15
  7. `define B 16
  8. `define C 17
  9. `define D 18
  10. `define E 19
  11. `define F 20
  12. `define G 21
  13. `define H 22
  14. `define I 23
  15. `define J 24
  16. `define K 25
  17. `define L 26
  18. `define M 27
  19. `define N 28
  20. `define O 29
  21. `define P 30
  22. `define Q 31
  23. `define R 32
  24. `define S 33
  25. `define T 34
  26. `define U 35
  27. `define V 36
  28. `define W 37
  29. `define X 38
  30. `define Y 39
  31. `define Z 40
  32. //=======================================================
  33. //  This code is generated by Terasic System Builder
  34. //=======================================================
  35.  
  36. module VGA_TEXT(
  37.  
  38.     //////////// CLOCK //////////
  39.     input                       ADC_CLK_10,
  40.     input                       MAX10_CLK1_50,
  41.     input                       MAX10_CLK2_50,
  42.  
  43.     //////////// SDRAM //////////
  44.     output          [12:0]      DRAM_ADDR,
  45.     output           [1:0]      DRAM_BA,
  46.     output                      DRAM_CAS_N,
  47.     output                      DRAM_CKE,
  48.     output                      DRAM_CLK,
  49.     output                      DRAM_CS_N,
  50.     inout           [15:0]      DRAM_DQ,
  51.     output                      DRAM_LDQM,
  52.     output                      DRAM_RAS_N,
  53.     output                      DRAM_UDQM,
  54.     output                      DRAM_WE_N,
  55.  
  56.     //////////// SEG7 //////////
  57.     output           [7:0]      HEX0,
  58.     output           [7:0]      HEX1,
  59.     output           [7:0]      HEX2,
  60.     output           [7:0]      HEX3,
  61.     output           [7:0]      HEX4,
  62.     output           [7:0]      HEX5,
  63.  
  64.     //////////// KEY //////////
  65.     input            [1:0]      KEY,
  66.  
  67.     //////////// LED //////////
  68.     output           [9:0]      LEDR,
  69.  
  70.     //////////// SW //////////
  71.     input            [9:0]      SW,
  72.  
  73.     //////////// VGA //////////
  74.     output           [3:0]      VGA_B,
  75.     output           [3:0]      VGA_G,
  76.     output                      VGA_HS,
  77.     output           [3:0]      VGA_R,
  78.     output                      VGA_VS,
  79.  
  80.     //////////// Accelerometer //////////
  81.     output                      GSENSOR_CS_N,
  82.     input            [2:1]      GSENSOR_INT,
  83.     output                      GSENSOR_SCLK,
  84.     inout                       GSENSOR_SDI,
  85.     inout                       GSENSOR_SDO,
  86.  
  87.     //////////// Arduino //////////
  88.     inout           [15:0]      ARDUINO_IO,
  89.     inout                       ARDUINO_RESET_N,
  90.  
  91.     //////////// GPIO, GPIO connect to GPIO Default //////////
  92.     inout           [35:0]      IOGPIO
  93. );
  94.  
  95.  
  96. //=======================================================
  97. //  REG/WIRE declarations
  98. //=======================================================
  99.  
  100. wire c0, c1, c2, c3;
  101. VGA_PLL vga_clk(MAX10_CLK1_50, c0, c1, c2, c3);//, phase: 0°, 90°, 180° 270°
  102.  
  103. reg [20:0] count;
  104. reg [10:0] currentLine;
  105. reg [10:0] currentColumn;
  106. reg [10:0] x;
  107. reg [10:0] y;
  108.  
  109. reg [5:0] carattere;
  110. reg [2:0] size; //dimensione testo
  111.  
  112. reg [7:0]R_val;
  113. reg [7:0]G_val;
  114. reg [7:0]B_val;
  115.  
  116.  
  117.  
  118. //135MHz
  119. parameter Htime = 144;//41;     //clock
  120. parameter Vtime = 3;//10;       //lines
  121.  
  122. parameter VBporch = 38;//2; //lines
  123. parameter VFporch = 1;//2;  //lines
  124.  
  125. parameter HBporch = 248;//2;    //clk
  126. parameter HFporch = 16;//2; //clk
  127.  
  128. parameter columns = 1280;
  129. parameter lines = 1024;
  130.  
  131. parameter lineTime = (columns+HFporch+Htime+HBporch);   //th
  132. parameter totalFrame = lineTime*(lines+VFporch+Vtime+VBporch);
  133.  
  134. assign VGA_HS = ((currentColumn) > (columns+HFporch) && (currentColumn < (columns+HFporch+Htime)));//HSYNC_val;
  135. assign VGA_VS = ((currentLine) > (lines+VFporch) && (currentLine) < (lines+VFporch+Vtime));//VSYNC_val;
  136.  
  137. assign VGA_R[3:0] = R_val[3:0];
  138. assign VGA_G[3:0] = G_val[3:0];
  139. assign VGA_B[3:0] = B_val[3:0];
  140.  
  141. //tabella font
  142. //n righe, n elementi, n colonne
  143. reg [7:0] font [41][6] = '{
  144.     '{8'h00,8'h00,8'h00,8'h00,8'h00,8'h00}, //   //0
  145.     '{8'h30,8'h30,8'h00,8'h00,8'h00,8'h00}, // . //1
  146.     '{8'h08,8'h08,8'h08,8'h08,8'h08,8'h00}, // - //2
  147.     '{8'h40,8'h40,8'h40,8'h40,8'h40,8'h40}, // _    //3
  148.     '{8'h24,8'h00,8'h00,8'h00,8'h00,8'h00}, // : //4
  149.     '{8'h1e,8'h31,8'h29,8'h25,8'h23,8'h1e}, // 0 //5
  150.     '{8'h22,8'h21,8'h3f,8'h20,8'h20,8'h20}, // 1 //6
  151.     '{8'h32,8'h29,8'h29,8'h29,8'h29,8'h26}, // 2 //7
  152.     '{8'h12,8'h21,8'h21,8'h25,8'h25,8'h1a}, // 3 //8
  153.     '{8'h18,8'h14,8'h12,8'h3f,8'h10,8'h10}, // 4 //9
  154.     '{8'h17,8'h25,8'h25,8'h25,8'h25,8'h19}, // 5 //10
  155.     '{8'h1e,8'h25,8'h25,8'h25,8'h25,8'h18}, // 6 //11
  156.     '{8'h01,8'h01,8'h31,8'h09,8'h05,8'h03}, // 7 //12
  157.     '{8'h1a,8'h25,8'h25,8'h25,8'h25,8'h1a}, // 8 //13
  158.     '{8'h06,8'h29,8'h29,8'h29,8'h29,8'h1e}, // 9 //14
  159.     '{8'h3e,8'h09,8'h09,8'h09,8'h09,8'h3e}, // A //15
  160.     '{8'h3f,8'h25,8'h25,8'h25,8'h25,8'h1a}, // B //16
  161.     '{8'h1e,8'h21,8'h21,8'h21,8'h21,8'h12}, // C //17
  162.     '{8'h3f,8'h21,8'h21,8'h21,8'h12,8'h0c}, // D //18
  163.     '{8'h3f,8'h25,8'h25,8'h25,8'h25,8'h21}, // E //19
  164.     '{8'h3f,8'h05,8'h05,8'h05,8'h05,8'h01}, // F //20
  165.     '{8'h1e,8'h21,8'h21,8'h21,8'h29,8'h1a}, // G //21
  166.     '{8'h3f,8'h04,8'h04,8'h04,8'h04,8'h3f}, // H //22
  167.     '{8'h21,8'h21,8'h3f,8'h21,8'h21,8'h21}, // I //23
  168.     '{8'h10,8'h20,8'h20,8'h20,8'h20,8'h1f}, // J //24
  169.     '{8'h3f,8'h04,8'h0c,8'h0a,8'h11,8'h20}, // K //25
  170.     '{8'h3f,8'h20,8'h20,8'h20,8'h20,8'h20}, // L //26
  171.     '{8'h3f,8'h02,8'h04,8'h04,8'h02,8'h3f}, // M //27
  172.     '{8'h3f,8'h02,8'h04,8'h08,8'h10,8'h3f}, // N //28
  173.     '{8'h1e,8'h21,8'h21,8'h21,8'h21,8'h1e}, // O //29
  174.     '{8'h3f,8'h09,8'h09,8'h09,8'h09,8'h06}, // P //30
  175.     '{8'h1e,8'h21,8'h29,8'h31,8'h21,8'h1e}, // Q //31
  176.     '{8'h3f,8'h09,8'h09,8'h09,8'h19,8'h26}, // R //32
  177.     '{8'h12,8'h25,8'h25,8'h25,8'h25,8'h18}, // S //33
  178.     '{8'h01,8'h01,8'h01,8'h3f,8'h01,8'h01}, // T //34
  179.     '{8'h1f,8'h20,8'h20,8'h20,8'h20,8'h1f}, // U //35
  180.     '{8'h0f,8'h10,8'h20,8'h20,8'h10,8'h0f}, // V //36
  181.     '{8'h1f,8'h20,8'h10,8'h10,8'h20,8'h1f}, // W //37
  182.     '{8'h21,8'h12,8'h0c,8'h0c,8'h12,8'h21}, // X //38
  183.     '{8'h01,8'h02,8'h0c,8'h38,8'h04,8'h02}, // Y //39
  184.     '{8'h21,8'h31,8'h29,8'h25,8'h23,8'h21}  // Z //40
  185. };
  186.  
  187. //array che contiene le scritte
  188. reg [5:0] arrayChar [columns/6][lines/8]; //6 = larghezza font - 8 = altezza font (8 solo perchè è un byte, ne usiamo solo 6 di bit)
  189.  
  190. //=======================================================
  191. //  Structural coding
  192. //=======================================================
  193. reg [6:0]selectedChar;
  194. reg [8:0]colonna;
  195. reg [3:0]xChar;
  196. reg [3:0]yChar;
  197.  
  198. always @(posedge c0)
  199. begin
  200.     if (count < totalFrame)
  201.         count <= (count + 1'b1) % totalFrame;
  202.     else
  203.         count <= 0;
  204. end
  205.  
  206. always @(posedge c1)
  207. begin
  208.     currentColumn <= count%lineTime;
  209.     currentLine <= count/lineTime;
  210.    
  211. end
  212.  
  213. always @(posedge c2)
  214. begin
  215.     selectedChar <= currentColumn/(8*size);
  216.     colonna <= currentLine/(8*size);
  217.     xChar <= (currentColumn/size)%8-1;
  218.     yChar <= (currentLine/size)%8-1;
  219.    
  220. end
  221.  
  222.  
  223. always @(posedge c3)
  224. begin
  225.  
  226.     if ((currentLine) < lines && (currentColumn) < columns)
  227.     begin
  228.             if (font[arrayChar[selectedChar][colonna]][xChar][yChar])
  229.             begin
  230.                 R_val [7:0] <= 255;
  231.                 G_val [7:0] <= 255;
  232.                 B_val [7:0] <= 255;
  233.             end
  234.             else
  235.             begin //------
  236.                 R_val [7:0] <= 0;
  237.                 G_val [7:0] <= 0;
  238.                 B_val [7:0] <= 0;
  239.             end //------
  240.            
  241.     end
  242.     else
  243.     begin
  244.         R_val [7:0] <= 0;
  245.         G_val [7:0] <= 0;
  246.         B_val [7:0] <= 0;
  247.     end
  248.    
  249. end
  250.  
  251.  
  252.  
  253. always @(1)
  254. begin
  255.     size = 2;
  256.     arrayChar[1][1] <= `T;
  257.     arrayChar[2][1] <= `E;
  258.     arrayChar[3][1] <= `S;
  259.     arrayChar[4][1] <= `T;
  260.     arrayChar[5][1] <= `DOT;
  261.     arrayChar[6][1] <= `DOT;
  262.     arrayChar[7][1] <= `DOT;
  263.  
  264. end
  265.  
  266.  
  267.  
  268. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement