FPGA綜合設(shè)計實例(行業(yè)經(jīng)驗)_第1頁
FPGA綜合設(shè)計實例(行業(yè)經(jīng)驗)_第2頁
FPGA綜合設(shè)計實例(行業(yè)經(jīng)驗)_第3頁
FPGA綜合設(shè)計實例(行業(yè)經(jīng)驗)_第4頁
FPGA綜合設(shè)計實例(行業(yè)經(jīng)驗)_第5頁
已閱讀5頁,還剩125頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、第十章綜合設(shè)計實例1沐風(fēng)書屋e1 鍵盤掃描與顯示矩陣式鍵盤:行,列矩陣是鍵盤以行列形式排列,鍵盤上每個按鍵其實是一個開關(guān)電路,當(dāng)某鍵被按下時,該按鍵對應(yīng)的位置就呈現(xiàn)邏輯0狀態(tài).行掃描方式:逐行送0電平,讀取列的狀態(tài),以判斷按下的鍵號.列掃描方式:逐列送0電平,讀取行的狀態(tài),以判斷按下的鍵號.2沐風(fēng)書屋e以行掃描為例:1給行依次送0111,1011,1101,1110信號;2讀取列電平狀態(tài),3沐風(fēng)書屋e數(shù)碼管顯示4沐風(fēng)書屋elibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity key_sca

2、n is port(column:in std_logic_vector(3 downto 0); -列狀態(tài) scan_cnt:in std_logic_vector(3 downto 0);-掃描字 row:out std_logic_vector(3 downto 0);-行狀態(tài) key_pressed:out std_logic);-按鍵有效與否,后續(xù)判斷為零則為有鍵按下end ;architecture rtl of key_scan isbegin row=1110 when scan_cnt(3 downto 2)=00 else 1101 when scan_cnt(3 down

3、to 2)=01 else 1011 when scan_cnt(3 downto 2)=10 else 0111; key_pressed=column(0) when scan_cnt(1 downto 0)=00 else column(1) when scan_cnt(1 downto 0)=01 else column(2) when scan_cnt(1 downto 0)=“10 else column(3); end rtl ;按鍵掃描控制程序5沐風(fēng)書屋e按鍵處理控制模塊library ieee;use ieee.std_logic_1164.all;use ieee.std_

4、logic_unsigned.all;use ieee.std_logic_arith.all;entity scan_count isport(clk:in std_logic;-clockscan_clk:in std_logic;-1khz clkkey_pressed:in std_logic;-檢測按鍵有效與否,停止計數(shù). scan_cnt:out std_logic_vector(3 downto 0);-計數(shù)end;architecture behav of scan_count issignal qscan:std_logic_vector(3 downto 0);begin

5、scan_1:process(clk,scan_clk,key_pressed) begin if(clkevent and clk=1)then if(scan_clk=1 and key_pressed=1)then qscan=qscan+1; end if; end if; end process; scan_cnt=qscan; end;6沐風(fēng)書屋e按鍵消抖控制模塊library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity de

6、bounce isport(key_pressed:in std_logic; clk:in std_logic;-同步時鐘 scan_clk:in std_logic;-1khz clock key_valid:out std_logic);end;architecture behav of debounce isbegin 7沐風(fēng)書屋edebounce:process(clk,scan_clk,key_pressed) variable dbnq:std_logic_vector(5 downto 0); begin if(key_pressed=1)then dbnq:=111111;-

7、unkey_pressed,count reset at 63 elsif(clkevent and clk=1)then if scan_clk=1 then if dbnq/=1 then dbnq:=dbnq-1;-key_pressed not enough long time end if; end if; end if; if dbnq=2 then key_valid=1;-key_valid after key_pressed 1/63k second else key_validbutt_codebutt_codebutt_codebutt_codebutt_codebutt

8、_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_code=1111;-fend case;end if; end if;end process;end ;10沐風(fēng)書屋e 電鎖控制模塊library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity ctrl is port(data_n:in std_logic_vector(3 downto 0); key_valid

9、,clk:in std_logic; enlock:out std_logic; d,c,b,a:out std_logic_vector(3 downto 0);end;architecture aaa of ctrl is signal acc,reg:std_logic_vector(15 downto 0);signal nc:std_logic_vector(2 downto 0);signal qa,qb:std_logic;beginkeyin:block is begin process(data_n,key_valid) 11沐風(fēng)書屋ebegin if data_n=1101

10、 then acc=0000000000000000; nc=000; elsif key_validevent and key_valid=1 then if data_n1101 then if nc=4 then acc=acc(11 downto 0)&data_n; nc=nc+1; end if;end if;end if;end process;end block; lock:block is begin process(clk,data_n) begin if(clkevent and clk=1)then if nc=4 then if data_n=1110 then re

11、g=acc; qa=1;qb=0; elsif data_n=1111 then if reg=acc then qa=0;qb=1; end if;end if;end if;end if;end process;end block;12沐風(fēng)書屋eenlock=qa and not qb; d=acc(15 downto 12); c=acc(11 downto 8); b=acc(7 downto 4); a=acc(3 downto 0); end aaa;13沐風(fēng)書屋e動態(tài)掃描顯示控制模塊library ieee;use ieee.std_logic_1164.all;use ieee

12、.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity sel_display isport(clk:in std_logic; d,c,b,a:in std_logic_vector(3 downto 0); db_out:out std_logic_vector(3 downto 0); dis_out:out std_logic_vector(3 downto 0);end entity;architecture rtl of sel_display is signal sel:std_logic_vector(1 down

13、to 0); signal dis:std_logic_vector(3 downto 0); signal db:std_logic_vector(3 downto 0);begin14沐風(fēng)書屋ecounter:block is signal q:std_logic_vector(6 downto 0); begin process(clk) begin if clkevent and clk=1 then q=q+1; end if; end process; sel=q(1 downto 0); end block counter;15沐風(fēng)書屋emultiplexer:block is

14、begin process(sel) begin if sel=0 then db=d; dis=0111; elsif sel=1 then db=c; dis=1011; elsif sel=2 then db=b; dis=1101; elsif sel=3 then db=a; dis=1110; end if; end process; end block multiplexer; db_out=db; dis_out=dis; end rtl;16沐風(fēng)書屋e17沐風(fēng)書屋e18沐風(fēng)書屋e19沐風(fēng)書屋e實例1 數(shù)字鐘設(shè)計實時顯示時、分、秒分析:1、最小計時單位:秒。因此,首先要由時鐘產(chǎn)

15、生1HZ的信號;2、對秒進(jìn)行0-59的計數(shù),并且有進(jìn)位功能,且顯示;3、對分進(jìn)行0-59的計數(shù),并且有進(jìn)位功能,且顯示;4、對時進(jìn)行0-59的計數(shù),且顯示;20沐風(fēng)書屋e21沐風(fēng)書屋elibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.allentity second is port(clk,clr:in std_logic;-clk=1Hz sec1,sec0:out std_logic_vector(3 downto 0); co:out std_logic );end second;architectu

16、re arch of second isbegin process(clk,clr) variable cnt1,cnt0:std_logic_vector(3 downto 0); begin if clr=0 then cnt1:=0000; cnt0:=0000; elsif clkevent and clk=1 then if cnt1=0101 and cnt0=1000 then co=1; cnt0:=1001; elsif cnt01001 then cnt0:=cnt0+1; else cnt0:=0000; if cnt10101 then cnt1:=cnt1+1;els

17、e cnt1:=0000; co=0; end if; end if; end if; sec1=cnt1; sec0 kinside:=0; -停止?fàn)顟B(tài)或空擋28沐風(fēng)書屋e when 001= kinside:=28; -第一檔,慢速行駛狀態(tài),行駛100m需要28個時鐘周期 when 010= kinside:=24; -第二檔 when 011= kinside:=20; -第三檔 when 100= kinside:=16; -第四檔 when 101= kinside:=12; -第五檔 when 110= kinside:=8; -第六檔 when 111= kinside:=4;

18、-第七檔,也是速度最大的檔 end case; if reset=1then s_state:=s0; elsif clkevent and clk=1then case s_state is when s0= cnt:=0;clkout clkout=0; if stop=1 then s_state:=s0; -相當(dāng)于無客戶上車 elsif sp=000 then s_state:=s1; -有客戶上車,但車速位0,即客戶剛上車還未起步 elsif cnt=kinside then cnt:=0;clkout=1; s_state:=s1; else cnt:=cnt+1; s_state

19、:=s1; end if; end case; end if; end process;end behav;30沐風(fēng)書屋ekilometers模塊此模塊主要用于記錄行進(jìn)的距離。通過對clkout信號的計數(shù),可以計算行駛的距離kmcount。一個clkout脈沖相當(dāng)于行進(jìn)100m,所以只要記錄clkout的脈沖數(shù)目即可確定共行進(jìn)的距離。kmcount1為十分位,kmcount2為個位,kmcount3為十位,分別為十進(jìn)制數(shù)。31沐風(fēng)書屋eLibrary ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity

20、kilometers is Port(clkout,reset:in std_logic; kmcnt1:out std_logic_vector(3 downto 0); kmcnt2:out std_logic_vector(3 downto 0); kmcnt3:out std_logic_vector(3 downto 0);end kilometers;architecture behav of kilometers isbegin process(clkout,reset) variable km_reg:std_logic_vector(11 downto 0);begin if

21、 reset=1then km_reg:=000000000000; elsif clkoutevent and clkout=1then -km_reg(3 downto 0)對應(yīng)里程十分位32沐風(fēng)書屋e if km_reg(3 downto 0)=1001then km_reg:=km_reg+0111; -十分位向個位的進(jìn)位處理 else km_reg(3 downto 0):=km_reg(3 downto 0)+0001; end if; if km_reg(7 downto 4)=1010then km_reg:=km_reg+01100000; -個位向十位的進(jìn)位處理 end i

22、f;end if;kmcnt1=km_reg(3 downto 0);kmcnt2=km_reg(7 downto 4);kmcnt3 waittime:=0;timecount if sp=000then t_state:=t2; else waittime:=0;t_state:=t1; end if; when t2 = waittime:=waittime+1; timecount=0; if waittime=1000 then timecount=1; -20s,即1000個clk,產(chǎn)生一個時間計費脈沖 waittime:=0; elsif stop=1then t_state:=

23、t0; elsif sp=000then t_state:=t2; else timecount=000001000000then price=0100; Else price=0011)or(kmcnt3=0001)then enable=1; Else enable=0; End if; End process;kmmoney2:process(reset,clkout,clk,enable,price,kmcnt2)variable reg2:std_logic_vector(11 downto 0);variable clkout_cnt:integer range 0 to 10;b

24、egin if reset=1 then cash1001 then reg2(7 downto 0):=reg2(7 downto 0)+00000111; if reg2(7 downto 4)1001 then cash =reg2+000001100000; else cash=reg2; end if; else cash00001001then reg2(7 downto 0):=reg2(7 downto 0)+00000110+price; if reg2(7 downto 4)1001then cash=reg2+000001100000; else cash=reg2; e

25、nd if; else cash=reg2+price; end if; else clkout_cnt:=clkout_cnt+1; end if;end if;end if;end process;count1=cash(3 downto 0); -總費用的個位count2=cash(7 downto 4); -總費用的十位count3=cash(11 downto 8); -總費用的百位End behav;40沐風(fēng)書屋e41沐風(fēng)書屋e分頻模塊對系統(tǒng)的時鐘進(jìn)行分頻,以模擬輪胎的滾動。 (a)100分頻 (b)10分頻42沐風(fēng)書屋eLibrary ieee;Use ieee.std_logi

26、c_1164.all;entity fp is port(clr,clk:in std_logic; newclk:out std_logic);end fp;architecture behav of fp issignal tem:integer range 0 to 99;begin process(clk,clr) begin if(clr=1)then tem=0; newclk=0; elsif(clkevent and clk=1)then if(tem=99)then tem=0; newclk=1; else tem=tem+1; newclk=0; end if; end

27、if; end process;end behav;43沐風(fēng)書屋eLibrary ieee;Use ieee.std_logic_1164.all;entity fp10 is port(clr,clk:in std_logic; newclk:out std_logic);end fp10;architecture behav of fp10 issignal tem:integer range 0 to 9;begin process(clk,clr) begin if(clr=1)then tem=0; newclk=0; elsif(clkevent and clk=1)then if

28、(tem=9)then tem=0; newclk=1; else tem=tem+1; newclk=0; end if; end if; end process;end behav;44沐風(fēng)書屋e顯示模塊45沐風(fēng)書屋elibrary ieee;use ieee.std_logic_1164.all;entity sev_yima isport(s:in std_logic_vector(3 downto 0); q:out std_logic_vector(6 downto 0);end sev_yima;architecture rtl of sev_yima isbegin with

29、s select q= 1000000when 0000, 1111001when 0001, 0100100when 0010, 0110000when 0011, 0011001when 0100, 0010010when 0101, 0000010when 0110, 1111000when 0111, 0000000when 1000, 0010000when 1001, 1111111when others;end rtl;46沐風(fēng)書屋e實例3 頻率計設(shè)計要求:對輸入信號進(jìn)行頻率的測量并實時顯示。47沐風(fēng)書屋e 分頻器模塊時鐘信號源輸出的時鐘信號頻率高達(dá)50MHz,經(jīng)過分頻器將其分頻

30、為1Hz、4Hz、500Hz和1000Hz時鐘信號。這四種信號再經(jīng)過1/2分頻,得到時間基準(zhǔn)信號,其中1000Hz的時鐘基準(zhǔn)信號用于動態(tài)掃描譯碼電路,1Hz的時鐘基準(zhǔn)信號用于計數(shù)器的始能信號。48沐風(fēng)書屋elibrary ieee;use ieee.std_logic_1164.all; entity fenpin is port( clk: in std_logic;-50MHz clk1: out std_logic;-1Hz clk2: out std_logic;-4Hz clk3: out std_logic;-500hz clk4: out std_logic -1khz );en

31、d fenpin;architecture arch of fenpin isbeginprocess(clk) variable cnt1: integer range 0 to 49999999; variable cnt2: integer range 0 to 12499999; variable cnt3: integer range 0 to 99999; variable cnt4: integer range 0 to 49999; variable x1,x2,x3,x4: std_logic:=0;begin if clkevent and clk=1 then if cn

32、t149999999 then cnt1:=cnt1+1; else cnt1:=0; x1:=not x1; end if; if cnt212499999 then cnt2:=cnt2+1; else cnt2:=0; x2:=not x2; end if; if cnt299999 then cnt3:=cnt3+1; else cnt3:=0; x3:=not x3; end if; if cnt449999 then cnt4:=cnt4+1; else cnt4:=0; x4:=not x4; end if; end if; clk1=x1; clk2=x2; clk3=x3;

33、clk4=x4;end process;end arch;49沐風(fēng)書屋e 計數(shù)器模塊計數(shù)器模塊始能端door輸入分頻器模塊分頻出的0.5Hz為基準(zhǔn)時鐘信號頻率。計數(shù)器sig輸入待測信號與基準(zhǔn)時鐘信號進(jìn)行比較,并且計數(shù)。q03.0對應(yīng)的是個位輸出,q13.0對應(yīng)的是十位輸出,q23.0對應(yīng)的是百位輸出,q33.0對應(yīng)的是千位輸出。50沐風(fēng)書屋elibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity measure is port( sig,door: in std_logic; q3,q2,q

34、1,q0,dang: out std_logic_vector(3 downto 0) );end measure;architecture arch of measure is signal c0,c1,c2,c3,c4,c5,c6 : std_logic_vector(3 downto 0):=0000; signal suo : std_logic;-lock the count numberbeginprocess(door,sig)begin51沐風(fēng)書屋eif sigevent and sig=1 then if door=1 then suo=1; if c01001 then c

35、0=c0+1; else c0=0000; if c11001 then c1=c1+1; else c1=0000; if c21001 then c2=c2+1; else c2=0000; if c31001 then c3=c3+1; else c3=0000; if c41001 then c4=c4+1; else c4=0000; if c51001 then c5=c5+1; else c5=0000; if c61001 then c6=c6+1; else52沐風(fēng)書屋e c6=0000; end if; end if; end if; end if; end if; end

36、 if; end if; else -to if door=1 c0=0000;c1=0000;c2=0000;c3=0000; c4=0000;c5=0000;c6=0000;suo=0; if suo=1 then if c6/=0000 then q3=c6;q2=c5;q1=c4;q0=c3;dang=0100; elsif c5/=0000 then q3=c5;q2=c4;q1=c3;q0=c2;dang=0010; elsif c4/=0000 then q3=c4;q2=c3;q1=c2;q0=c1;dang=0010; else q3=c3;q2=c2;q1=c1;q0=c0

37、;dang=0001; end if; else null; end if; end if; -to if door=1 else null; -to if sigevent and sig=1 then end if;end process;end arch;53沐風(fēng)書屋e鎖存器模塊鎖存器模塊主要由1個鎖存器組成,主要作用是鎖存計數(shù)器的計數(shù)值。設(shè)置鎖存器可以使數(shù)據(jù)顯示穩(wěn)定可靠,不會由于周期性的清零信號而使數(shù)碼管不斷閃爍。鎖存信號由控制電路產(chǎn)生,在1個周期的計數(shù)時間結(jié)束時,鎖存器立即鎖存計數(shù)值。鎖存器的數(shù)據(jù)輸入端與計數(shù)器數(shù)據(jù)輸出端連接,數(shù)據(jù)輸出與動態(tài)掃描譯碼電路中的顯示譯碼電路連接,時鐘輸入端

38、與基準(zhǔn)時鐘電路端連接。在信號的上升沿,將計數(shù)器中的測量數(shù)據(jù)存入鎖存器。a23.0對應(yīng)的是個位輸入,a33.0對應(yīng)的是十位輸入,a43.0對應(yīng)的是百位輸入,a53.0對應(yīng)的是千位輸入,q23.0對應(yīng)的是個位輸出,q33.0對應(yīng)的是十位輸出,q43.0對應(yīng)的是百位輸出,q53.0對應(yīng)的是千位輸出鎖存,clk連接的是分頻器分頻出的1000HZ的信號。 54沐風(fēng)書屋elibrary ieee;use ieee.std_logic_1164.all;entity lock is port( clk: in std_logic; a5,a4,a3,a2,a1,a0: in std_logic_vector

39、(3 downto 0); q5,q4,q3,q2,q1,q0: out std_logic_vector(3 downto 0) );end lock;architecture arch of lock issignal aa5,aa4,aa3,aa2,aa1,aa0: std_logic_vector(3 downto 0);beginprocess(clk)begin if clkevent and clk=0 then aa5=a5;aa4=a4;aa3=a3;aa2=a2;aa1=a1;aa0=a0; end if; q5=aa5;q4=aa4;q3=aa3;q2=aa2;q1=aa

40、1;q0=aa0;end process;end arch;55沐風(fēng)書屋e譯碼器模塊譯碼器模塊主要由4個顯示模塊組成。主要功能是將鎖存器保存的4位二進(jìn)制計數(shù)值轉(zhuǎn)換成相應(yīng)的數(shù)碼管顯示代碼,顯示模塊輸出端與4個7段數(shù)碼管相連,可以在數(shù)碼管上顯示所測頻率的十進(jìn)制輸出值。d3.0對應(yīng)的是譯碼信號的輸入,q6.0對應(yīng)的是譯碼信號的輸出。 56沐風(fēng)書屋e57沐風(fēng)書屋e58沐風(fēng)書屋e59沐風(fēng)書屋e實例4 交通燈模擬系統(tǒng)設(shè)計結(jié)合DEII實際,擬用不同顏色發(fā)光二極管模擬南北方向和東西方向的紅綠燈;每個方向有紅、綠、黃三個燈,并能對綠燈放行時間進(jìn)行設(shè)置和調(diào)整。60沐風(fēng)書屋e控制模塊設(shè)計 本模塊主要實現(xiàn)對兩個方向紅

41、綠燈的交替顯示控制。 其中Clock是時鐘源,為分頻模塊的輸出信號;hold是控制信號 ,起保持功能; countnum是計數(shù)模塊的輸出信號,為一個周期的循環(huán)計數(shù)值;numa是a組交通燈輸出;numb是b組交通燈輸出; reda是a組紅燈輸出;greenda是a組綠燈輸出;yellowa是a組黃燈輸出;redb是b組紅燈輸出;greendb是b組綠燈輸出;yellowb是a組黃燈輸出;flash是閃爍輸出 61沐風(fēng)書屋elibrary ieee;use ieee.std_logic_1164.all;entity controller isport(clock:in std_logic; ho

42、ld: in std_logic; countnum:in integer range 0 to 49; numa,numb:out integer range 0 to 25; reda,greena,yellowa:out std_logic; redb,greenb,yellowb:out std_logic; flash:out std_logic);end controller;architecture arch of controller isbegin process(clock) begin if falling_edge(clock) then if hold=0 then

43、reda=0; redb=0; greena=1; greenb=1; yellowa=1; yellowb=1; flash=1; else flash=0;- if countnum=19 then numa=20-countnum; reda=1;greena=0; yellowa=1; elsif countnum=24 then numa=25-countnum; reda=1; greena=1; yellowa=0; else numa=50-countnum; reda=0; greena=1; yellowa=1; end if;62沐風(fēng)書屋e- if countnum=24

44、 then numb=25-countnum; redb=0; greenb=1; yellowb=1; elsif countnum=44 then numb=45-countnum; redb=1; greenb=0; yellowb=1; else numb=50-countnum; redb=1; greenb=1; yellowb=0; end if; end if; end if;end process;end arch;63沐風(fēng)書屋e計數(shù)模塊設(shè)計 本模塊主要實現(xiàn)一個周期的循環(huán)計數(shù),在此以50秒為一個周期進(jìn)行循環(huán)計數(shù),當(dāng)然可以根據(jù)實際情況進(jìn)行調(diào)整,如調(diào)整為60秒或120秒。0-50

45、的計數(shù)范圍用二進(jìn)制表示則需要六位,因此本模塊的計數(shù)輸出為六位,如果需要調(diào)整計數(shù)周期,則計數(shù)的輸出位數(shù)需要相應(yīng)調(diào)整。64沐風(fēng)書屋elibrary ieee;use ieee.std_logic_1164.all;entity counter isport(clock:in std_logic; reset:in std_logic; hold: in std_logic; countnum:buffer integer range 0 to 49);end counter;architecture arch of counter isbegin process(reset ,clock) beg

46、in if reset=0 then countnum=0; elsif rising_edge(clock) then if hold=0 then countnum=countnum; else if countnum=49 then countnum=0; else countnum=20 then num1=2; num2=10 then num1=1; num2=numin-10; else num1=0; num2 reg_clr cnt3:=cnt3+1; if x=1then if cnt3=27 then-一個編碼的長度為4a,約27個時鐘周期 reg_clr=1;state

47、1:=t0; else state1:=t1; end if; else state1:=t0; end if; end case; end if;end process pro1;85沐風(fēng)書屋e-進(jìn)程pro2:對紅外接收信號解碼pro2:process(clk,reg_clr,state,flag)begin if(reg_clr=1)then state=s0;reg12 cnt1=0;cnt2=0;reg_bell=0; reg12=000000000000; if x=0then state cnt1=4 then state=s2; else state -接收到的信號為1 cnt2

48、=cnt2+1;reg12=reg12(10 downto 0)&1; if cnt2=11 then state=s4; else state -接收到的信號為0 cnt2=cnt2+1;reg12=reg12(10 downto 0)&0; if cnt2=11 then state=s4; -是否接收完12位編碼 else state -已接收到12位編碼,并進(jìn)行校驗處理 state=s0; if flag=0 then qreg12=reg12;flag=1; else flag=0; if reg12=qreg12 then z=reg12;state=s0;reg_bell=1;

49、else z cnt1=0; if x=0then state bell cnt4:=cnt4+1; bell reg2=00000001; if control=1 then reg1=1;-按鍵1 else reg1 reg2=00000010; if control=1 then reg1=1;-2 else reg1 reg2=00000011; if control=1 then reg1=1;-3 else reg1 reg2=00000100; if control=1 then reg1=1;-4 else reg1 reg2=00000101; if control=1 th

50、en reg1=1;-5 else reg1 reg2=00000110; if control=1 then reg1=1;-6 else reg1reg2=00000111;reg1reg2=00001000;reg1reg2=00001001;reg1reg2=00010000;reg1reg2=00010001;reg1reg2=00010010;reg1reg2=00010011;reg1reg2=00010100;reg1reg2=00010101;reg1reg2=00010110;reg1reg2=00010111;reg1reg2=00011000;reg1reg2=0000

51、0000;reg1=0; end case; end if; end process; BCD1=reg2;LED1=reg1;LED2=z(11 downto 9);end behav;94沐風(fēng)書屋e(1)當(dāng)接收到遙控器的連續(xù)鍵6,設(shè)遙控器用戶碼為“111”,即Z為“111100000001”時,譯碼器的輸出BCD1為“00000110”,3個顯示用戶碼的二極管全亮,LED2為“111”,且當(dāng)control=1時,連續(xù)鍵指示燈亮(LED1=1), 當(dāng)接收到遙控器的單擊鍵7,設(shè)遙控器用戶碼為“111”,即Z為“111010100000”時,譯碼器的輸出BDC為“00000111”,3個顯示用戶

52、碼的二極管全亮,LED2為“111”,連續(xù)鍵指示燈滅(LED1=0), 95沐風(fēng)書屋e 鍵盤掃描模塊當(dāng)有鍵被按下時,對掃描輸出keyout進(jìn)行編碼,輸出兩個4位BCD碼,同時蜂鳴器響。其中,鍵盤上的按鍵16對應(yīng)著遙控器的連續(xù)鍵16,當(dāng)鍵盤按鍵16被按下時,蜂鳴器開始響,直到按鍵被松開為止;鍵盤上的按鍵718對應(yīng)著遙控器的單擊鍵718,無論被按下多久,蜂鳴器只會響很短的滴的一聲,本程序中設(shè)為30個clk。 96沐風(fēng)書屋elibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity Keyboard

53、isport (clk:in std_logic;-時鐘頻率16kHz keyin:in std_logic_vector(17 downto 0);-18位鍵盤輸入 LED1:out std_logic;-區(qū)分連續(xù)按鍵和單機(jī)按鍵 bell:out std_logic; sel:out std_logic; BCD2:out std_logic_vector(7 downto 0);-BCD碼輸出end Keyboard;architecture behav of Keyboard is type state_type is (s0,s1); signal pre_state,next_sta

54、te:state_type:=s0; signal reg1:std_logic; -暫存LED1值 signal reg2:std_logic_vector(7 downto 0);-暫存BCD碼begin pro1:process(clk) begin if rising_edge(clk)then pre_state reg2=00000001;reg1=1;bell=1;state:=t0;sel reg2=00000010;reg1=1;bell=1;state:=t0;sel reg2=00000011;reg1=1;bell=1;state:=t0;sel reg2=000001

55、00;reg1=1;bell=1;state:=t0;sel reg2=00000101;reg1=1;bell=1;state:=t0;sel reg2=00000110;reg1=1;bell=1;state:=t0;selreg2=00000111;reg1=0;sel cnt:=0;bell cnt:=cnt+1;bell cnt:=0;bellreg2=00001000;reg1=0;sel cnt:=0;bell cnt:=cnt+1;bell cnt:=0;bellreg2=00001001;reg1=0;sel cnt:=0;bell cnt:=cnt+1;bell cnt:=

56、0;bellreg2=00010000;reg1=0;sel cnt:=0;bell cnt:=cnt+1;bell cnt:=0;bellreg2=00010001;reg1=0;sel cnt:=0;bell cnt:=cnt+1;bell cnt:=0;bellreg2=00010010;reg1=0;sel cnt:=0;bell cnt:=cnt+1;bell cnt:=0;bellreg2=00010011;reg1=0;sel cnt:=0;bell cnt:=cnt+1;bell cnt:=0;bellreg2=00010100;reg1=0;sel cnt:=0;bell c

57、nt:=cnt+1;bell cnt:=0;bellreg2=00010101;reg1=0;sel cnt:=0;bell cnt:=cnt+1;bell cnt:=0;bellreg2=00010110;reg1=0;sel cnt:=0;bell cnt:=cnt+1;bell cnt:=0;bellreg2=00010111;reg1=0;sel cnt:=0;bell cnt:=cnt+1;bell cnt:=0;bellreg2=00011000;reg1=0;sel cnt:=0;bell cnt:=cnt+1;bell cnt:=0;bellreg2=00000000;reg1

58、=0;bell=0;state:=t0;sel=0; end case; end if; end process pro2; LED1=reg1; BCD2=reg2; end behav;104沐風(fēng)書屋e對鍵盤掃描模塊進(jìn)行仿真編譯,當(dāng)沒有按鍵按下時,LED1,BCD2,bell都為低電平。當(dāng)分別按下連續(xù)鍵16時,LED1,bell高電平的時間與按鍵按住的時間相同,直到松開按鍵為止,根據(jù)仿真波形,對16鍵的BCD2譯碼正確。當(dāng)按下單擊鍵718時,LED1指示燈熄滅,蜂鳴器只響很短的一段時間(30個clk),根據(jù)仿真波形,對718鍵的BCD2譯碼正確。 105沐風(fēng)書屋eDEII板除了用3個發(fā)光二

59、極管指示用戶碼外,還將用戶碼用一個7段數(shù)碼管顯示。用戶碼、按鍵個位以及按鍵的十位分別用三個7段數(shù)碼管顯示。按鍵有遙控器和鍵盤兩種,這里模仿電視機(jī)將鍵盤的優(yōu)先級設(shè)為最高。以Keyboard模塊的sel輸出信號作為鍵盤按鍵的指示信號sel,當(dāng)sel為高電平說明鍵盤有按鍵被按下。 106沐風(fēng)書屋elibrary ieee;use ieee.std_logic_1164.all;entity display is port(clk:in std_logic; sel:in std_logic; -判斷鍵盤輸入還是遙控板輸入 BCD1:in std_logic_vector(7 downto 0); -

60、鍵盤BCD碼輸入 BCD2:in std_logic_vector(7 downto 0); -遙控板BCD碼輸入 user_BCD:in std_logic_vector(3 downto 0); -用戶碼輸入 a:out std_logic_vector(3 downto 0); -個位BCD碼輸出 b:out std_logic_vector(3 downto 0); -十位BCD碼輸出 c:out std_logic_vector(3 downto 0); -用戶碼輸出end display;architecture behav of display isbegin process(c

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論