QuartusII时钟CASE语句.docx

上传人:b****5 文档编号:6187822 上传时间:2023-01-04 格式:DOCX 页数:17 大小:19.09KB
下载 相关 举报
QuartusII时钟CASE语句.docx_第1页
第1页 / 共17页
QuartusII时钟CASE语句.docx_第2页
第2页 / 共17页
QuartusII时钟CASE语句.docx_第3页
第3页 / 共17页
QuartusII时钟CASE语句.docx_第4页
第4页 / 共17页
QuartusII时钟CASE语句.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

QuartusII时钟CASE语句.docx

《QuartusII时钟CASE语句.docx》由会员分享,可在线阅读,更多相关《QuartusII时钟CASE语句.docx(17页珍藏版)》请在冰豆网上搜索。

QuartusII时钟CASE语句.docx

QuartusII时钟CASE语句

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entityszzis

port(clk:

instd_logic;

       clk1:

instd_logic;

       md1:

instd_logic;

       md2:

instd_logic_vector(1downto0);

       speak:

outstd_logic;

       dout:

outstd_logic_vector(6downto0);

       selout:

outstd_logic_vector(2downto0));

endszz;

architectureoneofszzis

signalsel:

std_logic_vector(2downto0);

signalhou1:

std_logic_vector(3downto0);

signalhou2:

std_logic_vector(3downto0);

signalmin1:

std_logic_vector(3downto0);

signalmin2:

std_logic_vector(3downto0);

signalseth1:

std_logic_vector(3downto0);

signalseth2:

std_logic_vector(3downto0);

signalsetm1:

std_logic_vector(3downto0);

signalsetm2:

std_logic_vector(3downto0);

signalsec1:

std_logic_vector(3downto0);

signalsec2:

std_logic_vector(3downto0);

signalh1:

std_logic_vector(3downto0);

signalh2:

std_logic_vector(3downto0);

signalm1:

std_logic_vector(3downto0);

signalm2:

std_logic_vector(3downto0);

signals1:

std_logic_vector(3downto0);

signals2:

std_logic_vector(3downto0);

-------------------------------------------------

begin

----------------------------------------------模6计数

choice:

process(clk1)

begin

ifclk1'eventandclk1='1'then

ifsel="101"then

sel<="000";

else

sel<=sel+1;

endif;

endif;

endprocesschoice;

-----------------------------------------------小时十位

h110:

process(clk,hou2,min1,min2,sec1,sec2,md1,md2)

begin

ifclk'eventandclk='1'then

if(hou1="0010"andhou2="0011")and(min1="0101"andmin2="1001")and(sec1="0101"andsec2="1001")     then

hou1<="0000";

elsifhou1="0010"andhou2="0011"andmd1='0'andmd2="01"then--当时间为23点且处于校时状态时

hou1<="0000";

elsif(hou2="1001"and(min1="0101"andmin2="1001")and(sec1="0101"andsec2="1001"))or(hou2="1001"andmd1='0'andmd2="01")    then

hou1<=hou1+1;

endif;

endif;

endprocessh110;

-----------------------------------------------小时个位

h220:

process(clk,min1,min2,sec1,sec2,md1,md2,hou1)

begin

ifclk'eventandclk='1'then

if(hou1="0010"andhou2="0011")and(min1="0101"andmin2="1001")and(sec1="0101"andsec2="1001")then

hou2<="0000";

elsifhou2="1001"and(min1="0101"andmin2="1001")and(sec1="0101"andsec2="1001")    then

hou2<="0000";

elsif(hou2="1001"andmd1='0'andmd2="01")or(hou1="0010"andhou2="0011")then

hou2<="0000";--md<='1';

elsif((min1="0101"andmin2="1001")and(sec1="0101"andsec2="1001"))or(md1='0'andmd2="01")then

hou2<=hou2+1;--speak<=clk;

endif;

endif;

endprocessh220;

-----------------------------------------------分钟十位

m110:

process(clk,min2,sec1,sec2,md1,md2)

begin

ifclk'eventandclk='1'then

if(min1="0101"andmin2="1001")and(sec1="0101"andsec2="1001")then

min1<="0000";

elsifmin1="0101"andmin2="1001"and(md1='0'andmd2="00")then

min1<="0000";

elsif(min2="1001"and(sec1="0101"andsec2="1001"))or(min2="1001"andmd1='0'andmd2="00")then

min1<=min1+1;

endif;

endif;--endif;

endprocessm110;

----------------------------------------------分钟个位

m220:

process(clk,sec1,sec2,md1,md2)

begin

ifclk'eventandclk='1'then

ifmin2="1001"and(sec1="0101"andsec2="1001")then

min2<="0000";

elsifmin2="1001"and(md1='0'andmd2="00")then

min2<="0000";

else    if(sec1="0101"andsec2="1001")or(md1='0'andmd2="00")then

min2<=min2+1;

endif;

endif;endif;

endprocessm220;

---------------------------------------------秒十位

s110:

process(clk)

begin

ifclk'eventandclk='1'then

if(sec1="0101"andsec2="1001")then

sec1<="0000";

elseifsec2="1001"then

sec1<=sec1+1;

endif;

endif;endif;

endprocesss110;

--------------------------------------------秒个位

s220:

process(clk)

begin

ifclk'eventandclk='1'then

ifsec2="1001"then

sec2<="0000";

elsesec2<=sec2+1;

endif;

endif;

endprocesss220;

-------------------------------------------时间设置小时部分

sethour1:

process(clk,seth2)

begin

ifclk'eventandclk='1'then

ifseth1="0010"andseth2="0011"then

seth1<="0000";

elsifseth2="1001"    then

seth1<=seth1+1;

endif;

endif;

endprocesssethour1;

-------------------------------------------

sethour2:

process(clk,md1,md2,seth1)

begin

ifclk'eventandclk='1'then

if(seth1="0010"andseth2="0011")orseth2="1001"then

seth2<="0000";

elsifmd1='1'andmd2="00"then

seth2<=seth2+1;

endif;

endif;

endprocesssethour2;

-------------------------------------------时间设置分钟部分

setmin1:

process(clk,setm2)

begin

ifclk'eventandclk='1'then

ifsetm1="0101"andsetm2="1001"then

setm1<="0000";

elsifsetm2="1001"then

setm1<=setm1+1;

endif;

endif;

endprocesssetmin1;

----------------------------------------------

setmin2:

process(clk,md1,md2)

begin

ifclk'eventandclk='1'then

ifsetm2="1001"then

setm2<="0000";

elsifmd1='1'andmd2="01"then

setm2<=setm2+1;

endif;

endif;

endprocesssetmin2;

--------------------------------------------

--------------------------------------------闹铃

speaker:

process(clk1,hou1,hou2,min1,min2)

begin

ifclk1'eventandclk1='1'then

ifseth1=hou1andseth2=hou2andsetm1=min1andsetm2=min2then

speak<=clk1;

elsespeak<='0';

endif;

endif;

endprocessspeaker;

-------------------------------------------

-------------------------------------------

disp:

process(sel,md1,hou1,hou2,min1,min2,sec1,sec2,seth1,seth2,setm1,setm2)

begin

ifsel="000"then

selout<="000";

caseh1is

when"0000"=>dout<="0111111";

when"0001"=>dout<="0000110";

when"0010"=>dout<="1011011";

whenothers=>dout<="1000000";

endcase;

elsifsel="001"then

selout<="001";

caseh2is

when"0000"=>dout<="0111111";

when"0001"=>dout<="0000110";

when"0010"=>dout<="1011011";

when"0011"=>dout<="1001111";

when"0100"=>dout<="1100110";

when"0101"=>dout<="1101101";

when"0110"=>dout<="1111101";

when"0111"=>dout<="0000111";

when"1000"=>dout<="1111111";

when"1001"=>dout<="1101111";

whenothers=>dout<="1000000";

endcase;

elsifsel="010"then

selout<="010";

casem1is

when"0000"=>dout<="0111111";

when"0001"=>dout<="0000110";

when"0010"=>dout<="1011011";

when"0011"=>dout<="1001111";

when"0100"=>dout<="1100110";

when"0101"=>dout<="1101101";

whenothers=>dout<="1000000";

endcase;

elsifsel="011"then

selout<="011";

casem2is

when"0000"=>dout<="0111111";

when"0001"=>dout<="0000110";

when"0010"=>dout<="1011011";

when"0011"=>dout<="1001111";

when"0100"=>dout<="1100110";

when"0101"=>dout<="1101101";

when"0110"=>dout<="1111101";

when"0111"=>dout<="0000111";

when"1000"=>dout<="1111111";

when"1001"=>dout<="1101111";

whenothers=>dout<="1000000";

endcase;

elsifsel="100"then

selout<="100";

cases1is

when"0000"=>dout<="0111111";

when"0001"=>dout<="0000110";

when"0010"=>dout<="1011011";

when"0011"=>dout<="1001111";

when"0100"=>dout<="1100110";

when"0101"=>dout<="1101101";

whenothers=>dout<="1000000";

endcase;

elsifsel="101"then

selout<="101";

cases2is

when"0000"=>dout<="0111111";

when"0001"=>dout<="0000110";

when"0010"=>dout<="1011011";

when"0011"=>dout<="1001111";

when"0100"=>dout<="1100110";

when"0101"=>dout<="1101101";

when"0110"=>dout<="1111101";

when"0111"=>dout<="0000111";

when"1000"=>dout<="1111111";

when"1001"=>dout<="1101111";

whenothers=>dout<="1000000";

endcase;

endif;

ifmd1='0'    then---------------计时时间显示和设置模式

h1<=hou1;h2<=hou2;

m1<=min1;m2<=min2;

s1<=sec1;s2<=sec2;

else                -----------闹铃时间现实和设置模式

h1<=seth1;h2<=seth2;

m1<=setm1;m2<=setm2;

s1<="1111";s2<="1111";

endif;

endprocessdisp;

------------------------------------------

end    one;

.1数字钟的基本组成及工作原理

   数字钟实际上是一个对标准频率(1HZ)进行计数的计数电路.由于计数的起始时间不可能与标准时间(如北京时间)一致,故需要在电路上加一个校时电路,同时标准的1HZ时间信号必须做到准确稳定.通常使用石英晶体振荡器电路构成数字钟.图1.1所示为数字钟的一般构成框图.

⑴晶体振荡器电路 晶体振荡器电路给数字钟提供一个频率稳定准确的32768Hz的方波信号,可保证数字钟的走时准确及稳定.不管是指针式的电子钟还是数字显示的电子钟都使用了晶体振荡器电路.

⑵分频器电路 分频器电路将32768Hz的高频方波信号经32768()次分频后得到1Hz的方波信号供秒计数器进行计数.分频器实际上也就是计数器.

⑶时间计数器电路 时间计数电路由秒个位和秒十位计数器,分个位和分十位计数器及时个位和时十位计数器电路构成,其中秒个位和秒十位计数器,分个位和分十位计数器为60进制计数器,而根据设计要求,时个位和时十位计数器为12进制计数器.

⑷译码驱动电路 译码驱动电路将计数器输出的8421BCD码转换为数码管需要的逻辑状态,并且为保证数码管正常工作提供足够的工作电流.

⑸数码管 数码管通常有发光二极管(LED)数码管和液晶(LCD)数码管,本设计提供的为LED数码管.

2.2数字钟的工作原理

1)晶体振荡器电路

晶体振荡器是构成数字式时钟的核心,它保证了时钟的走时准确及稳定.

一般输出为方波的数字式晶体振荡器电路通常有两类,一类是用TTL门电路构成;另一类是通过CMOS非门构成的电路,如图1.2所示,从图上可以看出其结构非常简单.该电路广泛使用于各种需要频率稳定及准确的数字电路,如数字钟,电子计算机,数字通信电路等.

CMOS非门U1与晶体,电容和电阻构成晶体振荡器电路,U2实现整形功能,将振荡器输出的近似于正弦波的波形转换为较理想的方波.输出反馈电阻为非门提供偏置,使电路工作于放大区域,即非门的功能近似于一个高增益的反相放大器.电容C1,C2与晶体构成一个谐振型网络,完成对振荡频率的控制功能,同时提供了一个180度相移,从而和非门构成一个正反馈网络,实现了振荡器的功能.由于晶体具有较高的频率稳定性及准确性,从而保证了输出频率的稳定和准确.

2)分频器电路

通常,数字钟的晶体振荡器输出频率较高,为了得到1Hz的秒信号输入,需要对振荡器的输出信号进行分频.

通常实现分频器的电路是计数器电路,一般采用多级2进制计数器来实现.例如,将32768Hz的振荡信号分频为1HZ的分频倍数为32768(),即实现该分频功能的计数器相当于15级2进制计数器.常用的2进制计数器有74HC393等.

3)时间计数单元

时间计数单元有时计数,分计数和秒计数等几个部分.

时计数单元以24进制计数器,其输出为两位8421BCD码形式;分计数和秒计数单元为60进制计数器,其输出也为8421BCD码.

一般采用10进制计数器如74HC290,74HC390等来实现时间计数单元的计数功能.欲实现24进制和60进制计数还需进行计数模值转换.

4)译码驱动及显示单元

计数器实现了对时间的累计以8421BCD码形式输出,为了将计数器输出的8421BCD码显示出来,需用显示译码电路将计数器的输出数码转换为数码显示器件所需要的输出逻辑和一定的电流,一般这种译码器通常称为7段译码显示驱动器.

常用的7段译码显示驱动器有CD4511.

5)校时电源电路

当重新接通电源或走时出现误差时都需要对时间进行校正.通常,校正时间的方法是:

首先截断正常的计数通路,然后再进行人工出触发计数或将频率较高的方波信号加到需要校正的计数单元的输入端,校正好后,再转入正常计时状态即可library    ieee;

use   ieee.std_logic_1164.all;

use   ieee.std_logic_arith.all;

use   ieee.std_logic_unsigned.all;

entity  clock  is  

port   (clk,clr,a,c,e,f,g:

in  std_logic;               ---输入信号

        led_sel:

out   std_logic_vector(2  downto  0);     ---位控输入信号

        led:

out   std_logic_vector(0to  6);                 --七段码输出

        p,q:

in   std_logic_vector(3downto  0);       --选择

        b:

in   std_logic_vector(2  downto  0);

        ring:

out   std_logic);                   ---蜂鸣器输出

end  entityclock;

architecturebeha  of  clockis  

  signal  m:

  integerrange0  to999;

  signal  hou1,hou0,min1,min0,sec1,sec0,s2:

std_logic_vector(3  downto  0);

  signal  rhou1,rhou0,rmin1,rmin0,rsec1,rsec0:

std_

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1