【正文】
二、試驗項目名稱: 基于 vhdl語言的數(shù)碼管時鐘設(shè)計 三、實驗?zāi)康模? 利用 FPGA 開發(fā)板上的數(shù)碼管,晶振等資源設(shè)計出能夠顯示時、分、 秒的時鐘。 四、實驗內(nèi)容及原理: (一)、綜述 本實驗?zāi)繕?biāo)是利用 FPGA 邏輯資源, 編程設(shè)計實現(xiàn) 一個數(shù)字電子時鐘 。實驗環(huán)境為 fpga 開發(fā)板。電路設(shè)計采用 VHDL 硬件描述語言編程實現(xiàn),開發(fā)軟件為。 (二)、模塊框架設(shè)計 計數(shù)時鐘由模為 60 的秒計數(shù)器模塊、模為 60 的分計數(shù)模塊、模為 24 的小時計數(shù)器模 塊、 此外還有最后的數(shù)碼管顯示模塊。 包括計時及進(jìn)位兩個進(jìn)程,實現(xiàn)時鐘邏輯功能。 將時鐘的每次變化所對應(yīng)的時間及時輸出到數(shù)碼管上。實質(zhì)為數(shù)碼管譯碼 器。 (三)、 VHDL 編程與仿真: 各個進(jìn)程模塊 以下三個 process 分別為分頻,進(jìn)位以及計時進(jìn)程。分頻進(jìn)程用于統(tǒng)計 CLK 輸入信號輸出完整的 1 秒。進(jìn)位進(jìn)程控制 60 進(jìn)制, 60 進(jìn)制和 24 進(jìn)制的進(jìn)位關(guān)系。計時進(jìn)程用于實現(xiàn)電子時鐘的基本計時功能,即每秒均變化。 分頻部分 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)計到此時為 1S t=0。 end if。 end if。 end process。 進(jìn)位共包括秒個位向秒十位進(jìn)位,秒十位向分個位進(jìn)位,分個位向分十位進(jìn)位,分十位向時個位進(jìn)位,時個位向時十位進(jìn)位。根據(jù)進(jìn)位規(guī)則則可以實現(xiàn)從 0 時 0分 0 秒到 23 時 59 分 59 秒之間任意時刻的顯示。 各位的進(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 時向秒十位進(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 時向分個位進(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)位時向分十位進(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 且分個位進(jìn)位時向時 個位進(jìn)位 else jinwei(3)=39。039。 end if。 if(jinwei(3)=39。139。 and dataout_buf(6)=9)then jinwei(4)=39。139。 時個位為 9 且分十位進(jìn)位時向時十位進(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 時且時個位進(jìn)位時標(biāo)記最高標(biāo)記位 else jinwei(5)=39。039。 end if。 end if。 end process。 計數(shù)進(jìn)程,其進(jìn)程邏輯上受分頻輸出與進(jìn)位控制,當(dāng)分頻輸出變化(即每秒),秒個位自加,當(dāng)滿足進(jìn)位條件時,調(diào)用進(jìn)位規(guī)則,進(jìn)行時間的跳轉(zhuǎn)。 2 計數(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ù)碼管顯示模塊: 動態(tài)刷新分為兩個部分,即移位部分與賦值部分 ,如下兩個進(jìn)程 —— 移位顯示進(jìn)程通過移位寄存器控制數(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。 顯示部分實質(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。 總程序為: 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