【文章內(nèi)容簡介】
cg:=0000。secs:=0000。co=39。139。 elsif secg=1001 then secs:=secs+1。secg:=0000。co=39。039。 elsif secg1001 then secg:=secg+1。 end if。當(dāng)計(jì)數(shù)個(gè)位為9,十位為5,計(jì)數(shù)值為59時(shí),秒的個(gè)位十位都為零,進(jìn)位為一,說明此時(shí)計(jì)數(shù)為一分鐘。秒的個(gè)位一直計(jì)數(shù),計(jì)數(shù)值不到9時(shí),一直加,直到出現(xiàn)個(gè)位出現(xiàn)9,十位加一。 模式選擇模塊的軟件設(shè)計(jì) entity slc is port( add: in std_logic_vector(2 downto 0)。 sel:in std_logic。 naout,clkout : out std_logic_vector(2 downto 0))。end entity。architecture art of slc is begin process(sel,add) begin if(sel=39。139。) then sel為一時(shí),鬧鐘模式開啟,否則繼續(xù)時(shí)鐘的顯示 naout=add。 else clkout=add。 數(shù)碼管 位選和段選 architecture art of sel is signal data: std_logic_vector(3 downto 0)。 begin process(sel,f0,f1,f2,f3,f4,f5) begin case sel is 數(shù)碼管的位選,數(shù)碼管為共陽極的,秒分時(shí)共用六個(gè) when 000=data=f0。wei=111110。數(shù)碼管顯示 when 001=data=f1。wei=111101。 when 010=data=f2。wei=111011。 when 011=data=f3。wei=110111。 when 100=data=f4。wei=101111。 when 101=data=f5。wei=011111。 when others=data=f0。wei=111111。 end case。 end process。 process(data,sel) begin if sel=010 or sel=100 then 若是第二個(gè)或是第四個(gè)數(shù)碼管亮,則低位的兩個(gè)點(diǎn)要顯示,低電平有效。 case data is when0000=du=01000000。 when0001=du=01111001。 when0010=du=00100100。 when0011=du=00110000。 when0100=du=00011001。 when0101=du=00010010。 when0110=du=00000010。 when0111=du=01111000。 when1000=du=00000000。 when1001=du=00010000。 when others=du=01000000。 end case。 else case data is when0000=du=11000000。 when0001=du=11111001。 when0010=du=10100100。 when0011=du=10110000。 when0100=du=10011001。 when0101=du=10010010。 when0110=du=10000010。 when0111=du=11111000。 when1000=du=10000000。 when1001=du=10010000。 when others=du=11000000。 段選 end case。 end if。 end process。 鬧鐘模塊的軟件設(shè)計(jì) 鬧鐘能否正常計(jì)數(shù)、能否對計(jì)時(shí)時(shí)間進(jìn)行調(diào)整,定時(shí)鬧鈴功能是否正常,動(dòng)態(tài)掃描顯示是否正常。 原理框圖: (1)計(jì)數(shù)模塊:按照時(shí)鐘模式完成一天24小時(shí)的計(jì)時(shí)功能。 (2)譯碼模塊:根據(jù)計(jì)時(shí)模塊的狀態(tài)輸出值來確定對應(yīng)位的數(shù)據(jù)的,其輸出是7段高低電平,以點(diǎn)亮相應(yīng)的數(shù)碼管; (3)計(jì)數(shù)控制模塊:根據(jù)外部控制信號,進(jìn)行時(shí)鐘計(jì)數(shù)的調(diào)整和計(jì)時(shí)的控制; (4)響鈴控制模塊:根據(jù)外部鬧鐘控制信號完成鬧鐘的定時(shí),當(dāng)計(jì)數(shù)模塊技術(shù)到和該模塊所設(shè)定時(shí)間一致時(shí),該模塊將驅(qū)動(dòng)蜂鳴器響鈴。(5)分頻器:根據(jù)外部的輸入時(shí)鐘,將外部時(shí)鐘成兩路信號,一路用于正常的計(jì)數(shù),一路用于七段顯示數(shù)碼管的動(dòng)態(tài)掃描輸出。 architecture art of beep is signal bep : std_logic。 begin process(bep,clk,hh1,hh2,mm1,mm2,h1,h2,m1,m2) begin if (h1=hh1 and h2=hh2 and mm1=m1 and mm2=m2 ) OR (mm1=0000 and mm2=0000) then 當(dāng)前時(shí)間的時(shí)分秒完全等于設(shè)置的鬧鐘時(shí)間,蜂鳴器才有效,否則蜂鳴器不響,繼續(xù)顯示當(dāng)前的時(shí)間 if clk=39。139。 and clk39。event then bep=not bep。 end if。 else bep=39。139。 end if。 系統(tǒng)時(shí)鐘的軟件設(shè)計(jì) process(clk) variable counts:integer range 0 to 50000000。 系統(tǒng)時(shí)鐘為50MHZ begin if clk39。event and clk=39。139。 then 時(shí)鐘高電平有效 if(counts25000000) then 計(jì)數(shù)周期為1ms,1ms掃描100次, clks=39。139。 counts:=counts+1。 elsif(counts50000000) then clks=39。039。 counts:=counts+1。 else counts:=0。 end if。 end if。 end process。 process(clk) variable countms:integer range 0 to 50000。 分頻段 begin if clk39。event and clk=39。139。 then 時(shí)鐘高電平有效 if(countms25000) then clkms=39。139。 countms:=countms+1。 elsif(countms50000) then clkms=39。039。 countms:=countms+1。 else countms:=0。 end if。 end if。 end process。end architecture fenp。 end if。 c=co。 ssec=secs。 gsec=secg。 end process。end architecture。動(dòng)態(tài)掃描,時(shí)間1s計(jì)數(shù)達(dá)到59秒后本身清零,進(jìn)位給分位,依次類推時(shí)鐘信號的輸入模式的切換,鬧鐘的輸入端口三個(gè)圖分別為秒分時(shí)的輸入端口位選六位,段選8位 硬件的測試 本次選用EP2c5Q208C8N芯片。外部需接幾上升沿按鍵,并接揚(yáng)聲器和不許譯碼器的數(shù)碼管。下載測試后,按復(fù)位鍵后數(shù)碼管顯示0時(shí)0分0秒開始計(jì)數(shù),分秒時(shí)計(jì)數(shù)都正確。按動(dòng)調(diào)分鍵或調(diào)小時(shí)鍵后,分位或小時(shí)位開始自加,再按鍵