【正文】
。 以下為發(fā)光二極管組合譯碼電路,表示球的位置 WITH led_pos SELECT led_out = 00011000 when 0, 10011000 when 1, 01011000 when 2, 00111000 when 3, 00001000 when 4, 00010000 when 5, 00011100 when 6, 00011010 when 7, 00011001 when 8, 00011000 when 9。 end if。 end if。= state = p2ready。 when 39。039。 state = waiting。 狀態(tài)轉(zhuǎn)移至等待裁判開始 elsif(score2 = 11) then p2total = 39。139。039。039。 end if。 else led_pos = led_pos 1。139。 end if。139。) then if(led_pos = 2) then state = p1top2。 when p2top1= if(p1 = 39。 球繼續(xù)移動 state = p1top2。 p1方得分 state = ends。 elsif(led_pos = 9) then 球“出界“ p1win = 39。 擊球失誤,p1方得分 state = ends。擊球成功 else p1win = 39。139。 end if。) then state = p2top1。 if(p2 = 39。039。 end if。) then state = p1top2??拷l(fā)球方的發(fā)光二極管被點亮(下同) if(p1 = 39。039。 end if。 end if。state=p1ready。= first=39。 when 39。139。039。 END CASE。139。139。state=p1ready。= first=39。 送至分數(shù)統(tǒng)計模塊,清除比分 if(total = 0 OR total = 2 OR total = 4 OR total = 6) then CASE sel IS when 39。) then clear = 39。 if(judge = 39。039。039。039。039。) then state = waiting。BEGIN PROCESS(clk,judge,reset) BEGIN if(reset=39。 表示當(dāng)前發(fā)光二極管被點亮的位置TYPE statetype IS (waiting,p1ready,p2ready,p1top2,p2top1,ends)。發(fā)光二極管的顯示END ENTITY。 總比分和 p1total,p2total,p1win,p2win,clear,first: OUT STD_LOGIC。低頻時鐘,發(fā)球/擊球,裁判,當(dāng)前發(fā)球權(quán),首發(fā)權(quán)選擇,全局復(fù)位 score1,score2: IN integer range 0 to 11。use 。use 。END ARCHITECTURE。 total1 = total_1。 end if。 end if。139。139。) then total_2 =0。 PROCESS(p2total,reset,ends,reset_all) BEGIN if(reset_all = 39。 end if。 比賽重新開始,總比分清零 end if。139。139。) then 全局復(fù)位 total_1 = 0。BEGIN PROCESS(p1total,reset,ends,reset_all) BEGIN if(reset_all = 39。END ENTITY。ENTITY total_stat IS port(p1total,p2total,reset,reset_all,ends: IN STD_LOGIC。use 。// 程序名稱:// 程序作者:陳 梁// 最后修改日期:200932library ieee。139。039。 END PROCESS。 PROCESS(clk_out_5hz) BEGIN if(rising_edge(clk_out_5hz)) then clk_out_2hz = NOT clk_out_2hz。 end if。 else count := count + 1。記數(shù)器,分為5Hz BEGIN if(rising_edge(clk)) then if(count = 99999) then count := 0。ARCHITECTURE main OF clk_div ISSIGNAL clk_out_2hz,clk_out_5hz:STD_LOGIC。clk為1MHz高頻時鐘輸入,sel為分頻輸出選擇 clk_out:OUT STD_LOGIC)。use 。use 。END ARCHITECTURE。 end if。 count = count + 1。digit = d6。digit = d5。digit = d4。digit = d3。digit = d2。digit = d1。 PROCESS(clk) BEGIN if(rising_edge(clk)) then 掃描數(shù)碼管 if(count=6) then count = 0。 END CASE。 when 3= d6 = 1111001。 when 1= d6 = 0110000。 END CASE。 when 3= d5 = 1111001。 when 1= d5 = 0110000。 END PROCESS。 d4 = 0110000。 d4 = 1111110。 d4 = 1111011。 d4 = 1111111。 d4 = 1110000。 d4 = 1011111。 d4 = 1011011。 d4 = 0110011。 d4 = 1111001。 d4 = 1101101。 d4 = 0110000。 d4 = 1111110。 END CASE。 when 11=d1 = 0110000。 when 10=d1 = 0110000。 when 9= d1 = 0000000。 when 8= d1 = 0000000。 when 7= d1 = 0000000。 when 6= d1 = 0000000。 when 5= d1 = 0000000。 when 4= d1 = 0000000。 when 3= d1 = 0000000。 when 2= d1 = 0000000。 when 1= d1 = 0000000。BEGIN PROCESS(score1,score2) BEGIN 以下為分數(shù)譯碼進程 CASE score1 IS when 0= d1 = 0000000。ARCHITECTURE main OF score_show ISSIGNAL count:integer range 0 to 5。數(shù)碼管選通 digit:OUT STD_LOGIC_VECTOR(6 downto 0))。 total1,total2: IN integer range 0 to 4。ENTITY score_show IS PORT(clk: IN STD_LOGIC。use 。// 程序名稱:// 程序作者:陳 梁// 最后修改日期:200932library ieee。 score2 = score_2。 END PROCESS。 elsif(rising_edge(p2win)) then score_2 = score_2 + 1。139。139。 END PROCESS。 復(fù)位,比分清零 elsif(rising_edge(p1win)) then 檢測到P1得分信號(高電平) score_1 = score_1 + 1。139。139。ARCHITECTURE main OF score_stat ISSIGNAL score_1,score_2:integer range 0 to 11。得分信號,比分清零,全局復(fù)位 score1,score2: OUT integer range 0 to 11)。use 。use 。 U4: total_stat PORT MAP(p1total=p1total,p2total=p2total,total1=total1,total2=total2,reset=clear,reset_all=reset,ends=ends)。 U2: control PORT MAP(clk = clk_temp,p1 = p1,p2 = p2,judge=judge,reset = reset,who=who,first=first,sel=first_sel,clear=clear,score1 = score1,score2=score2,p1win=p1win,p2win=p2win,p1total=p1total,p2total=p2total,led_out=led,total=total)。END COMPONENT。 cat:OUT STD_LOGIC_VECTOR(5 downto 0)。 score1,score2: IN integer range 0 to 11。END COMPONENT。 total: OUT integer range 0 to 7。 score1,score2: IN integer range 0 to 11。END COMPONENT。COMPONENT total_stat IS PORT(p1total,p2total,reset,ends,reset_all: IN STD_LOGIC。 score1,score2: OUT integer range 0 to 11)。發(fā)光二極管的顯示END COMPONENT。 p1total,p2total,p1win,p2win,cle