- 相關(guān)推薦
發(fā)光二極管走馬燈電路的設計與實(shí)現實(shí)驗(一)
實(shí)驗程序:
設計思路:首先用按鍵SW1來(lái)控制顯示模式。用狀態(tài)機來(lái)實(shí)現單點(diǎn)移動(dòng)和幕布式移動(dòng)。
VHDL程序如下
library ieee;
use ieee.std_logic_1164.all;
entity scan is
port(clk,reset:in std_logic;
light:out std_logic_vector(7 downto 0);
a:in std_logic
);
end scan;
architecture arch_scan of scan is
TYPE state_type is(s0,s1,s2,s3,s4,s5,s6,s7);
signal state:state_type;
begin
process(a,clk,reset) ——————process使用嵌套
begin
if(reset='1') then light<="00000000";
elsif(rising_edge(clk)) then
if a='0' then ——————‘a(chǎn)’代表BW1的值,控制顯示模式
case state is ——————實(shí)現單點(diǎn)移動(dòng)
when s0=>
state<=s1;
light<="10000000";
when s1=>
state<=s2;
light<="01000000";
when s2=>
state<=s3;
light<="00100000";
when s3=>
state<=s4;
light<="00010000";
when s4=>
state<=s5;
light<="00001000";
when s5=>
state<=s6;
light<="00000100";
when s6=>
state<=s7;
light<="00000010";
when s7=>
state<=s0;
light<="00000001";
end case;
else
case state is ——————實(shí)現幕布式移動(dòng)
when s0=>
state<=s1;
light<="00011000";
when s1=>
state<=s2;
light<="00111100";
when s2=>
state<=s3;
light<="01111110";
when s3=>
state<=s4;
light<="11111111";
when s4=>
state<=s5;
light<="01111110";
when s5=>
state<=s6;
light<="00111100";
when s6=>
state<=s7;
light<="00011000";
when s7=>
state<=s0;
light<="00000000";
end case;
end if;
end if;
end process;
end arch_scan;
仿真波形如下:
600)makesmallpic(this,600,1800);' src="file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/ksohtml/wps_clip_image-0.png" width="662" height="244" />
實(shí)驗總結
仿照上個(gè)實(shí)驗的狀態(tài)機設計,自己寫(xiě)出了以上的程序。雖然程序簡(jiǎn)單,容易寫(xiě)出,但由于語(yǔ)法不熟,在編寫(xiě)的過(guò)程中走了很多的彎路也出現了較多的錯誤。還好,在老師的指導下,經(jīng)過(guò)不段的調試,改正終于得出了正確的結果。
最初,我由于不知道要用嵌套PROCESS,而在一個(gè)PROCESS中又加入倆個(gè)PROCESS。導致編譯不能通過(guò)。這是由于語(yǔ)法不清而犯的錯誤。
還有就是在寫(xiě)程序的時(shí)候沒(méi)有進(jìn)行深入的思考。簡(jiǎn)單的認為狀態(tài)機不能實(shí)現幕布式的移動(dòng)(因為我認為狀態(tài)機的狀態(tài)不足以表達幕布式的各個(gè)狀態(tài),其實(shí)是足夠的)而使用了兩個(gè)循環(huán),這樣就把程序弄的很復雜。編寫(xiě)的時(shí)候太草率了,應該進(jìn)行細致的思考后再去編寫(xiě)。
最后的問(wèn)題就是,整個(gè)編程的過(guò)程中,小錯誤總是不段。這里多個(gè)‘;’,那里少個(gè)字母的。這些小的錯誤雖然在編譯后能夠更正過(guò)來(lái),但最好還是希望自己能在以后不要在出現類(lèi)似的錯誤。
經(jīng)過(guò)這次實(shí)驗,存在的問(wèn)題還是老問(wèn)題——語(yǔ)法不清、不夠細心。語(yǔ)法的問(wèn)題是由于沒(méi)有具體的學(xué)習過(guò),又沒(méi)有在課下反復的聯(lián)系。要去系統的學(xué)習VHDL語(yǔ)言,在近期有點(diǎn)不切實(shí)際,還是要多加練習。在練習中熟練 VHDL的語(yǔ)法,而做的多了,也就能避免在細節問(wèn)題上總是出錯。
【發(fā)光二極管走馬燈電路的設計與實(shí)現實(shí)驗(一)】相關(guān)文章:
錯誤檢測與糾正電路的設計與實(shí)現03-20
ADPCM語(yǔ)音編解碼電路設計及FPGA實(shí)現03-18
Boost電路的一種軟開(kāi)關(guān)實(shí)現方法03-18
AGC電路的設計03-07
用Protel99SE實(shí)現脈沖電路的仿真03-18
換體DMA高速數據采集電路的CPLD實(shí)現03-18