adolf01

Untitled

Jun 11th, 2020
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_unsigned.all;
  4.  
  5. entity VGA is
  6. port
  7. (
  8. CLK : in std_logic;
  9. RST : in std_logic := '1';
  10. HSYNC : OUT STD_logic;
  11. VSYNC : OUT std_logic;
  12. RGB : OUT std_logic_vector(2 downto 0);
  13. RGB_in : IN STD_logic_vector(2 downto 0);
  14. Reg_ADDR: OUT std_logic_vector(12 downto 0);
  15. Reg_DATA: IN STD_logic_vector(7 downto 0)
  16. );
  17.  
  18. end entity;
  19.  
  20. architecture Behavioral of VGA is
  21.  
  22. constant HD : integer := 799;
  23. constant HFP : integer := 40;
  24. constant HSP : integer := 128;
  25. constant HBP : integer := 88;
  26.  
  27. constant VD : integer := 599;
  28. constant VFP : integer := 1;
  29. constant VSP : integer := 4;
  30. constant VBP : integer := 23;
  31.  
  32. -- constant HD : integer := 319;
  33. -- constant HFP : integer := 8;
  34. -- constant HSP : integer := 32;
  35. -- constant HBP : integer := 40;
  36. --
  37. -- constant VD : integer := 199;
  38. -- constant VFP : integer := 3;
  39. -- constant VSP : integer := 6;
  40. -- constant VBP : integer := 6;
  41.  
  42. -- constant HD : integer := 639;
  43. -- constant HFP : integer := 16;
  44. -- constant HSP : integer := 96;
  45. -- constant HBP : integer := 48;
  46. --
  47. -- constant VD : integer := 479;
  48. -- constant VFP : integer := 10;
  49. -- constant VSP : integer := 2;
  50. -- constant VBP : integer := 33;
  51. constant W_x_size : integer:= 512;
  52. constant W_H_Start : integer:= ((HD - W_x_size)/2);
  53. constant W_y_size : integer:= 512;
  54. constant W_V_Start : integer:= ((VD - W_y_size)/2);
  55.  
  56. signal hPos : integer :=0;
  57. signal vPos : integer :=0;
  58. signal video_on:std_logic:='0';
  59. signal clk25 : std_logic;
  60.  
  61.  
  62. begin
  63.  
  64.  
  65. clk_div:process(CLK)
  66. begin
  67. -- if rising_edge(clk25) then
  68. -- clk25 <= not clk25;
  69. -- end if;
  70.  
  71. end process;
  72.  
  73. clk25 <= CLK;
  74.  
  75. Hor_pos_cnt:process(clk25,RST)
  76. begin
  77. if (RST = '0') then
  78. hPos <= 0;
  79. elsif rising_edge(clk25) then
  80. if (hPos = (HD + HFP + HSP + HBP))then
  81. hPos <= 0;
  82. else
  83. hPos <= hPos +1;
  84. end if;
  85. end if;
  86. end process;
  87.  
  88.  
  89. Ver_pos_cnt:process(clk25,RST, hPos)
  90. begin
  91. if (RST = '0') then
  92. vPos <= 0;
  93. elsif rising_edge(clk25) then
  94. if(hPos = (HD + HFP + HSP + HBP))then
  95. if (vPos = (VD + VFP + VSP + VBP))then
  96. vPos <= 0;
  97. else
  98. vPos <= vPos +1;
  99. end if;
  100. end if;
  101. end if;
  102. end process;
  103.  
  104. Hor_sync:process(clk25,RST,hPos)
  105. begin
  106. if (RST = '0') then
  107. HSYNC <= '0';
  108. elsif rising_edge(clk25) then
  109. if(hPos <= (HD + HFP) OR hPos >= (HD + HFP + HSP))then
  110. HSYNC <= '1';
  111. else
  112. HSYNC <= '0';
  113. end if;
  114. end if;
  115. end process;
  116.  
  117. Ver_sync:process(clk25,RST,vPos)
  118. begin
  119. if (RST = '0') then
  120. VSYNC <= '0';
  121. elsif rising_edge(clk25) then
  122. if(vPos <= (VD + VFP) OR vPos >= (VD + VFP + VSP))then
  123. VSYNC <= '1';
  124. else
  125. VSYNC <= '0';
  126. end if;
  127. end if;
  128. end process;
  129.  
  130. videoOn:process(clk25,RST,hPos,vPos)
  131. begin
  132. if (RST = '0') then
  133. video_on <= '0';
  134. elsif rising_edge(clk25) then
  135. if(hPos <= HD AND vPos <= VD)then
  136. video_on <= '1';
  137. else
  138. video_on <= '0';
  139. end if;
  140. end if;
  141. end process;
  142.  
  143.  
  144. draw:process(clk25, RST, hPos, vPos, video_on,RGB_in)
  145. begin
  146. if(RST = '0')then
  147. RGB <= "000";
  148. elsif rising_edge(clk25) then
  149. if(video_on = '1')then
  150. if((hPos >= W_H_Start and hPos <= (W_H_Start + W_X_size)) AND (vPos >= W_V_Start and vPos <= (W_V_Start + W_y_size)))then
  151. --RGB <= "001";
  152. RGB <= RGB_in;
  153. else
  154. RGB <= "000";
  155. end if;
  156. else
  157. RGB <= "000";
  158. end if;
  159. end if;
  160. end process;
  161.  
  162.  
  163.  
  164. draw_text:process(clk25,RST,hPos,vPos,video_on)
  165. begin
  166. if (RST = '0')then
  167.  
  168. elsif rising_edge(clk25)then
  169. if (video_on = '1')then
  170. Reg_ADDR <= hPos /8;
  171. end if;
  172. end if;
  173. end process;
  174.  
  175.  
  176.  
  177.  
  178. -- Red_Line:process(CLK,vPos,hPos,video_on,RST)
  179. -- begin
  180. -- if (RST = '0') then
  181. -- RGB <= "000";
  182. -- elsif rising_edge(CLK) then
  183. -- if (video_on = '1') then
  184. -- if (hPos >=300 and hPos <= 600)then
  185. -- if(vPos >=100 and vPos <= 400)then
  186. -- RGB <= "111";
  187. -- else
  188. -- RGB <= "000";
  189. -- end if;
  190. -- end if;
  191. --
  192. --
  193. -- else
  194. -- RGB <= "000";
  195. -- end if;
  196. -- end if;
  197. -- end process;
  198.  
  199. end Behavioral;
Add Comment
Please, Sign In to add comment