【正文】
整體rtl圖四、硬件測(cè)試編程下載和硬件測(cè)試的步驟如下: 打開(kāi)下載窗口。 設(shè)置下載電纜。并在”Hardware Setup”中設(shè)置下載電纜。Altera器件基本都支持JTAG在系統(tǒng)編程方式,這種方式簡(jiǎn)單易行,不需要專(zhuān)門(mén)的編程器。五、實(shí)驗(yàn)困難問(wèn)題及解決措施在實(shí)驗(yàn)的過(guò)程中,編寫(xiě)主程序的時(shí)候,也遇到調(diào)試不成功的問(wèn)題,主要問(wèn)題如下:①在編寫(xiě)xianshi模塊時(shí),最后給輸出信號(hào)賦值時(shí),使用了進(jìn)程語(yǔ)句,但是由于敏感列表不全,導(dǎo)致在仿真時(shí)其輸出信號(hào)的值產(chǎn)生錯(cuò)誤。②在實(shí)現(xiàn)綠燈剩余時(shí)間小于三秒時(shí)開(kāi)始閃爍功能時(shí),遇到問(wèn)題。開(kāi)始為了在綠燈狀態(tài),使綠燈在高、地電平間變換,所以就嘗試使用時(shí)鐘信號(hào)clk的上升沿和下降沿,其中上升沿時(shí),綠燈高電平即亮,下降沿時(shí)綠燈熄滅。經(jīng)過(guò)多次試驗(yàn),使用了clk高低電平觸發(fā),不再使用其上升下降沿。因?yàn)樵贗F語(yǔ)句中如果過(guò)沒(méi)有ELSE語(yǔ)句,那么輸出將默認(rèn)保持前一個(gè)狀態(tài),這樣很容易產(chǎn)生錯(cuò)誤。在查閱試驗(yàn)箱說(shuō)明書(shū)的情況下,完成了引腳的選定,并把程序下載到了試驗(yàn)箱里面,完成了實(shí)物的演示。分為五個(gè)模塊,分別為控制模塊、計(jì)時(shí)模塊、顯示模塊、譯碼模塊和分頻模塊,下面針對(duì)每個(gè)模塊給出相應(yīng)的程序:模塊一:/*************************控制部分**********************//***********定義輸入輸出端口***********/library ieee。use 。 at,bt : in std_logic_vector(7 downto 0)。end kongzhi。begin main logicprocess (clk,clr,at,bt)beginif clr=39。 then q=011。event and clk =39。) then if (at=x01) or (bt=x01) then 倒計(jì)時(shí)結(jié)束時(shí),狀態(tài)發(fā)生改變;q=q+1。 end if。end process。end rtl。use 。entity jishi is 實(shí)體部分 port ( clk, clr : in std_logic。 at,bt :out std_logic_vector(7 downto 0) )。architecture rtl of jishi is 結(jié)構(gòu)體signal ati,bti :std_logic_vector(7 downto 0)。signal brt,bgt,blt:std_logic_vector(7 downto 0)。art=x33。 A方向直行綠燈總時(shí)間為20s;alt=x10。 黃燈總時(shí)間為4s;brt=x38。 B方向直行綠燈總時(shí)間為15s;blt=x04。139。bti=x24。event and clk =39。) then if(ati=x01) or (bti=x01) then case s is 在每個(gè)狀態(tài),賦給相應(yīng)初始時(shí)間; when 000=ati=alt。 when 001=ati=abyt。 when 011=ati=abyt。bti=blt。 when 110=bti=bgt。 when others=ati=ati。 end case。 if ati/=x01 then 當(dāng)前時(shí)間大于1s時(shí),則相應(yīng)位進(jìn)行減一; if ati(3 downto 0)=0000 then ati(3 downto 0)=1001。 else ati(3 downto 0)=ati(3 downto 0)1。 end if。 if bti/=x01 then 當(dāng)前時(shí)間大于1s時(shí),則相應(yīng)位進(jìn)行減一; if bti(3 downto 0)=0000 then bti(3 downto 0)=1001。 else bti(3 downto 0)=bti(3 downto 0)1。 end if。 end if。at= ati。end rtl。use 。entity xianshi is 實(shí)體部分; port ( clk1k,clr ,clk : in std_logic。 led : out std_logic_vector(6 downto 0)。end xianshi。signal dis,ds : std_logic_vector(7 downto 0)。signal sq : std_logic_vector(3 downto 0):=0000。139。 elsif (clk1k39。139。 else sl =sl+1。 end if。sq1: process(sl) 產(chǎn)生位選信號(hào) begin case sl is when 000=sq=0001。 when 010=sq=0100。 when others=null。 end process。 when 001=ou=bt(7 downto 4)。 when 011=ou=at(7 downto 4)。 end case。 ds1:process(ou) begin 將顯示時(shí)間轉(zhuǎn)換成數(shù)碼管顯示; case ou is when x0=ds=x3F。 when x2=ds=x5b。 when x4=ds=x66。 when x6=ds=x7d。 when x8=ds=x7f。 when ot