Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.35 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 14:06:57 01/27/2020
  6. -- Design Name:
  7. -- Module Name: bitmap - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.STD_LOGIC_ARITH.ALL;
  23. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  24.  
  25. ---- Uncomment the following library declaration if instantiating
  26. ---- any Xilinx primitives in this code.
  27. --library UNISIM;
  28. --use UNISIM.VComponents.all;
  29.  
  30. entity bitmap is
  31. Port ( SYS_CLK : in STD_LOGIC; --Horloge du gestionnaire de la souris
  32. DATA : in STD_LOGIC; --Données de la souris
  33. X : out STD_LOGIC_VECTOR (7 downto 0); --Déplacement de la souris
  34. Y : out STD_LOGIC_VECTOR (7 downto 0); --Déplacement de la souris
  35. CLK : in STD_LOGIC; --Horloge de la souris
  36. COLOR : out STD_LOGIC_VECTOR (1 downto 0); --Définie si on est en écriture/suppression ou rien du tout
  37. W : out STD_LOGIC); --Verifier que tout est valide
  38. end bitmap;
  39.  
  40. architecture Behavioral of bitmap is
  41.  
  42. --Signaux intérmédiaires que l'on va utiliser:
  43. signal XX : STD_LOGIC_VECTOR (7 downto 0);
  44. signal YY : STD_LOGIC_VECTOR (7 downto 0);
  45. signal CCOLOR : STD_LOGIC_VECTOR (1 downto 0);
  46. signal dirX, dirY : STD_LOGIC;
  47. signal prevState : STD_LOGIC :='0';
  48. signal WW : STD_LOGIC :='0';
  49. signal Err : STD_LOGIC :='0';
  50.  
  51. --Déclaration des états
  52. type sysState is (waitingControl, control, waitingMovX, movX, waitingMovY, movY, endState);
  53. signal actualState : sysState := waitingControl;
  54. signal positionCounter : integer range 0 to 9;
  55.  
  56. begin
  57.  
  58.  
  59. process(SYS_CLK)
  60.  
  61. variable i : integer := 0;
  62. variable Xcomp : STD_LOGIC_VECTOR (7 downto 0) := "00000000";
  63. variable Ycomp : STD_LOGIC_VECTOR (7 downto 0) := "00000000";
  64.  
  65. begin
  66. if(rising_edge(SYS_CLK)) then
  67. if(WW = '1' and Err = '0') then
  68.  
  69. --Ecriture de la couleur
  70. COLOR <= CCOLOR;
  71.  
  72. --Calcul de X
  73. Xcomp := XX;
  74. if(Xcomp(7)='1')then
  75. Xcomp(6 downto 0) := "1111111";
  76. end if;
  77. Xcomp(7) := '0';
  78.  
  79. if(dirX = '0') then
  80. Xcomp := not Xcomp;
  81. Xcomp := Xcomp + "00000001";
  82. end if;
  83.  
  84. --Calcul de Y
  85. Ycomp := YY;
  86. if(Ycomp(7)='1')then
  87. Ycomp(6 downto 0) := "1111111";
  88. end if;
  89. Ycomp(7) := '0';
  90.  
  91. if(dirY = '0') then
  92. Ycomp := not Ycomp;
  93. Ycomp := Ycomp + "00000001";
  94. end if;
  95.  
  96. --Ecriture de X et de Y et indication de W
  97. Y<=Ycomp;
  98. X<=Xcomp;
  99. W<='1';
  100.  
  101. else
  102. --Reinitialisation de W
  103. W<='0';
  104. end if;
  105. end if;
  106. end process;
  107.  
  108. --Conversion des datas lignes en data colonnes pour les variables temporaires
  109.  
  110. process(CLK)
  111.  
  112. variable parity : STD_LOGIC;
  113.  
  114. begin
  115.  
  116. --Detection du front montant de l'horloge
  117. if(rising_edge(CLK)) then
  118.  
  119. --Détection du bit de start et changement d'état
  120. if(prevState = '1' and DATA='0') then
  121. if(actualState=waitingControl) then
  122. CCOLOR<="00";
  123. actualState<=control;
  124. positionCounter <= 1;
  125.  
  126. elsif(actualState=waitingMovX) then
  127. actualState<=movX;
  128. positionCounter <= 1;
  129.  
  130. elsif(actualState=waitingMovY) then
  131. actualState<=movY;
  132. positionCounter <= 1;
  133. end if;
  134.  
  135. elsif(DATA = '1') then
  136. prevState<='1';
  137. end if;
  138.  
  139. --Raz
  140. if(actualState=endState) then
  141. actualState<=waitingControl;
  142. Err<='0';
  143. WW <= '0';
  144. end if;
  145.  
  146. --Cas de la lecture des boutons de la souris
  147. if(actualState = control) then
  148. case(positionCounter) is
  149. when 0 =>
  150. when 1 =>
  151. if(DATA='1') then
  152. CCOLOR <="11";
  153. end if;
  154. parity:=DATA;
  155. when 2 =>
  156. if(CCOLOR = "11") then
  157. else
  158. if(DATA = '1') then
  159. CCOLOR <= "10";
  160. else
  161. CCOLOR <= "00";
  162. end if;
  163. end if;
  164. parity:=parity xor DATA;
  165. when 3 => parity:=parity xor DATA;
  166. when 4 => parity:=parity xor DATA;
  167. when 5 =>
  168. if(DATA = '1') then
  169. dirX<='1';
  170. else
  171. dirX<='0';
  172. end if;
  173. parity:=parity xor DATA;
  174. when 6 =>
  175. if(DATA = '1') then
  176. dirY<='1';
  177. else
  178. dirY<='0';
  179. end if;
  180. parity:=parity xor DATA;
  181. when 7 => parity:=parity xor DATA;
  182. when 8 => parity:=parity xor DATA;
  183. when 9 =>
  184. parity :=parity xor DATA;
  185. if(parity = '0') then
  186. Err<='1';
  187. end if;
  188. actualState<=waitingMovX;
  189. prevState<='0';
  190. end case;
  191.  
  192. --Cas du déplacement de la souris dans l'axe X
  193. elsif(actualState = movX) then
  194.  
  195. if(positionCounter >= 1 and positionCounter <=8) then
  196. XX(positionCounter-1)<=DATA;
  197. if(positionCounter = 1) then
  198. parity:= DATA;
  199. else
  200. parity := parity xor DATA;
  201. end if;
  202. elsif(positionCounter = 9) then
  203. parity:= parity xor DATA;
  204. if(parity = '0') then
  205. Err<='1';
  206. end if;
  207. actualState<=waitingMovY;
  208. prevState<='0';
  209. end if;
  210.  
  211. --Cas du déplacement de la souris dans l'axe Y
  212. elsif(actualState = movY) then
  213.  
  214. if(positionCounter >= 1 and positionCounter <=8) then
  215. YY(positionCounter-1)<=DATA;
  216. if(positionCounter = 1) then
  217. parity:= DATA;
  218. else
  219. parity := parity xor DATA;
  220. end if;
  221. elsif(positionCounter = 9) then
  222. parity:= parity xor DATA;
  223. if(parity = '0') then
  224. Err<='1';
  225. end if;
  226. actualState<=endState;
  227. prevState<='0';
  228. WW <= '1';
  229. end if;
  230.  
  231. end if;
  232.  
  233. --Incrémentation du compteur
  234. if(actualState = control or actualState = movX or actualState = movY) then
  235. if(positionCounter<9) then
  236. positionCounter <= positionCounter+1;
  237. else
  238. positionCounter<=0;
  239. end if;
  240. end if;
  241.  
  242. end if;
  243.  
  244. end process;
  245.  
  246. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement