【正文】
en case t is when 00=shift=0111。 data_ledin=1111。 t:=t+1。 when 01=shift=1011。 data_ledin=d2(11 downto 8)。 t:=t+1。 when 10=shift=1101。 data_ledin=d2(7 downto 4)。 t:=t+1。 when 11=shift=1110。 data_ledin=d2(3 downto 0)。 t:=00。 when others=t:=00。 shift=1111。 end case。 end if。end process。process (data_ledin) 譯碼 begin case data_ledin is when0000=data_led=11000000。0 when0001=data_led=11111001。1 when0010=data_led=10100100。2 when0011=data_led=10110000。3 when0100=data_led=10011001。4 when0101=data_led=10010010。5 when0110=data_led=10000010。6 when0111=data_led=11111000。7 when1000=data_led=10000000。8 when1001=data_led=10010000。9 when others=data_led=11111111。No signal。 end case。end process。end Behavioral。/**/按鍵去抖模塊(同下,略去)頂層模塊/**/按鍵去抖模塊library IEEE。use 。use 。use 。 Unment the following lines to use the declarations that are provided for instantiating Xilinx primitive ponents.library UNISIM。use 。entity anjianqd is Port (clk,key:in std_logic。系統(tǒng)時鐘/輸入按鍵 keyo:out std_logic )。輸出按鍵end anjianqd。architecture Behavioral of anjianqd issignal clkk,dly,ndly,diff:std_logic。beginprocess(clk)variable t:integer range 1 to 256000。begin if clk39。event and clk=39。139。 then if t=2 then t:=1。 clkk=39。139。 else t:=t+1。clkk=39。039。 end if。 end if。end process。debunce:blocksignal d0,d1,s,r:std_logic。begin process(clk) begin if clk39。event and clk=39。139。 then if clkk=39。139。 then d1=d0。d0=key。 s=d0 and d1。 r=not d0 and not d1。 end if。 end if。 end process。 dly=r nor ndly。 ndly=s nor dly。end block。differetial:block signal d1,d0:std_logic。 begin process(clk) begin if clk39。event and clk=39。139。 then d1=d0。d0=dly。 end if。 end process。diff=d0 and not d1。end block。keyo=diff。end Behavioral。/**/頂層控制模塊library IEEE。use 。use 。use 。 Unment the following lines to use the declarations that are provided for instantiating Xilinx primitive ponents.library UNISIM。use 。entity top isPort (rst,add,sub,sel,shift1,startstop:in std_logic。復(fù)位/加鍵/減鍵/換向鍵/步進(jìn)伺服切換/起止鍵 clock:in std_logic。 系統(tǒng)時鐘 shift:out std_logic_vector(3 downto 0)。 數(shù)碼管位選信號輸出 data_led:out std_logic_vector(7 downto 0)。 七段數(shù)碼管輸出 pwmout:out std_logic_vector(1 downto 0)。 伺服電機(jī)控制脈沖 stepout:out std_logic_vector(3 downto 0) )。步進(jìn)電機(jī)控制脈沖end top。architecture Behavioral of top isponent step_top is Port (clk,add,sub,sel,rst,startstop:in std_logic。 step:out std_logic_vector(3 downto 0)。 shift:out std_logic_vector(3 downto 0)。 data_led:out std_logic_vector(7 downto 0) )。end ponent step_top。ponent pwms is Port (clk,rst,add,sub,set,startstop:in std_logic。 y,yf:out std_logic 。 shift:out std_logic_vector(3 downto 0)。 data_led:out std_logic_vector(7 downto 0))。end ponent pwms。ponent anjianqd is Port (clk,key:in std_logic。 keyo:out std_logic )。end ponent anjianqd。signal key,addp,subp,selp,rstp,adds,subs,sels,sel1,sel2,rsts:std_logic。signal startstopp,startstops,q1,q2,q3:std_logic。signal shift15,rst5,clk:std_logic。signal shiftp,shifts:std_logic_vector(3 downto 0)。signal data_ledp,data_leds:std_logic_vector(7 downto 0)。beginprocess(key,sel2) begin if rising_edge(key) then sel2=not sel2。 end if。end process。process(sel1,add,sub,sel,rst5,startstop,shiftp,data_ledp,shifts,data_leds) 按鍵/顯示切換模塊begin case sel1 is when 39。139。=addp=add。subp=sub。selp=sel。rstp=rst5。startstopp=startstop。 adds=39。139。subs=39。139。sels=39。139。rsts=39。139。startstops=39。139。 shift=shiftp。data_led=data_ledp。 when 39。039。=addp=39。139。subp=39。139。selp=39。139。rstp=39。139。startstopp=39。139。 adds=add。subs=sub。sels=sel。rsts=rst5。startstops=startstop。 shift=shifts。data_led=data_leds。 when others=null。 end case。end process。process(clock) 系統(tǒng)初始化模塊variable t:integer range 0 to 32000000:=0。begin if rising_edge(clock) then if t100000 then t:=t+1。sel1=39。039。rst5=39。139。 elsif t200000 then t:=t+1。sel1=39。039。rst5=39。039。 elsif t300000 then t:=t+1。sel1=39。039。rst5=39。139。 elsif t400000 then t:=t+1。sel1=39。139。rst5=39。139。 elsif t500000 then t:=t+1。sel1=39。139。rst5=39。039。 elsif t600000 then t:=t+1。sel1=39。139。rst5=39。139。 else t:=700000。sel1=sel2。rst5=rst。 end if。 end if。 end process。clk=clock。u1:anjianqd port map (clk=clk,key=shift1,keyo=key)。u2:step_top port map (clk=clk,add=adds,sub=subs,sel=sels,step=stepout,rst=rsts, shift=shifts,data_led=data_leds,startstop=startstops)。u3:pwms port map (clk=clk,add=addp,sub=subp,rst=rstp,set=selp, shift=shiftp,data_led=data_ledp,y=pwmout(1),yf=pwmout(0),startstop=startstopp)。end Behaviora