【文章內(nèi)容簡介】
HEX1[2] PIN_W21 HEX1[3] PIN_Y22 HEX1[4] PIN_AA24 HEX1[5] PIN_AA23 HEX1[6] PIN_AB24 LEDR[17] PIN_AD12 KEY[3] PIN_W26 CLOCK_50 PIN_N2 四 . 實(shí)驗(yàn)代碼 LIBRARY ieee。 USE 。 entity segment is port ( in1 : in integer range 0 to 15。 out1 : out std_logic_vector(6 downto 0)。 out2: out std_logic_vector(6 downto 0))。 end segment。 architecture seg of segment is type array3 is array(9 downto 0 )of std_logic_vector(6 downto 0)。 begin process(in1) CONSTANT lookuptable :array3 := ((0011000),(0000000),(1111000),(0000011), (0010010),(0011001),(0110000),(0100100),(1001111),(1000000))。 begin if(in1=10)then out2=1001111。 else out2=1111111。 end if。 if(in1=10)then out1=lookuptable(in110)。 else out1=lookuptable(in1)。 end if。 for i in 6 to 0 loop out1(i)=lookuptable(index,i)。 end loop。 end process。 end seg。 LIBRARY ieee。 USE 。 entity segment is port ( clk: in std_logic。 key17: in std_logic。 led17: out std_logic。 out1 : out std_logic_vector(6 downto 0)。 out2: out std_logic_vector(6 downto 0))。 end segment。 architecture seg of segment is type array3 is array(9 downto 0 )of std_logic_vector(6 downto 0)。 signal in1 : integer range 0 to 15。 signal count1 : integer range 0 to 33554432。 begin process(clk) CONSTANT lookuptable :array3 := ((0010000),(0000000),(1111000),(0000010), (0010010),(0011001),(0110000),(0100100),(1001111),(1000000))。 begin if(clk39。event and clk=39。139。)then count1=count1+1。 if(key17=39。139。)then led17=39。139。 else led17=39。039。 end if。 if(count1=33554432)then if(key17=39。139。)then in1=in1+1。 else in1=in11。 end if。 if(in1=10)then out2=1001111。 else out2=1111111。 end if。 if(in1=10)then out1=lookuptable(in110)。 else out1=lookuptable(in1)。 end if。 end if。 end if。 end process。 end seg。 五 . 實(shí)驗(yàn)心得體會(huì) 本次實(shí)驗(yàn)要用到七段碼的知識,所幸我們前面已接觸了不少,這里馬上想到了用查表的辦法。除此之外,還要綜合考慮定時(shí),計(jì)數(shù)等。 實(shí)驗(yàn)五 . 狀態(tài)機(jī)代碼驗(yàn)證 一.實(shí)驗(yàn)?zāi)康? 以狀態(tài)機(jī)的一些代碼為例,熟悉狀態(tài)機(jī)設(shè)計(jì)方法 二.實(shí)驗(yàn)內(nèi)容 以經(jīng)典雙進(jìn)程狀態(tài)機(jī)、使用變量的狀態(tài)機(jī)、帶異步清零的狀態(tài)機(jī)、模式檢測狀態(tài)機(jī)、帶摩爾和米立輸出的狀態(tài)機(jī)、 摩爾型狀態(tài)機(jī)、米立型狀態(tài)機(jī)代碼為例,熟悉各種狀態(tài)機(jī)設(shè)計(jì)方法,體會(huì)它樣的區(qū)別 4. 學(xué)習(xí)已給的經(jīng)典雙進(jìn)程狀態(tài)機(jī)代碼,畫出狀態(tài)轉(zhuǎn)換圖,編譯,仿真。 5. 學(xué)習(xí)已給的使用變量的狀態(tài)機(jī)代碼,畫出狀態(tài)轉(zhuǎn)換圖,編譯,仿真。 6. 學(xué)習(xí)已給的帶異步清零的狀態(tài)機(jī)代碼,畫出狀態(tài)轉(zhuǎn)換圖,編譯,仿真。 7. 學(xué)習(xí)已給的模式檢測狀態(tài)機(jī)代碼,畫出狀態(tài)轉(zhuǎn)換圖,編譯,仿真。 8. 學(xué)習(xí)已給的帶摩爾和米立輸出的狀態(tài)機(jī)代碼,畫出狀態(tài)轉(zhuǎn)換圖,編譯,仿真。 9. 學(xué)習(xí)已給的摩爾型狀態(tài)機(jī)代碼,畫出狀態(tài)轉(zhuǎn)換圖,編譯,仿真。 10. 學(xué)習(xí)已給的米立型狀態(tài)機(jī)代碼,畫出狀態(tài)轉(zhuǎn)換圖,編譯,仿真。 三.實(shí)驗(yàn)代碼 1)經(jīng)典雙進(jìn)程狀態(tài)機(jī) MEALY TYPE STATE MACHINE EXAMPLE ENTITY fsm IS PORT( clock, x : IN BIT。 z : OUT BIT)。 END fsm。 ARCHITECTURE behaviour OF fsm IS TYPE state_type IS (s0, s1, s2, s3)。 SIGNAL present_state, next_state : state_type。 BEGIN state register process state_reg: PROCESS BEGIN WAIT UNTIL clock39。EVENT AND clock = 39。139。 present_state = next_state。 END PROCESS。 binational logic feedback process fb_logic:PROCESS(present_state, x) BEGIN CASE present_state IS WHEN s0 = IF x = 39。039。 THEN z = 39。039。 next_state = s0。 ELSE z = 39。139。 next_state = s2。 END IF。 WHEN s1 = IF x = 39。039。 THEN z = 39。039。 next_state = s0。 ELSE z = 39。039。 next_state = s2。 END IF。 WHEN s2 = IF x = 39。039。 THEN z = 39。139。 next_state = s2。 ELSE z = 39。039。 next_state = s3。 END IF。 WHEN s3 = IF x = 39。039。 THEN z = 39。039。 next_state = s3。 ELSE z = 39。139。 next_state = s1。 END IF。 END CASE。 END PROCESS。 END behaviour。 五.實(shí)驗(yàn)心得體會(huì) 通過本次實(shí)驗(yàn),我收悉了仿真的基本方法,進(jìn)一步加深了狀態(tài)機(jī)的基本設(shè)計(jì)方法的掌握。 實(shí)驗(yàn)六 . 序列檢測器的設(shè)計(jì) 一.實(shí)驗(yàn)?zāi)康? 1. 掌握用 VHDL 實(shí)現(xiàn)狀態(tài)機(jī)的方法 2. 利用狀態(tài)機(jī)設(shè)計(jì)一個(gè)序列檢測器 二.實(shí)驗(yàn)內(nèi)容 使用狀態(tài)機(jī)設(shè)計(jì)一個(gè) 5位序列檢測器。從一串二進(jìn)制碼中檢測出一個(gè)已預(yù)置的 5 位二進(jìn)制碼 ”10110” [具體要求 ] 。(每增加一位二進(jìn)制碼相當(dāng)于增加一個(gè)狀態(tài),再加上一個(gè)初始態(tài),用 6 個(gè)狀態(tài)可以實(shí)現(xiàn) .) ,編譯。要求當(dāng)檢測到預(yù)置序列時(shí),輸出一個(gè)脈沖的高電平,其余時(shí)候輸出為低電平。 ,看結(jié)果是否正確。 三 . 實(shí)驗(yàn)框圖 四. 實(shí)驗(yàn)代碼 library ieee。 use 。 ENTITY fsm IS PORT( clock,x : IN BIT。 z : OUT BIT)。 END fsm。 x= 1 x= 1 x= 1 x= 0 x= 1 x= 0 x= 0 x= 0 x= 0 x= 1 x= 0 S0 S1 S2 S3 S4 S5 x= 0 ARCHITECTURE using_wait OF fsm IS TYPE state_type IS (s0, s1, s2, s3,s4,s5)。 BEGIN PROCESS VARIABLE st : state_type := s0。 BEGIN WAIT UNTIL (clock39。EVENT AND clock = 39。139。)。 CASE st IS WHEN s0 = IF x = 39。139。 THEN st := s1。 z = 39。039。 ELSE st := s0。 z = 39。039。 END IF。 WHEN s1 = IF x = 39。039。 THEN st := s2。 z = 39。039。 ELSE st:= s1。 z = 39。039。 END IF。 WHEN s2 = IF x = 39。039。 THEN st := s0。 z = 39。039。 ELSE st := s3。 z = 39。039。 END IF。 WHEN s3 = IF x = 39。139。 THEN st := s4。