⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shinningblock.vhd

📁 FPGA的串口通信程序
💻 VHD
字号:
LIBRARY ieee ;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.ALL;

ENTITY shinningblock IS PORT
( 
  clk    : IN std_logic;
  vcount : IN std_logic_vector(11 DOWNTO 0);
  hcount : IN std_logic_vector(10 DOWNTO 0);
  clken_fcount: IN std_logic;
  mode   : IN std_logic;
  outsel : IN std_logic;
  startin: IN std_logic; 
  refresh: IN std_logic_vector(1  DOWNTO 0);
  time1  : IN std_logic_vector(3  DOWNTO 0);
  time2  : IN std_logic_vector(3  DOWNTO 0);
  time3  : IN std_logic_vector(3  DOWNTO 0);
  level1 : IN std_logic_vector(7  DOWNTO 0);
  level2 : IN std_logic_vector(7  DOWNTO 0);
  level3 : IN std_logic_vector(7  DOWNTO 0);
  size   : IN std_logic_vector(3  DOWNTO 0);
  pos    : IN std_logic_vector(3  DOWNTO 0);
  trigger: OUT std_logic;
  out_r_e: OUT std_logic_vector(7 DOWNTO 0);
  out_g_e: OUT std_logic_vector(7 DOWNTO 0);
  out_b_e: OUT std_logic_vector(7 DOWNTO 0);
  out_r_o: OUT std_logic_vector(7 DOWNTO 0);
  out_g_o: OUT std_logic_vector(7 DOWNTO 0);
  out_b_o: OUT std_logic_vector(7 DOWNTO 0)
);

CONSTANT HAC:integer:=640;   -- horizontal active pixels 1448*1151
CONSTANT HSY:integer:=20;     -- horizontal sync width (negative polarity)
CONSTANT HBP:integer:=20;     -- horizontal back porch
CONSTANT VAC:integer:=1024;    -- vertical active pixels
CONSTANT VSY:integer:=25;      -- vertical sync width (negative polarity)
CONSTANT VBP:integer:=25;     -- vertical back porch

END shinningblock;

ARCHITECTURE rtl OF shinningblock IS

SIGNAL inter1,inter2,inter3,hsize,count : integer;
SIGNAL xpos,ypos:integer;
SIGNAL color,color1 : std_logic;
SIGNAL count1,count2,count3 : std_logic_vector(6 DOWNTO 0);
TYPE state_type IS (tristate,state1,state2,state3);
SIGNAL state: state_type;
SIGNAL out1_r_e    :   std_logic_vector(7 DOWNTO 0);
SIGNAL out1_g_e    :   std_logic_vector(7 DOWNTO 0);
SIGNAL out1_b_e    :   std_logic_vector(7 DOWNTO 0);
SIGNAL out1_r_o    :   std_logic_vector(7 DOWNTO 0);
SIGNAL out1_g_o    :   std_logic_vector(7 DOWNTO 0);
SIGNAL out1_b_o    :   std_logic_vector(7 DOWNTO 0);
SIGNAL out2_r_e    :   std_logic_vector(7 DOWNTO 0);
SIGNAL out2_g_e    :   std_logic_vector(7 DOWNTO 0);
SIGNAL out2_b_e    :   std_logic_vector(7 DOWNTO 0);
SIGNAL out2_r_o    :   std_logic_vector(7 DOWNTO 0);
SIGNAL out2_g_o    :   std_logic_vector(7 DOWNTO 0);
SIGNAL out2_b_o    :   std_logic_vector(7 DOWNTO 0);

BEGIN

PROCESS(time1,refresh)		--图像维持时间
BEGIN
CASE time1&refresh IS
	WHEN  "000000"=>inter1<=0;
	WHEN  "000100"=>inter1<=1;
	WHEN  "001000"=>inter1<=6;
    WHEN  "001100"=>inter1<=12;
    WHEN  "010000"=>inter1<=18;
    WHEN  "010100"=>inter1<=24;
    WHEN  "011000"=>inter1<=30;
    WHEN  "011100"=>inter1<=36;
    WHEN  "100000"=>inter1<=42;
    WHEN  "100100"=>inter1<=48;
    WHEN  "101000"=>inter1<=54;
    WHEN  "101100"=>inter1<=60;
    WHEN  "000001"=>inter1<=0;
	WHEN  "000101"=>inter1<=1;
	WHEN  "001001"=>inter1<=5;
    WHEN  "001101"=>inter1<=10;
    WHEN  "010001"=>inter1<=15;
    WHEN  "010101"=>inter1<=20;
    WHEN  "011001"=>inter1<=25;
    WHEN  "011101"=>inter1<=30;
    WHEN  "100001"=>inter1<=35;
    WHEN  "100101"=>inter1<=40;
    WHEN  "101001"=>inter1<=45;
    WHEN  "101101"=>inter1<=50;
    WHEN  "000010"=>inter1<=0;
	WHEN  "000110"=>inter1<=1;
	WHEN  "001010"=>inter1<=7;
    WHEN  "001110"=>inter1<=14;
    WHEN  "010010"=>inter1<=21;
    WHEN  "010110"=>inter1<=28;
    WHEN  "011010"=>inter1<=35;
    WHEN  "011110"=>inter1<=42;
    WHEN  "100010"=>inter1<=49;
    WHEN  "100110"=>inter1<=56;
    WHEN  "101010"=>inter1<=63;
    WHEN  "101110"=>inter1<=70;
	WHEN  OTHERS =>inter1<=0;
END CASE;
END PROCESS;

PROCESS(time2,refresh)
BEGIN
CASE time2&refresh IS
	WHEN  "000000"=>inter2<=0;
	WHEN  "000100"=>inter2<=1;
	WHEN  "001000"=>inter2<=6;
    WHEN  "001100"=>inter2<=12;
    WHEN  "010000"=>inter2<=18;
    WHEN  "010100"=>inter2<=24;
    WHEN  "011000"=>inter2<=30;
    WHEN  "011100"=>inter2<=36;
    WHEN  "100000"=>inter2<=42;
    WHEN  "100100"=>inter2<=48;
    WHEN  "101000"=>inter2<=54;
    WHEN  "101100"=>inter2<=60;
    WHEN  "000001"=>inter2<=0;
	WHEN  "000101"=>inter2<=1;
	WHEN  "001001"=>inter2<=5;
    WHEN  "001101"=>inter2<=10;
    WHEN  "010001"=>inter2<=15;
    WHEN  "010101"=>inter2<=20;
    WHEN  "011001"=>inter2<=25;
    WHEN  "011101"=>inter2<=30;
    WHEN  "100001"=>inter2<=35;
    WHEN  "100101"=>inter2<=40;
    WHEN  "101001"=>inter2<=45;
    WHEN  "101101"=>inter2<=50;
    WHEN  "000010"=>inter2<=0;
	WHEN  "000110"=>inter2<=1;
	WHEN  "001010"=>inter2<=7;
    WHEN  "001110"=>inter2<=14;
    WHEN  "010010"=>inter2<=21;
    WHEN  "010110"=>inter2<=28;
    WHEN  "011010"=>inter2<=35;
    WHEN  "011110"=>inter2<=42;
    WHEN  "100010"=>inter2<=49;
    WHEN  "100110"=>inter2<=56;
    WHEN  "101010"=>inter2<=63;
    WHEN  "101110"=>inter2<=70;
	WHEN  OTHERS =>inter2<=0;
END CASE;
END PROCESS;

PROCESS(time3,refresh)
BEGIN
CASE time3&refresh IS
	WHEN  "000000"=>inter3<=0;
	WHEN  "000100"=>inter3<=1;
	WHEN  "001000"=>inter3<=6;
    WHEN  "001100"=>inter3<=12;
    WHEN  "010000"=>inter3<=18;
    WHEN  "010100"=>inter3<=24;
    WHEN  "011000"=>inter3<=30;
    WHEN  "011100"=>inter3<=36;
    WHEN  "100000"=>inter3<=42;
    WHEN  "100100"=>inter3<=48;
    WHEN  "101000"=>inter3<=54;
    WHEN  "101100"=>inter3<=60;
    WHEN  "000001"=>inter3<=0;
	WHEN  "000101"=>inter3<=1;
	WHEN  "001001"=>inter3<=5;
    WHEN  "001101"=>inter3<=10;
    WHEN  "010001"=>inter3<=15;
    WHEN  "010101"=>inter3<=20;
    WHEN  "011001"=>inter3<=25;
    WHEN  "011101"=>inter3<=30;
    WHEN  "100001"=>inter3<=35;
    WHEN  "100101"=>inter3<=40;
    WHEN  "101001"=>inter3<=45;
    WHEN  "101101"=>inter3<=50;
    WHEN  "000010"=>inter3<=0;
	WHEN  "000110"=>inter3<=1;
	WHEN  "001010"=>inter3<=7;
    WHEN  "001110"=>inter3<=14;
    WHEN  "010010"=>inter3<=21;
    WHEN  "010110"=>inter3<=28;
    WHEN  "011010"=>inter3<=35;
    WHEN  "011110"=>inter3<=42;
    WHEN  "100010"=>inter3<=49;
    WHEN  "100110"=>inter3<=56;
    WHEN  "101010"=>inter3<=63;
    WHEN  "101110"=>inter3<=70;
	WHEN  OTHERS =>inter3<=0;
END CASE;
END PROCESS;

PROCESS(size)
BEGIN
CASE size IS				--图像尺寸确定
	WHEN  "0000"=>hsize<=1;
	WHEN  "0001"=>hsize<=2;
	WHEN  "0010"=>hsize<=3;
    WHEN  "0011"=>hsize<=4;
    WHEN  "0100"=>hsize<=5;
    WHEN  "0101"=>hsize<=6;
    WHEN  "0110"=>hsize<=7;
    WHEN  "0111"=>hsize<=10;
    WHEN  "1000"=>hsize<=15;
    WHEN  "1001"=>hsize<=20;
    WHEN  "1010"=>hsize<=25;
    WHEN  "1011"=>hsize<=38;
	WHEN  "1100"=>hsize<=50;
	WHEN  "1101"=>hsize<=63;
	WHEN  "1110"=>hsize<=75;
	WHEN  "1111"=>hsize<=80;
END CASE;
END PROCESS;

process(pos)
begin 
case pos is					--图像位置确定
   when "0000"=>xpos<=75;
                ypos<=112;
   when "0001"=>xpos<=95;
                ypos<=152;
   when "0010"=>xpos<=120;
                ypos<=192;
   when "0011"=>xpos<=145;
                ypos<=232;
   when "0100"=>xpos<=170;
                ypos<=272;
   when "0101"=>xpos<=195;
                ypos<=312;
   when "0110"=>xpos<=220;
                ypos<=352;
   when "0111"=>xpos<=245;
                ypos<=392;
   when "1000"=>xpos<=270;
                ypos<=432;
   when "1001"=>xpos<=295;
                ypos<=472;
   when others=>xpos<=75;
                ypos<=112;
end case;
end process;

state_machine: PROCESS(clk,startin)
BEGIN
IF startin='0' THEN
count1<=(OTHERS=>'0');
count2<=(OTHERS=>'0');
count3<=(OTHERS=>'0');
state<=tristate;
ELSIF clk'event AND clk='1' THEN
CASE state IS

WHEN tristate=>
IF count=5000000 then 
count<=0;
state<=state1;
trigger<='0';
ELSE
trigger<='1';
count<=count+1;
state<=tristate;
END IF;


WHEN state1=>
IF count1=inter1 then 
count1<=(OTHERS=>'0');
state<=state2;
ELSIF clken_fcount='1' THEN
count1<=count1+1;
state<=state1;
END IF;

WHEN state2=>
IF count2=inter2 then 
count2<=(OTHERS=>'0');
state<=state3;
ELSIF clken_fcount='1' THEN
count2<=count2+1;
state<=state2;
END IF;

WHEN state3=>
IF count3=inter3 and mode='1' then 
count3<=(OTHERS=>'0');
state<=tristate;
ELSIF clken_fcount='1' THEN
count3<=count3+1;
state<=state3;
END IF;

WHEN others=>
state<=tristate;
END CASE;
END IF;
END PROCESS;

output:PROCESS(clk)
BEGIN
IF clk'event AND clk='1' THEN
CASE state IS

WHEN state1=>
IF color='1' THEN
out1_r_e<=level1; 
out1_g_e<=level1;  
out1_b_e<=level1;  
out1_r_o<=level1;  
out1_g_o<=level1;  
out1_b_o<=level1;
ELSE 
out1_r_e<=(OTHERS=>'0');
out1_g_e<=(OTHERS=>'0');
out1_b_e<=(OTHERS=>'0'); 
out1_r_o<=(OTHERS=>'0'); 
out1_g_o<=(OTHERS=>'0');
out1_b_o<=(OTHERS=>'0');
END IF;

WHEN state2=>
IF color='1' THEN 
out1_r_e<=level2; 
out1_g_e<=level2;  
out1_b_e<=level2;  
out1_r_o<=level2;  
out1_g_o<=level2;  
out1_b_o<=level2;
ELSE 
out1_r_e<=(OTHERS=>'0');
out1_g_e<=(OTHERS=>'0');
out1_b_e<=(OTHERS=>'0'); 
out1_r_o<=(OTHERS=>'0'); 
out1_g_o<=(OTHERS=>'0');
out1_b_o<=(OTHERS=>'0');
END IF;

WHEN state3=>
IF color='1' THEN 
out1_r_e<=level3; 
out1_g_e<=level3;  
out1_b_e<=level3;  
out1_r_o<=level3;  
out1_g_o<=level3;  
out1_b_o<=level3;
ELSE 
out1_r_e<=(OTHERS=>'0');
out1_g_e<=(OTHERS=>'0');
out1_b_e<=(OTHERS=>'0'); 
out1_r_o<=(OTHERS=>'0'); 
out1_g_o<=(OTHERS=>'0');
out1_b_o<=(OTHERS=>'0');
END IF;

WHEN others=>
IF color='1' THEN
out1_r_e<=level1; 
out1_g_e<=level1;  
out1_b_e<=level1;  
out1_r_o<=level1;  
out1_g_o<=level1;  
out1_b_o<=level1;
ELSE 
out1_r_e<=(OTHERS=>'0');
out1_g_e<=(OTHERS=>'0');
out1_b_e<=(OTHERS=>'0'); 
out1_r_o<=(OTHERS=>'0'); 
out1_g_o<=(OTHERS=>'0');
out1_b_o<=(OTHERS=>'0');
END IF;
END case;
END IF;
END PROCESS;

output1:PROCESS(clk)
BEGIN
IF clk'event AND clk='1' THEN
CASE state IS

WHEN state1=>
IF color1='1' THEN
out2_r_e<=level1; 
out2_g_e<=level1;  
out2_b_e<=level1;  
out2_r_o<=level1;  
out2_g_o<=level1;  
out2_b_o<=level1;
ELSE 
out2_r_e<=(OTHERS=>'0');
out2_g_e<=(OTHERS=>'0');
out2_b_e<=(OTHERS=>'0'); 
out2_r_o<=(OTHERS=>'0'); 
out2_g_o<=(OTHERS=>'0');
out2_b_o<=(OTHERS=>'0');
END IF;

WHEN state2=>
IF color1='1' THEN 
out2_r_e<=level2; 
out2_g_e<=level2;  
out2_b_e<=level2;  
out2_r_o<=level2;  
out2_g_o<=level2;  
out2_b_o<=level2;
ELSE 
out2_r_e<=(OTHERS=>'0');
out2_g_e<=(OTHERS=>'0');
out2_b_e<=(OTHERS=>'0'); 
out2_r_o<=(OTHERS=>'0'); 
out2_g_o<=(OTHERS=>'0');
out2_b_o<=(OTHERS=>'0');
END IF;

WHEN state3=>
IF color1='1' THEN 
out2_r_e<=level3; 
out2_g_e<=level3;  
out2_b_e<=level3;  
out2_r_o<=level3;  
out2_g_o<=level3;  
out2_b_o<=level3;
ELSE 
out2_r_e<=(OTHERS=>'0');
out2_g_e<=(OTHERS=>'0');
out2_b_e<=(OTHERS=>'0'); 
out2_r_o<=(OTHERS=>'0'); 
out2_g_o<=(OTHERS=>'0');
out2_b_o<=(OTHERS=>'0');
END IF;

WHEN others=>
IF color1='1' THEN
out2_r_e<=level1; 
out2_g_e<=level1;  
out2_b_e<=level1;  
out2_r_o<=level1;  
out2_g_o<=level1;  
out2_b_o<=level1;
ELSE 
out2_r_e<=(OTHERS=>'0');
out2_g_e<=(OTHERS=>'0');
out2_b_e<=(OTHERS=>'0'); 
out2_r_o<=(OTHERS=>'0'); 
out2_g_o<=(OTHERS=>'0');
out2_b_o<=(OTHERS=>'0');
END IF;
END case;
END IF;
END PROCESS;

PROCESS(clk)
BEGIN
IF clk'event AND clk='1' THEN
IF(vcount>=512+VBP+VSY-hsize-hsize AND vcount<512+VBP+VSY+hsize+hsize AND hcount>=HBP+HSY+320-hsize AND hcount<HBP+HSY+320+hsize)
or(vcount>=ypos+VBP+VSY-hsize-hsize and vcount<ypos+VBP+VSY+hsize+hsize and hcount>=xpos+HBP+HSY-hsize and hcount<xpos+HBP+HSY+hsize)
or(vcount>=ypos+VBP+VSY-hsize-hsize and vcount<ypos+VBP+VSY+hsize+hsize and hcount>=320+HBP+HSY-hsize and hcount<320+HBP+HSY+hsize)
or(vcount>=ypos+VBP+VSY-hsize-hsize and vcount<ypos+VBP+VSY+hsize+hsize and hcount>=640-xpos+HBP+HSY-hsize and hcount<640-xpos+HBP+HSY+hsize)
or(vcount>=512+VBP+VSY-hsize-hsize and vcount<512+VBP+VSY+hsize+hsize and hcount>=xpos+HBP+HSY-hsize and hcount<xpos+HBP+HSY+hsize)
or(vcount>=512+VBP+VSY-hsize-hsize and vcount<512+VBP+VSY+hsize+hsize and hcount>=640-xpos+HBP+HSY-hsize and hcount<640-xpos+HBP+HSY+hsize)
or(vcount>=1024-ypos+VBP+VSY-hsize-hsize and vcount<1024-ypos+VBP+VSY+hsize+hsize and hcount>=xpos+HBP+HSY-hsize and hcount<xpos+HBP+HSY+hsize)
or(vcount>=1024-ypos+VBP+VSY-hsize-hsize and vcount<1024-ypos+VBP+VSY+hsize+hsize and hcount>=320+HBP+HSY-hsize and hcount<320+HBP+HSY+hsize)
or(vcount>=1024-ypos+VBP+VSY-hsize-hsize and vcount<1024-ypos+VBP+VSY+hsize+hsize and hcount>=640-xpos+HBP+HSY-hsize and hcount<640-xpos+HBP+HSY+hsize)
THEN color<='1';
ELSE color<='0';
END IF;
END IF;
END PROCESS;
PROCESS(clk)
BEGIN
IF clk'event AND clk='1' THEN
IF(vcount>=512+VBP+VSY-hsize-hsize AND vcount<512+VBP+VSY+hsize+hsize AND hcount>=HBP+HSY+320-hsize AND hcount<HBP+HSY+320+hsize)
THEN color1<='1';
ELSE color1<='0';
END IF;
END IF;
END PROCESS;

out_r_e<=out1_r_e when outsel='0' ELSE out2_r_e;
out_g_e<=out1_g_e when outsel='0' ELSE out2_g_e;
out_b_e<=out1_b_e when outsel='0' ELSE out2_b_e;
out_r_o<=out1_r_o when outsel='0' ELSE out2_r_o;
out_g_o<=out1_g_o when outsel='0' ELSE out2_g_o;
out_b_o<=out1_b_o when outsel='0' ELSE out2_b_o;

END rtl;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -