(PLD可编程逻辑器件]d应用程序举例.pdf
(PLDPLD 可编程逻辑器件)可编程逻辑器件)d d应用程序举例应用程序举例PLD 段码显示library ieee;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_1164.all;entity duanma isentity duanma isport(fff:out bit_vector(1 to 5);port(fff:out bit_vector(1 to 5);aaa:out bit_vector(1 to 5);aaa:out bit_vector(1 to 5);end;end;architecture kk of duanma isarchitecture kk of duanma isbeginbeginfff(1 to 5)=11111;fff(1 to 5)=11111;aaa(1 to 5)=11111;aaa(1 to 5)=11111;end;end;PLDPLD 三个数加法编程三个数加法编程library ieee;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_1164.all;entity jw isentity jw isport(in1,in2:in integer range 0 to 15;port(in1,in2:in integer range 0 to 15;a,b:out std_logic_vector(1 to 7);a,b:out std_logic_vector(1 to 7);end;end;architecture gg of jw isarchitecture gg of jw issignal he:integer range 0 to 45;signal he:integer range 0 to 45;beginbeginhe=in1+in2;he=in1+in2;with he selectwith he selecta=1111110 when 0|10|20|30|40,a=1111110 when 0|10|20|30|40,0110000 when 1|11|21|31|41,0110000 when 1|11|21|31|41,1101101 when 2|12|22|32|42,1101101 when 2|12|22|32|42,1111001 when 3|13|23|33|43,1111001 when 3|13|23|33|43,0110011 when 4|14|24|34|44,0110011 when 4|14|24|34|44,1011011 when 5|15|25|35|45,1011011 when 5|15|25|35|45,1011111 when 6|16|26|36,1011111 when 6|16|26|36,1110000 when 7|17|27|37,1110000 when 7|17|27|37,1111111 when 8|18|28|38,1111111 when 8|18|28|38,1111011 when 9|19|29|39,1111011 when 9|19|29|39,0000000 when others;0000000 when others;with he selectwith he selectb=0000000 when 0=he andb=0000000 when 0=he andhe=9,elsehe=9,else0110000 when 10=he and0110000 when 10=he andhe=19,elsehe=19,else1101101 when 20=he and1101101 when 20=he andhe=29,elsehe=29,else1111001 when 30=he and1111001 when 30=he andhe=39,elsehe=39,else0110011 when 40=he and0110011 when 40=he andhe=39,elsehe=39,else0000000 when others;0000000 when others;end;end;PLDPLD 八个按键两个灯八个按键两个灯library ieee;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_1164.all;entity guozi3 isentity guozi3 isport(in1,in2:in std_logic_vector(1 toport(in1,in2:in std_logic_vector(1 to4);4);a,b:out std_logic_vector(1 to 8);a,b:out std_logic_vector(1 to 8);end;end;architecture gg of guozi3 isarchitecture gg of guozi3 isbeginbeginwith in1 selectwith in1 select0110000 when 0001,0110000 when 0001,1101101 when 0010,1101101 when 0010,1111001 when 0011,1111001 when 0011,0110011 when 0100,0110011 when 0100,1011011 when 0101,1011011 when 0101,1011111 when 0110,1011111 when 0110,1110000 when 0111,1110000 when 0111,1111111 when 1000,1111111 when 1000,1111011 when 1001,1111011 when 1001,0000000 when others;0000000 when others;with in2 selectwith in2 selectb=0110000when 0001,b=0110000when 0001,1101101 when 0010,1101101 when 0010,1111001 when 0011,1111001 when 0011,0110011 when 0100,0110011 when 0100,1011011 when 0101,1011011 when 0101,1011111 when 0110,1011111 when 0110,1110000 when 0111,1110000 when 0111,1111111 when 1000,1111111 when 1000,1111011 when 1001,1111011 when 1001,0000000 when others;0000000 when others;end;end;PLDPLD 顺序语句编程顺序语句编程(0(0 加到加到 9)9)library ieee;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_1164.all;entity jinchen isentity jinchen isport(in1:in std_logic;port(in1:in std_logic;a:out std_logic_vector(1 to 7);a:out std_logic_vector(1 to 7);end;end;architecture gg of jinchen isarchitecture gg of jinchen issignal ss:integer range 0 to 9;signal ss:integer range 0 to 9;beginbeginprocessprocessbeginbeginwait until in1=1;wait until in1=1;ss=ss+1;ss=ss+1;if ss=10 thenif ss=10 thenss=0;ss=0;end if;end if;end process;end process;with ss selectwith ss selecta=1111110 when 0,a=1111110 when 0,0110000 when 1,0110000 when 1,1101101 when 2,1101101 when 2,1111001 when 3,1111001 when 3,0110011 when 4,0110011 when 4,1011011 when 5,1011011 when 5,1011111 when 6,1011111 when 6,1110000 when 7,1110000 when 7,1111111 when 8,1111111 when 8,1111011 when 9,1111011 when 9,0000000 when others;0000000 when others;end;end;PLDPLD 矢量矢量 1010 个控制个控制 2 2 个数码管个数码管library ieee;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_1164.all;entity kongzhi2 isentity kongzhi2 isport(a:out bit_vector(1 to 7);port(a:out bit_vector(1 to 7);b:in b:inbit_vector(1 to 10);bit_vector(1 to 10);end;end;architecture ff of kongzhi2 isarchitecture ff of kongzhi2 isbeginbegin a=1111110 a=1111110when b=1000000000elsewhen b=1000000000else01100000110000whenwhenb=0100000000elseb=0100000000else11011011101101when b=0010000000elsewhen b=0010000000else11110011111001when b=1001000000elsewhen b=1001000000else01100110110011when b=1000100000elsewhen b=1000100000else10110111011011when b=1000010000elsewhen b=1000010000else10111111011111when b=1000001000elsewhen b=1000001000else11100001110000when b=1000000100elsewhen b=1000000100else11111111111111when b=1000000010elsewhen b=1000000010else11100111110011when b=1000000001elsewhen b=1000000001else0000000;0000000;end;end;PLDPLD 晶振晶振 50M50M 控制数码管控制数码管library ieee;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_1164.all;entity jinzheng isentity jinzheng isport(in50m:in std_logic;port(in50m:in std_logic;a:out std_logic_vector(1 to 7);a:out std_logic_vector(1 to 7);end;end;architecture gg of jinzheng isarchitecture gg of jinzheng issignal in1:std_logic;signal in1:std_logic;signal ss:integer range 0 to 9;signal ss:integer range 0 to 9;signal count:integer range 0 tosignal count:integer range 0 to25000000;25000000;beginbeginprocessprocessbeginbeginwait until in50m=1;wait until in50m=1;count=count+1;count=count+1;if count=25000000 thenif count=25000000 thencount=0;count=0;in1=not in1;in1=not in1;end if;end if;end process;end process;processprocessbeginbeginwait until in1=1;wait until in1=1;ss=ss+1;ss=ss+1;if ss=10 thenif ss=10 thenss=0;ss=0;end if;end if;end process;end process;with ss selectwith ss selecta=1111110 when 0,a=1111110 when 0,0110000 when 1,0110000 when 1,1101101 when 2,1101101 when 2,1111001 when 3,1111001 when 3,0110011 when 4,0110011 when 4,1011011 when 5,1011011 when 5,1011111 when 6,1011111 when 6,1110000 when 7,1110000 when 7,1111111 when 8,1111111 when 8,1111011 when 9,1111011 when 9,0000000 when others;0000000 when others;end;end;PLDPLD 晶振晶振 50M50M 自动跳变程序(自动跳变程序(0 0 到到 5959)library ieee;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_1164.all;entity jiadxx isentity jiadxx isport(in50m:in std_logic;port(in50m:in std_logic;a,b:out std_logic_vector(1 to 7);a,b:out std_logic_vector(1 to 7);end;end;architecture gg of jiadxx isarchitecture gg of jiadxx issignal in1:std_logic;signal in1:std_logic;signal t,g:integer range 0 to 9;signal t,g:integer range 0 to 9;signal count:integer range 0 to 59signal count:integer range 0 to 5925000000;25000000;beginbeginprocessprocessbeginbeginwait until in50m=1;wait until in50m=1;count=count+1;count=count+1;if count=25000000 thenif count=25000000 thencount=0;count=0;in1=not in1;in1=not in1;end if;end if;end process;end process;processprocessbeginbeginwait until in1=1;wait until in1=1;g=g+1;g=g+1;if g=9 thenif g=9 thenif g=5 thenif g=5 theng=0;g=0;t=t+1;t=t+1;if t=5 thenif t=5 thent=0;t=0;end if;end if;end if;end if;end process;end process;with g selectwith g selecta=1111110 when 0,a=1111110 when 0,0110000 when 1,0110000 when 1,改变变量改变变量1101101 when 2,1101101 when 2,1111001 when 3,1111001 when 3,0110011 when 4,0110011 when 4,1011011 when 5,1011011 when 5,1011111 when 6,1011111 when 6,1110000 when 7,1110000 when 7,1111111 when 8,1111111 when 8,1111011 when 9,1111011 when 9,0000000 when others;0000000 when others;with t selectwith t selectb=1111110 when 0,b=1111110 when 0,0110000 when 1,0110000 when 1,1101101 when 2,1101101 when 2,1111001 when 3,1111001 when 3,0110011 when 4,0110011 when 4,1011011 when 5,1011011 when 5,1011111 when 6,1011111 when 6,1110000 when 7,1110000 when 7,1111111 when 8,1111111 when 8,1111011 when 9,1111011 when 9,0000000 when others;0000000 when others;end;end;PLDPLD(1-81-8 数码管显示)第六个显示数码管显示)第六个显示 0 0library ieee;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_1164.all;entity jiadxx isentity jiadxx isport(a:out std_logic_vector(1 to 7);port(a:out std_logic_vector(1 to 7);b:out std_logic_vector(1 to 3);b:out std_logic_vector(1 to 3);end;end;architecture kk of jiadxx isarchitecture kk of jiadxx isbeginbegina=1111110;a=1111110;-显示的数“显示的数“0 0”b=010;b=010;-显示的位“第显示的位“第 6 6 位”位”end;end;PLDPLD 动态间隔动态间隔 1 1 秒闪烁秒闪烁library ieee;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_1164.all;entity jiadxx isentity jiadxx isport(in50m:in std_logic;port(in50m:in std_logic;b:out std_logic_vector(1 to 3);b:out std_logic_vector(1 to 3);a:out std_logic_vector(1 to 7);a:out std_logic_vector(1 to 7);end;end;architecture gg of jiadxx isarchitecture gg of jiadxx issignalsignalcount:integer range 0 tocount:integer range 0 to25000000;25000000;signal count_one:integer range 0 to 1;signal count_one:integer range 0 to 1;signal one_hz:std_logic;signal one_hz:std_logic;beginbeginprocessprocessbeginbeginwait until in50m=1;wait until in50m=1;count=count+1;count=count+1;if count=25000000 thenif count=25000000 thencount=0;count=0;one_hz=not one_hz;one_hz=not one_hz;end if;end if;end process;end process;processprocessbeginbeginwait until one_hz=1;wait until one_hz=1;count_one=count_one+1;count_one=count_one+1;if count_one=0 thenif count_one=0 thenb=000;b=000;elseelseb=001;b=001;end if;end if;end process;end process;a=1111110;a=1111110;end;end;PLDPLD 动态显示动态显示 0 01 1library ieee;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_1164.all;entity dz1121 isentity dz1121 isport(in50m:in std_logic;port(in50m:in std_logic;a:out std_logic_vector(1 to 7);a:out std_logic_vector(1 to 7);b:out std_logic_vector(1 to 3);b:out std_logic_vector(1 to 3);end;end;architecture gg of ningyi isarchitecture gg of ningyi issignal in1:std_logic;signal in1:std_logic;signal count_c:integer range 0 to 3;signal count_c:integer range 0 to 3;signal count:integer range 0 to 2500;signal count:integer range 0 to 2500;beginbeginprocessprocessbeginbeginwait until in50m=1;wait until in50m=1;count=count+1;count=count+1;if count=2500 thenif count=2500 thencount=0;count=0;in1=not in1;in1=not in1;end if;end if;end process;end process;processprocessbeginbeginwait until in1=1;wait until in1=1;count_c=count_c+1;count_c=count_c+1;if count_c=1 thenif count_c=1 thencount_c=0;count_c=0;end if;end if;end process;end process;withwithcount_c selectcount_c selecta=1111110when 0,a=1111110when 0,0110000when 10110000when 1,0000000when others;0000000when others;with count_c selectwith count_c selectb=000 when 0,b=000 when 0,001 when 1,001 when 1,111 when others;111 when others;end;end;PLDPLD 数码管显示数码管显示 0 07 7library ieee;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_1164.all;entity xian0-7 isentity xian0-7 isport(in50m:in std_logic;port(in50m:in std_logic;a:out std_logic_vector(1 to 7);a:out std_logic_vector(1 to 7);b:out std_logic_vector(1 to 3);b:out std_logic_vector(1 to 3);end;end;architecture gg of xian0-7 isarchitecture gg of xian0-7 issignal in1:std_logic;signal in1:std_logic;signal count_c:integer range 0 to 7;signal count_c:integer range 0 to 7;signal count:integer range 0 to 2500;signal count:integer range 0 to 2500;beginbeginprocessprocessbeginbeginwait until in50m=1;wait until in50m=1;count=count+1;count=count+1;if count=2500 thenif count=2500 thencount=0;count=0;in1=not in1;in1=not in1;end if;end if;end process;end process;processprocessbeginbeginwait until in1=1;wait until in1=1;count_c=count_c+1;count_cbb=000;a=1111110;abb=001;a=0110000;abb=010;a=1101101;abb=011;a=1111001;abb=100;a=0110011;abb=101;a=1011011;abb=110;a=1011111;abb=111;a=1110000;a=1110000;if count_c=7 thenif count_c=7 thencount_c=0;count_c=0;end if;end if;end case;end case;end process;end process;end;end;PLDPLD 时钟显示时钟显示library ieee;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_1164.all;entity shizon isentity shizon isport(in50m:std_logic;port(in50m:std_logic;a:out std_logic_vector(1 to 7);-a:out std_logic_vector(1 to 7);-段码段码b:out std_logic_vector(1 to 3);-b:out std_logic_vector(1 to 3);-位码位码end;end;architecture ff of shizon isarchitecture ff of shizon issignal count:integer range 0 to 250;-signal count:integer range 0 to 250;-整数定义整数定义signal count_s:integer range 0 tosignal count_s:integer range 0 to25000;-25000;-半秒定义半秒定义signalsignalg1,g2,s1,s2,b1,b2:std_logic_vector(1g1,g2,s1,s2,b1,b2:std_logic_vector(1to 7);-to 7);-变量范围变量范围signal one_hz:std_logic;-signal one_hz:std_logic;-定义定义 1 1 赫兹信赫兹信号号signal one_s:std_logic;signal one_s:std_logic;signal x:integer range 0 to 7;-signal x:integer range 0 to 7;-signalsignalgg1,gg2,ss1,ss2,bb1,bb2:integergg1,gg2,ss1,ss2,bb1,bb2:integerrange 0 to 9;range 0 to 9;beginbeginprocessprocessbeginbeginwait until in50m=1;wait until in50m=1;count=count+1;count=count+1;if count=250 thenif count=250 thencount=0;count=0;one_hz=not one_hz;one_hz=not one_hz;end if;end if;end process;end process;processprocessbeginbeginwait until in50m=1;wait until in50m=1;count_s=count_s+1;count_s=count_s+1;if count_s=25000 thenif count_s=25000 thencount_s=0;count_s=0;one_s=not one_s;one_s=not one_s;end if;end if;end process;end process;processprocessbeginbeginwait until one_hz=1;wait until one_hz=1;x=x+1;xbb=000;a=g1;abb=001;a=g2;abb=010;a=0000001;abb=011;a=s1;abb=100;a=s2;abb=101;a=0000001;abb=110;a=b1;abb=111;a=b2;a=b2;x=0;x=0;end case;end case;end process;end process;processprocessbeginbeginwait until one_s=1;wait until one_s=1;gg1=gg1+1;gg1=gg1+1;if gg1=9 thenif gg1=9 thengg1=0;gg1=0;gg2=gg2+1;gg2=gg2+1;if gg2=5 thenif gg2=5 thengg2=0;gg2=0;ss1=ss1+1;ss1=ss1+1;if ss1=9 thenif ss1=9 thenss1=0;ss1=0;ss2=ss2+1;ss2=ss2+1;if ss2=5 thenif ss2=5 thenss2=0;ss2=0;bb1=bb1+1;bb1=bb1+1;if bb1=9 thenif bb1=9 thenbb1=0;bb1=0;bb2=bb2+1;bb2=bb2+1;end if;end if;if bb1=3 and bb2=2 thenif bb1=3 and bb2=2 thenbb1=0;bb1=0;bb2=0;bb2=0;end if;end if;end if;end if;end if;end if;end if;end if;end if;end if;end process;end process;with gg1 selectwith gg1 selectg1=1111110 when 0,g1=1111110 when 0,0110000 when 1,0110000 when 1,1101101 when 2,1101101 when 2,1111001 when 3,1111001 when 3,0110011 when 4,0110011 when 4,1011011 when 5,1011011 when 5,1011111 when 6,1011111 when 6,1110000 when 7,1110000 when 7,1111111 when 8,1111111 when 8,1111011 when 9,1111011 when 9,0000000 when others;0000000 when others;with gg2 selectwith gg2 selectg2=1111110 when 0,g2=1111110 when 0,0110000 when 1,0110000 when 1,1101101 when 2,1101101 when 2,1111001 when 3,1111001 when 3,0110011 when 4,0110011 when 4,1011011 when 5,1011011 when 5,0000000 when others;0000000 when others;with ss1 selectwith ss1 selects1=1111110 when 0,s1=1111110 when 0,0110000 when 1,0110000 when 1,1101101 when 2,1101101 when 2,1111001 when 3,1111001 when 3,0110011 when 4,0110011 when 4,1011011 when 5,1011011 when 5,1011111 when 6,1011111 when 6,1110000 when 7,1110000 when 7,1111111 when 8,1111111 when 8,1111011 when 9,1111011 when 9,0000000 when others;0000000 when others;with ss2 selectwith ss2 selects2=1111110 when 0,s2=1111110 when 0,0110000 when 1,0110000 when 1,1101101 when 2,1101101 when 2,1111001 when 3,1111001 when 3,