FPGA综合设计实例ppt课件

上传人:仙*** 文档编号:167959088 上传时间:2022-11-06 格式:PPT 页数:130 大小:4.66MB
收藏 版权申诉 举报 下载
FPGA综合设计实例ppt课件_第1页
第1页 / 共130页
FPGA综合设计实例ppt课件_第2页
第2页 / 共130页
FPGA综合设计实例ppt课件_第3页
第3页 / 共130页
资源描述:

《FPGA综合设计实例ppt课件》由会员分享,可在线阅读,更多相关《FPGA综合设计实例ppt课件(130页珍藏版)》请在装配图网上搜索。

1、第十章综合设计实例1;.21 键盘扫描与显示矩阵式键盘:行,列矩阵是键盘以行列形式排列,键盘矩阵是键盘以行列形式排列,键盘上每个按键其实是一个开关电路,上每个按键其实是一个开关电路,当某键被按下时,该按键对应的位当某键被按下时,该按键对应的位置就呈现逻辑置就呈现逻辑0状态状态.行扫描方式:逐行送0电平,读取列的状态,以判断按下的键号.列扫描方式:逐列送0电平,读取行的状态,以判断按下的键号.3以行扫描为例以行扫描为例:1给行依次送给行依次送0111,1011,1101,1110信号信号;2读取列电平状态读取列电平状态,4数码管显示5library ieee;use ieee.std_logic

2、_1164.all;use ieee.std_logic_unsigned.all;entity key_scan is port(column:in std_logic_vector(3 downto 0);-列状态列状态 scan_cnt:in std_logic_vector(3 downto 0);-扫描字扫描字 row:out std_logic_vector(3 downto 0);-行状态行状态 key_pressed:out std_logic);-按键有效与否按键有效与否,后续判断为零则为有键按下后续判断为零则为有键按下end;architecture rtl of key_

3、scan isbegin row=1110 when scan_cnt(3 downto 2)=00 else 1101 when scan_cnt(3 downto 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;按

4、键扫描控制程序按键扫描控制程序6按键处理控制模块library ieee;use ieee.std_logic_1164.all;use ieee.std_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;-检测按键有效与否,停止计数.scan_cnt:out std_logic_vector(3 downto 0);-计数end;archit

5、ecture behav of scan_count issignal qscan:std_logic_vector(3 downto 0);begin 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;7按键消抖控制模块按键消抖控制模块library ieee;use ieee.std_logic_1164.

6、all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity debounce 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 8debounce:process(clk,scan_clk,key_pressed)variable dbnq:s

7、td_logic_vector(5 downto 0);begin if(key_pressed=1)then dbnq:=111111;-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 sec

8、ond else key_validbutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_codebutt_code=1111;-fend case;end if;end if;end process;end;11 电锁控制模块电锁控制模块library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;ent

9、ity ctrl is port(data_n:in std_logic_vector(3 downto 0);key_valid,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

10、 is begin process(data_n,key_valid)12begin if data_n=1101 then acc=00000;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)

11、then if nc=4 then if data_n=1110 then reg=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;13enlock=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;14动态扫描显示控制模块动态扫描显示控制模块library ieee;use

12、ieee.std_logic_1164.all;use ieee.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 signa

13、l sel:std_logic_vector(1 downto 0);signal dis:std_logic_vector(3 downto 0);signal db:std_logic_vector(3 downto 0);begin15counter: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;16multiplexe

14、r:block is 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;17181920实例实例1 数字钟设计数字钟设计实时显示时、分、秒实时显示时、分、秒分析:分析:1、最小计时单位:秒。因此,首先要由时钟产生、最小

15、计时单位:秒。因此,首先要由时钟产生1HZ的信号;的信号;2、对秒进行、对秒进行0-59的计数,并且有进位功能,且显示;的计数,并且有进位功能,且显示;3、对分进行、对分进行0-59的计数,并且有进位功能,且显示;的计数,并且有进位功能,且显示;4、对时进行、对时进行0-59的计数,且显示;的计数,且显示;2122library 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_

16、logic_vector(3 downto 0);co:out std_logic);end second;architecture 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:=

17、cnt0+1;else cnt0:=0000;if cnt10101 then cnt1:=cnt1+1;else cnt1:=0000;co=0;end if;end if;end if;sec1=cnt1;sec0 kinside:=0;-停止状态或空挡29 when 001=kinside:=28;-第一档,慢速行驶状态,行驶100m需要28个时钟周期 when 010=kinside:=24;-第二档 when 011=kinside:=20;-第三档 when 100=kinside:=16;-第四档 when 101=kinside:=12;-第五档 when 110=kinsid

18、e:=8;-第六档 when 111=kinside:=4;-第七档,也是速度最大的档 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;-相当于无客户上车 elsif sp=000 then s_state:=s1;-有客户上车,但车速位0,即客户刚上车还未起步 elsif cnt=kinside then cnt:=0;clkout=1;s_state:=s1;el

19、se cnt:=cnt+1;s_state:=s1;end if;end case;end if;end process;end behav;31kilometers模块模块此模块主要用于记录行进的距离。通过对此模块主要用于记录行进的距离。通过对clkout信号的计数,可以计算行驶的距离信号的计数,可以计算行驶的距离kmcount。一个。一个clkout脉冲相当于行进脉冲相当于行进100m,所以只要记录,所以只要记录clkout的脉冲数目即可确定的脉冲数目即可确定共行进的距离。共行进的距离。kmcount1为十分位,为十分位,kmcount2为个位为个位,kmcount3为十位,分别为十进为十

20、位,分别为十进制数。制数。32Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity 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 kil

21、ometers isbegin process(clkout,reset)variable km_reg:std_logic_vector(11 downto 0);begin if reset=1then km_reg:=0;elsif clkoutevent and clkout=1then -km_reg(3 downto 0)对应里程十分位33 if km_reg(3 downto 0)=1001then km_reg:=km_reg+0111;-十分位向个位的进位处理 else km_reg(3 downto 0):=km_reg(3 downto 0)+0001;end if;if

22、 km_reg(7 downto 4)=1010then km_reg:=km_reg+01100000;-个位向十位的进位处理 end if;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;-20

23、s,即1000个clk,产生一个时间计费脉冲 waittime:=0;elsif stop=1then t_state:=t0;elsif sp=000then t_state:=t2;else timecount=0then 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)

24、;variable clkout_cnt:integer range 0 to 10;begin if reset=1 then cash1001 then reg2(7 downto 0):=reg2(7 downto 0)+00000111;if reg2(7 downto 4)1001 then cash=reg2+0;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+0;el

25、se cash=reg2;end 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;4142分频模块对系统的时钟进行分频,以模拟轮胎的滚动。(a)100分频 (b)10分频43Library ieee;Use ieee.std_logic_1164.al

26、l;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 if;end process;end

27、 behav;44Library 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(tem=9)then tem=0;newclk=1;e

28、lse tem=tem+1;newclk=0;end if;end if;end process;end behav;45显示模块46library 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 s select q=1000000when 0000,1111001when 0001,

29、0100100when 0010,0110000when 0011,0011001when 0100,0010010when 0101,0000010when 0110,1111000when 0111,0000000when 1000,0010000when 1001,1111111when others;end rtl;47实例实例3 频率计设计频率计设计要求:对输入信号进行频率的测量并实时显示。要求:对输入信号进行频率的测量并实时显示。48 分频器模块分频器模块时钟信号源输出的时钟信号频率高达50MHz,经过分频器将其分频为1Hz、4Hz、500Hz和1000Hz时钟信号。这四种信号再经

30、过1/2分频,得到时间基准信号,其中1000Hz的时钟基准信号用于动态扫描译码电路,1Hz的时钟基准信号用于计数器的始能信号。49library 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 );end fenpin;architecture arch of fenpin isbeginpr

31、ocess(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 cnt149999999 then cnt1:=cnt1+1;else cnt1:=0;x1:=not x1;end

32、 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;clk4=x4;end process;end arch;50 计数器模块计数器模块计数器模块始能端door输入分频器模块分频出的0.5Hz为基准时钟信

33、号频率。计数器sig输入待测信号与基准时钟信号进行比较,并且计数。q03.0对应的是个位输出,q13.0对应的是十位输出,q23.0对应的是百位输出,q33.0对应的是千位输出。51library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity measure is port(sig,door:in std_logic;q3,q2,q1,q0,dang:out std_logic_vector(3 downto 0);end measure;architecture arch of measure

34、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)begin52if sigevent and sig=1 then if door=1 then suo=1;if c01001 then c0=c0+1;else c0=0000;if c11001 then c1=c1+1;else c1=0000;if c21001 then c2=c2+1;else c2=0000;if c31

35、001 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;else53 c6=0000;end if;end if;end if;end if;end if;end 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

36、 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;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;54锁存

37、器模块锁存器模块锁存器模块主要由1个锁存器组成,主要作用是锁存计数器的计数值。设置锁存器可以使数据显示稳定可靠,不会由于周期性的清零信号而使数码管不断闪烁。锁存信号由控制电路产生,在1个周期的计数时间结束时,锁存器立即锁存计数值。锁存器的数据输入端与计数器数据输出端连接,数据输出与动态扫描译码电路中的显示译码电路连接,时钟输入端与基准时钟电路端连接。在信号的上升沿,将计数器中的测量数据存入锁存器。a23.0对应的是个位输入,a33.0对应的是十位输入,a43.0对应的是百位输入,a53.0对应的是千位输入,q23.0对应的是个位输出,q33.0对应的是十位输出,q43.0对应的是百位输出,q5

38、3.0对应的是千位输出锁存,clk连接的是分频器分频出的1000HZ的信号。55library 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(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_vec

39、tor(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=aa1;q0=aa0;end process;end arch;56译码器模块译码器模块译码器模块主要由4个显示模块组成。主要功能是将锁存器保存的4位二进制计数值转换成相应的数码管显示代码,显示模块输出端与4个7段数码管相连,可以在数码管上显示所测频率的十进制输出值。d3.0对应的是译码信号的输入,q6.0

40、对应的是译码信号的输出。57585960实例实例4 交通灯模拟系统设计交通灯模拟系统设计结合DEII实际,拟用不同颜色发光二极管模拟南北方向和东西方向的红绿灯;每个方向有红、绿、黄三个灯,并能对绿灯放行时间进行设置和调整。61控制模块设计控制模块设计 本模块主要实现对两个方向红绿灯的交替显示控制。本模块主要实现对两个方向红绿灯的交替显示控制。clockholdcountnum5.0numa4.0numb4.0redagreenayellowaredbgreenbyellowbflashcontrollerinst其中其中Clock是时钟源,为分频模块的输出信号;是时钟源,为分频模块的输出信号;

41、hold是控制信号是控制信号,起保持功能,起保持功能;countnum是计数模块的输出信号,为一个周期的循环计数值;是计数模块的输出信号,为一个周期的循环计数值;numa是是a组交通灯输出;组交通灯输出;numb是是b组交通灯输出组交通灯输出;reda是是a组红灯输出;组红灯输出;greenda是是a组绿灯输出;组绿灯输出;yellowa是是a组黄灯输出;组黄灯输出;redb是是b组红灯输出;组红灯输出;greendb是是b组绿灯输出;组绿灯输出;yellowb是是a组黄灯输出;组黄灯输出;flash是闪烁输出是闪烁输出 62library ieee;use ieee.std_logic_11

42、64.all;entity controller isport(clock:in std_logic;hold: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)beg

43、in if falling_edge(clock)then if hold=0 then 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

44、if;63-if countnum=24 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;64计数模块设计计数模块设计 本模块主要实现一个周期的循环计数,在此以本模块主要实现一个周期的循环计数,在此以50秒为一个周期进行循环计数,当然可以秒

45、为一个周期进行循环计数,当然可以根据实际情况进行调整,如调整为根据实际情况进行调整,如调整为60秒或秒或120秒。秒。0-50的计数范围用二进制表示则需要六的计数范围用二进制表示则需要六位,因此本模块的计数输出为六位,如果需要调整计数周期,则计数的输出位数需要相应位,因此本模块的计数输出为六位,如果需要调整计数周期,则计数的输出位数需要相应调整。调整。clockresetholdcountnum5.0counterinst165library ieee;use ieee.std_logic_1164.all;entity counter isport(clock:in std_logic;re

46、set:in std_logic;hold:in std_logic;countnum:buffer integer range 0 to 49);end counter;architecture arch of counter isbegin process(reset,clock)begin 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

47、=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;state1:=t0;else state1:=t1;end if;else state1:=t0;end if;end case;end if;end process pro1;86-进程进程pro2:对红外接收信号解码:对红外接收信号解码pro2:process(clk,reg_clr,state,f

48、lag)begin if(reg_clr=1)then state=s0;reg12 cnt1=0;cnt2=0;reg_bell=0;reg12=0;if x=0then state cnt1=4 then state=s2;else state -接收到的信号为接收到的信号为1 cnt2=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;-是

49、否接收完是否接收完12位编码位编码 else state -已接收到已接收到12位编码,并进行校验处理位编码,并进行校验处理 state=s0;if flag=0 then qreg12=reg12;flag=1;else flag=0;if reg12=qreg12 then z=reg12;state=s0;reg_bell=1;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

50、=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 then reg1=1;-5 else reg1 reg2=00000110;if control=1 then reg1=1;-6 else reg1reg2=00000111;reg1reg2=00001000;reg1reg2=00001001;reg1reg2=000100

51、00;reg1reg2=00010001;reg1reg2=00010010;reg1reg2=00010011;reg1reg2=00010100;reg1reg2=00010101;reg1reg2=00010110;reg1reg2=00010111;reg1reg2=00011000;reg1reg2=00000000;reg1=0;end case;end if;end process;BCD1=reg2;LED1=reg1;LED2=z(11 downto 9);end behav;95(1)当接收到遥控器的连续键)当接收到遥控器的连续键6,设遥控器用户码为,设遥控器用户码为“11

52、1”,即,即Z为为“111100000001”时,时,译码器的输出译码器的输出BCD1为为“00000110”,3个显示用户码的二极管全亮,个显示用户码的二极管全亮,LED2为为“111”,且当,且当control=1时,连续键指示灯亮(时,连续键指示灯亮(LED1=1),),当接收到遥控器的单击键当接收到遥控器的单击键7,设遥控器用户码为,设遥控器用户码为“111”,即,即Z为为“111010100000”时,译码时,译码器的输出器的输出BDC为为“00000111”,3个显示用户码的二极管全亮,个显示用户码的二极管全亮,LED2为为“111”,连续键指,连续键指示灯灭(示灯灭(LED1=0

53、),),96 键盘扫描模块当有键被按下时,对扫描输出当有键被按下时,对扫描输出keyout进行编码,输出两个进行编码,输出两个4位位BCD码,同时蜂鸣器响。码,同时蜂鸣器响。其中,键盘上的按键其中,键盘上的按键16对应着遥控器的连续键对应着遥控器的连续键16,当键盘按键,当键盘按键16被按下时,蜂被按下时,蜂鸣器开始响,直到按键被松开为止;键盘上的按键鸣器开始响,直到按键被松开为止;键盘上的按键718对应着遥控器的单击键对应着遥控器的单击键718,无论被按下多久,蜂鸣器只会响很短的滴的一声,本程序中设为无论被按下多久,蜂鸣器只会响很短的滴的一声,本程序中设为30个个clk。clkkeyin17

54、.0LED1bellselBCD27.0Keyboardinst297library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity Keyboard isport(clk:in std_logic;-时钟频率时钟频率16kHz keyin:in std_logic_vector(17 downto 0);-18位键盘输入位键盘输入 LED1:out std_logic;-区分连续按键和单机按键区分连续按键和单机按键 bell:out std_logic;sel:out std_logic;BCD2

55、: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_state: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 pr

56、e_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=00000100;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:

57、=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:=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;

58、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 cnt:=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;bellr

59、eg2=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=0;bell=0;state:=t0;sel=0;end case;end if;end process pro2;LED1=reg1;BCD2=reg2;end behav;105对键盘扫描模块进行仿真编译,当没有按键按下时,对键盘扫描模块进行仿真编译,当没有按键按下时,LED1,BCD2,bell都为低

60、电平。当都为低电平。当分别按下连续键分别按下连续键16时,时,LED1,bell高电平的时间与按键按住的时间相同,直到松开按键高电平的时间与按键按住的时间相同,直到松开按键为止,根据仿真波形,对为止,根据仿真波形,对16键的键的BCD2译码正确。当按下单击键译码正确。当按下单击键718时,时,LED1指示灯指示灯熄灭,蜂鸣器只响很短的一段时间(熄灭,蜂鸣器只响很短的一段时间(30个个clk),根据仿真波形,对),根据仿真波形,对718键的键的BCD2译码译码正确。正确。106DEII板除了用板除了用3个发光二极管指示用户码外,还将用户码用一个个发光二极管指示用户码外,还将用户码用一个7段数码管

61、显示。用户码、按键段数码管显示。用户码、按键个位以及按键的十位分别用三个个位以及按键的十位分别用三个7段数码管显示。段数码管显示。按键有遥控器和键盘两种,这里模仿电视机将键盘的优先级设为最高。以按键有遥控器和键盘两种,这里模仿电视机将键盘的优先级设为最高。以Keyboard模块的模块的sel输出信号作为键盘按键的指示信号输出信号作为键盘按键的指示信号sel,当,当sel为高电平说明键盘有按键被按下。为高电平说明键盘有按键被按下。clkselBCD17.0BCD27.0user_BCD3.0a3.0b3.0c3.0displayinst4107library ieee;use ieee.std_

62、logic_1164.all;entity display is port(clk:in std_logic;sel:in std_logic;-判断键盘输入还是遥控板输入判断键盘输入还是遥控板输入 BCD1:in std_logic_vector(7 downto 0);-键盘键盘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);-个位个位B

63、CD码输出码输出 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(clk)variable cnt:integer range 0 to 1;begin if rising_edge(clk)then if sel=1 then -键盘输入键盘输入 a=BCD2(3 downto 0);b=BCD2(7 downto 4);c=user_

64、BCD;else a=BCD1(3 downto 0);b=BCD1(7 downto 4);c=user_BCD;end if;end if;end process;end behav;108由解码得到的由解码得到的4位位BCD码,需经过显示译码模块的译码才能显示。此模块采用了元件例码,需经过显示译码模块的译码才能显示。此模块采用了元件例化,把原本三个译码器集合在一个译码器中。化,把原本三个译码器集合在一个译码器中。a3.0b3.0c3.0g6.0s6.0user6.0disinst5109library ieee;use ieee.std_logic_1164.all;entity dis

65、 is port(a,b,c:in std_logic_vector(3 downto 0);g,s,user:out std_logic_vector(6 downto 0);end dis;architecture behav of dis is component yima -元件例化 port(BCD:in std_logic_vector(3 downto 0);Y:out std_logic_vector(6 downto 0);end component;begin u1:yima port map(a,g);u2:yima port map(b,s);u3:yima port

66、map(c,user);end behav;110设置本机用户码为设置本机用户码为“111”,所以当按下,所以当按下DEII板的键盘按键时,显示用户码为板的键盘按键时,显示用户码为7。当接收到遥。当接收到遥控器的信号时,用户码由发射板电路决定。在本设计中,以键盘输入优先,故用控器的信号时,用户码由发射板电路决定。在本设计中,以键盘输入优先,故用keyboard模块输出的模块输出的sel信号作为控制信号信号作为控制信号use_sel,当,当use_sel为高电平时说明键盘有键按下,寄存为高电平时说明键盘有键按下,寄存本机用户码,否则当接收到红外遥控器信号时,寄存红外遥控器的用户码。本机用户码,否则当接收到红外遥控器信号时,寄存红外遥控器的用户码。clkuse_seluse_in2.0use_BCD3.0userinst6111library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity user is port(clk:in std_logic;use_sel:in std_logic;us

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!