【正文】
out,jiafen_out,qingling_out) 記分進(jìn)程,實(shí)現(xiàn)加分、分?jǐn)?shù)清零以及清零按鍵按下時(shí)蜂鳴器發(fā)聲響應(yīng) variable jishu_ge:integer range 0 to 10。個(gè)位計(jì)數(shù) variable jishu_shi:integer range 0 to 10。十位計(jì)數(shù) variable hebing:std_logic_vector(1 downto 0)。 variable add:integer range 0 to 4。 variable add1:integer range 0 to 4。 begin hebing:=jiafen_out amp。 jianfen_out。 if qingling_out=39。039。 then jishu_ge:=0。 jishu_shi:=0。 feng_ming_qi=laba_maichong。 else feng_ming_qi=39。039。 if clkin39。event and clkin=39。139。 then if hebing=01 then add:=add+1。 if add1 then add:=2。 else if jishu_ge=9 then jishu_ge:=0。 if jishu_shi=9 then jishu_shi:=0。 else jishu_shi:=jishu_shi+1。 end if。 else jishu_ge:=jishu_ge+1。 end if。 end if。 elsif hebing=10 then add1:=add1+1。 if add11 then add1:=2。 else if jishu_shi=0 then if jishu_ge=0 then null。 else jishu_ge:=jishu_ge1。 end if。 else if jishu_ge=0 then jishu_ge:=9。 jishu_shi:=jishu_shi1。 else jishu_ge:=jishu_ge1。 end if。 end if。 end if。 elsif hebing=11 then add:=0。 add1:=0。 else null。 end if。 end if。 end if。 leda1=jishu_shi。 leda0=jishu_ge。 end process。 xianshiled1:process(leda1) 分?jǐn)?shù)的十位上的數(shù)字顯示進(jìn)程 begin case leda1 is when 0 = led1=B1111110。 when 1 = led1=B0110000。 when 2 = led1=B1101101。 when 3 = led1=B1111001。 when 4 = led1=B0110011。 when 5 = led1=B1011011。 when 6 = led1=B1011111。 when 7 = led1=B1110000。 when 8 = led1=B1111111。 when 9 = led1=B1111011。 when others = led1=B0000000。 end case。 end process。 xianshiled0:process(leda0) 分?jǐn)?shù)的個(gè)位上的數(shù)字顯示進(jìn)程 begin case leda0 is when 0 = led0=B1111110。 when 1 = led0=B0110000。 when 2 = led0=B1101101。 when 3 = led0=B1111001。 when 4 = led0=B0110011。 when 5 = led0=B1011011。 when 6 = led0=B1011111。 when 7 = led0=B1110000。 when 8 = led0=B1111111。 when 9 = led0=B1111011。 when others = led0=B0000000。 end case。 end process。end architecture c。(2)去抖程序:library ieee。use 。use 。use 。entity qudou is port(anjian_in:in std_logic。按鍵信號(hào)輸入 anjian_out:out std_logic。按鍵信號(hào)輸出 clkin:in std_logic。時(shí)鐘信號(hào)5Mhz res:in std_logic復(fù)位信號(hào) )。end entity qudou。architecture b of qudou is ponent fenpin is分頻元件定義 generic(n:integer:=1)。類屬參數(shù)定義,修改n的值可實(shí)現(xiàn)2*n分頻 port ( clkin1:in std_logic。 clkout:out std_logic。 res:in std_logic )。 end ponent。signal clk_200hz:std_logic。按鍵去抖檢測(cè)時(shí)鐘信號(hào)T=5msbegin u0: fenpin generic map(1) 參數(shù)傳遞映射語(yǔ)句 port map fenpin元件例化語(yǔ)句 (clkin1=clkin, clkout=clk_200hz, res=res)。 process(clk_200hz) variable count:integer range 0 to 3。脈沖計(jì)數(shù) variable count1:integer range 0 to 1。 begin if clk_200hz39。event and clk_200hz=39。139。 then if anjian_in=39。039。 then if count=2 then count:=0。 count1:=1。 if count1=1 then count1:=0。 anjian_out=39。039。 end if。 else count:=count+1。 anjian_out=39。139。 end if。 else count:=0。 anjian_out=39。139。 end if。 end if。 end process。end architecture b。(3)分頻程序library ieee。use 。use 。use 。entity fenpin isgeneric(n:integer:=1 )。類屬參數(shù)定義修改其值可實(shí)現(xiàn)2*n分頻,默認(rèn)2分頻port(clkin1:in std_logic。被分頻時(shí)鐘信號(hào)輸入 clkout:out std_logic。分頻信號(hào)輸出 res:in std_logic復(fù)位信號(hào) )。end entity fenpin。architecture a of fenpin is signal clkq:std_logic:=39。039。 signal leijia:std_logic_vector(30 downto 0):=(others=39。039。)。對(duì)脈沖計(jì)數(shù)begin process(clkin1,res) begin if res=39。039。 then leijia=(others=39。039。)。 clkq=39。039。 else if(clkin139。event and clkin1=39。139。)then if(leijia=n1) then leijia=(others=39。039。)。 clkq=not clkq。 else leijia=leijia+1。 end if。 end if。 end if。 end process。clkout=clkq。end architecture a。32