【正文】
二、試驗(yàn)項(xiàng)目名稱: 基于 vhdl語(yǔ)言的數(shù)碼管時(shí)鐘設(shè)計(jì) 三、實(shí)驗(yàn)?zāi)康模? 利用 FPGA 開發(fā)板上的數(shù)碼管,晶振等資源設(shè)計(jì)出能夠顯示時(shí)、分、 秒的時(shí)鐘。 四、實(shí)驗(yàn)內(nèi)容及原理: (一)、綜述 本實(shí)驗(yàn)?zāi)繕?biāo)是利用 FPGA 邏輯資源, 編程設(shè)計(jì)實(shí)現(xiàn) 一個(gè)數(shù)字電子時(shí)鐘 。實(shí)驗(yàn)環(huán)境為 fpga 開發(fā)板。電路設(shè)計(jì)采用 VHDL 硬件描述語(yǔ)言編程實(shí)現(xiàn),開發(fā)軟件為。 (二)、模塊框架設(shè)計(jì) 計(jì)數(shù)時(shí)鐘由模為 60 的秒計(jì)數(shù)器模塊、模為 60 的分計(jì)數(shù)模塊、模為 24 的小時(shí)計(jì)數(shù)器模 塊、 此外還有最后的數(shù)碼管顯示模塊。 包括計(jì)時(shí)及進(jìn)位兩個(gè)進(jìn)程,實(shí)現(xiàn)時(shí)鐘邏輯功能。 將時(shí)鐘的每次變化所對(duì)應(yīng)的時(shí)間及時(shí)輸出到數(shù)碼管上。實(shí)質(zhì)為數(shù)碼管譯碼 器。 (三)、 VHDL 編程與仿真: 各個(gè)進(jìn)程模塊 以下三個(gè) process 分別為分頻,進(jìn)位以及計(jì)時(shí)進(jìn)程。分頻進(jìn)程用于統(tǒng)計(jì) CLK 輸入信號(hào)輸出完整的 1 秒。進(jìn)位進(jìn)程控制 60 進(jìn)制, 60 進(jìn)制和 24 進(jìn)制的進(jìn)位關(guān)系。計(jì)時(shí)進(jìn)程用于實(shí)現(xiàn)電子時(shí)鐘的基本計(jì)時(shí)功能,即每秒均變化。 分頻部分 process(clk,reset) begin if(reset=39。039。)then t=0。 elsif(clk39。event and clk=39。139。)then t=t+1。 if(t=50000000)then 開發(fā)板晶振 50M,統(tǒng)計(jì)到此時(shí)為 1S t=0。 end if。 end if。 end process。 進(jìn)位共包括秒個(gè)位向秒十位進(jìn)位,秒十位向分個(gè)位進(jìn)位,分個(gè)位向分十位進(jìn)位,分十位向時(shí)個(gè)位進(jìn)位,時(shí)個(gè)位向時(shí)十位進(jìn)位。根據(jù)進(jìn)位規(guī)則則可以實(shí)現(xiàn)從 0 時(shí) 0分 0 秒到 23 時(shí) 59 分 59 秒之間任意時(shí)刻的顯示。 各位的進(jìn)位標(biāo)志 process(clk,reset) begin if reset=39。039。then jinwei=000000。 1 elsif clk39。event and clk=39。139。then if dataout_buf(0)=9 then jinwei(0)=39。139。 9S 時(shí)向秒十位進(jìn)位 else jinwei(0)=39。039。 end if。 if(jinwei(0)=39。139。and dataout_buf(1)=5)then jinwei(1)=39。139。 59S 時(shí)向分個(gè)位進(jìn)位 else jinwei(1)=39。039。 end if。 if(jinwei(1)=39。139。 and dataout_buf(3)=9)then jinwei(2)=39。139。 9 分且秒十位進(jìn)位時(shí)向分十位進(jìn)位 else jinwei(2)=39。039。 end if。 if(jinwei(2)=39。139。 and dataout_buf(4)=5)then jinwei(3)=39。139。 分十位為 5 且分個(gè)位進(jìn)位時(shí)向時(shí) 個(gè)位進(jìn)位 else jinwei(3)=39。039。 end if。 if(jinwei(3)=39。139。 and dataout_buf(6)=9)then jinwei(4)=39。139。 時(shí)個(gè)位為 9 且分十位進(jìn)位時(shí)向時(shí)十位進(jìn)位 else jinwei(4)=39。039。 end if。 if(jinwei(4)=39。139。 and dataout_buf(6)=2 and dataout_buf(7)=1)then jinwei(5)=39。139。 到 12 時(shí)且時(shí)個(gè)位進(jìn)位時(shí)標(biāo)記最高標(biāo)記位 else jinwei(5)=39。039。 end if。 end if。 end process。 計(jì)數(shù)進(jìn)程,其進(jìn)程邏輯上受分頻輸出與進(jìn)位控制,當(dāng)分頻輸出變化(即每秒),秒個(gè)位自加,當(dāng)滿足進(jìn)位條件時(shí),調(diào)用進(jìn)位規(guī)則,進(jìn)行時(shí)間的跳轉(zhuǎn)。 2 計(jì)數(shù) process(t,reset,dataout_buf,jinwei) begin if(reset=39。039。)then dataout_buf(0)=0。 dataout_buf(1)=0。 dataout_buf(2)=10。 dataout_buf(3)=0。 dataout_buf(4)=0。 dataout_buf(5)=10。 dataout_buf(6)=2。 dataout_buf(7)=1。 elsif (clk39。event and clk=39。139。)then if t=50000000 then if(jinwei(0)=39。039。)then dataout_buf(0)=dataout_buf(0)+1。 else dataout_buf(0)=0。 if(jinwei(1)=39。039。)then dataout_buf(1)=dataout_buf(1)+1。 else dataout_buf(1)=0。 if(jinwei(2)=39。039。)then dataout_buf(3)=dataout_buf(3)+1。 else dataout_buf(3)=0。 if(jinwei(3)=39。039。)then dataout_buf(4)=dataout_buf(4)+1。 else dataout_buf(4)=0。 if(jinwei(4)=39。039。)then dataout_buf(6)=dataout_buf(6)+1。 else dataout_buf(6)=0。 if(jinwei(5)=39。039。)then dataout_buf(7)=dataout_buf(7)+1。 else dataout_buf(7)=0。 end if。 end if。 end if。 end if。 end if。 end if。 3 end if。 end if。 end process。 數(shù)碼管顯示模塊: 動(dòng)態(tài)刷新分為兩個(gè)部分,即移位部分與賦值部分 ,如下兩個(gè)進(jìn)程 —— 移位顯示進(jìn)程通過(guò)移位寄存器控制數(shù)碼管的循環(huán)移位。 移位顯示 process(clk,reset,dataout_buf) begin if(reset=39。039。)then t_scan=0。 led_sel_buffer=00000001。 elsif(clk39。event and clk=39。139。)then t_scan=t_scan+1。 if(t_scan=800)then led_sel_buffer=led_sel_buffer(6 downto 0)amp。led_sel_buffer(7)。 t_scan=0。 end if。 end if。 led_sel=led_sel_buffer。 end process。 分段賦值 process(clk,led_sel_buffer,dataout_buf,reset) begin if reset=39。039。then datacode=0。 elsif(clk39。event and clk=39。139。)then case led_sel_buffer is when11111110=datacode=dataout_buf(0)。 when11111101=datacode=dataout_buf(1)。 when11111011=datacode=dataout_buf(2)。 when11110111=datacode=dataout_buf(3)。 when11101111=datacode=dataout_buf(4)。 when11011111=datacode=dataout_buf(5)。 when10111111=datacode=dataout_buf(6)。 when01111111=datacode=dataout_buf(7)。 when others=datacode=dataout_buf(0)。 end case。 end if。 end process。 顯示部分實(shí)質(zhì)為數(shù)碼管顯示譯碼器,把譯碼輸出到數(shù)碼管從而顯示數(shù)字。 顯示 4 process(datacode,reset) begin if reset=39。039。then dataout=11111111。 else case datacode is when 0=dataout=11111100。 when 1=dataout=01100000。 when 2=dataout=11011010。 when 3=dataout=11110010。 when 4=dataout=01100110。 when 5=dataout=10010110。 when 6=dataout=00111110。 when 7=dataout=11100000。 when 8=dataout=11111110。 when 9=dataout=11100110。 when 10=dataout=00000010。 when others=dataout=00000000。 end case。 end if。 led_data=dataout。 end process。 總程序?yàn)椋? library ieee。 use 。 use 。 entity clock is port(clk,reset:in std_logic。 led_data:out std_logic_vector(7 downto 0)。 led_sel:out std_logic_vector(7 downto 0) )。 end clock。 architecture logic of clock is type number is array (0 to 7) of integer。 signal dataout_buf:number。 signal led_sel_buffer:std_logic_vector(7 downto 0)。 signal dataout:std_logic_vector(7 downto 0)。 signal datacode:integer range 0 to 10。 signal jinwei:std_logic_vector(0 to 5)。 signal t_scan:integer。 signal t:integer。 begin 5 進(jìn)位標(biāo)志 process(clk,reset) begin if reset=39。039。then jinwei=000000。 elsif clk39。event and clk=39。139。then if dataout_buf(0)=9 then jinwei(0)=39。139。 else jinwei(0)=39。039。 end if。 if(jinwei(0)=39。139。and dataout_buf(1)=5)then jinwei(1)=39。139。 else jinwei(1)=39。039。 end if。 if(jinwei(1)=39。139。 and dataout_buf(3)=9)then jinwei(2)=39。139。 else jinwei(2)=39。039。 end if。 if(jinwei(2)=39。139。 and dataout_buf(4)=5)then jinwei(3)=39。139。 else jinwei(3)=39。039。 end if。 if(jinwei(3)=39。139。 a