1、数字逻辑设计及应用课程设计报告自动打铃器 ———————————————————————————————— 作者: ———————————————————————————————— 日期: 2 个人收集整理 勿做商业用途
2、 数字逻辑设计及应用 课程设计报告 姓 名: 学 号: 选课号: 设计题号: 一.设计题目 自动打铃器 二.设计要求 1.有数字钟功能; 2.可设置六个时间,定时打铃; 3.响铃5秒钟。 三. 设计过程 1.总体方案 数字钟系统可以分为以下几大模块:时钟信号发生模块,基本计时模块,动态显示模块,控制电路模块,报时电路模块。 首先需要将系统时钟进行分频得到1HZ 时钟信号进行计时
3、 计时电路采用了74LS160 二进制BCD 码计数器构成了模24 和模60 的计数器,进行时分秒的计时.为了避免产生逻辑冒险,计数器尽量采用了同步计数器。 译码显示电路采用的是动态显示的方案,动态显示使用数据选择器的分时复用功能,将任意多位数码管的显示驱动,由一个七段显示译码器来完成。 闹钟的主要部分是4个7485构成的16位数据比较器.闹钟设定时间和时钟时间做比较,然后给蜂鸣器信号闹钟。 2 。 各子模块设计原理 2.1 时钟信号发生模块 为了便于实现秒表的计时功能和报时功能,时钟信号发生模块共输出1HZ 100HZ 512HZ 1KHZ 的时钟信号,输入只有一个,就是系统
4、时钟48MHZ。48MHZ 分频的具体实现为,将48 进制计数器和1K 进制计数器级联。通过计数器的最高位产生1HZ 信号,由于48 不是2 的整数次幂,所以分频得到的信号。占空比不为50%。各个模块的进位信号为各个模块的最高位。 下面为48分频电路: 下面为1000分频电路: 2。2 秒计数电路 用两片74160模10计数器设计一个模60计数器,当计数值为59时,下一个时钟信号给计数器置数0. (1)秒计数的CLK时钟端用分频后的1hz输入。 (2)秒十位的sec[6]取非后输出用于分计数的进位脉冲。 (3)Clear输入用于清零端信号输入. (4)输出sec
5、[7。。0]作为秒计数器的值. 仿真波形如下: 2.3分计数电路 用两片74160模10计数器设计一个模60分计数器,当计数值为59时,因为要考虑到秒计时电路,所以还要输入一个当秒为59的信号,这样下一个时钟信号才能给计数器置数0。 电路图如下: 仿真波形如下: 2。4 小时计数电路 用两片74160以置数法设计一个模24计数器作为小时计数器电路。当秒计时为59,分计时为59时且小时计数为23时给置数端一个低电平信号置数。 仿真波形如下: 2.5动态数码显示电路 如上模块图,这个大的动态数码显示电路模块又分为4个小模块,分别为24选4MU
6、X,显示译码器,计数器,译码器74138。基本原理如下,由一个模6的计数器产生的3位信号输入到24选4MUX和译码74138上,分别选出4位BCD码,和8位译码器中的6位。BCD码通过显示译码器得到7位接到数码管的7段上.因为整个模块为动显,所以计数器的时钟信号需要输入1khz。 2。6时钟校分电路 通过在计时电路钟添加附加电路来实现校分电路功能 K1=1,K2=0,K3=1时设定时钟分钟,给时钟分钟模块的低位使能端一个高电平,同时再通过非门后给置零端一个信号,当分钟走到59时候置零,从而不会出现在校分的时候出现走到60或者之后的数字。 K1=0,K2=0,K3=0时设定时钟小时
7、设计的原理和分钟类似,条件改变了,当走到23的时候置零。 2。7 时钟清零电路 给计时电路的6个74160的清零端接到 一个开关上控制就行。 2.8闹钟模块 闹钟模块共有六路闹钟设定和时间比较模块,实现六路定时打铃。 2。8.1闹钟设定 闹钟的设定又一个模60计数器和一个模24计数器构成。 K1=1,K2=1,K3=0时设定闹钟分钟,原理和时钟校分电路一样.给闹钟分钟的低位使能端一个高电平,同时再通过非门后给置零端一个信号,当分钟走到59时候置零,从而不会出现在校分的时候出现走到60或者之后的数字。K1=0,K2=1,K3=1时设定闹钟小时,设计的原理和分钟类似,条件改变
8、了,当走到23的时候置零。 2。8.2时间比较 将时钟的分钟和小时BCD码和闹钟的分钟和小时的BCD码输入到比较模块中,通过比较器得到信号,输给蜂鸣器,达到闹钟的效果。 四. 设计结论 通过仿真,最终证明此设计能正常的工作,实验过程中,大多数问题在自己的仿真调试下都得到了解决,培养了独立思考解决问题的习惯。学会了电路的故障排查,学会了怎样从问题出发,找到问题的根源,然后用相应的方法来解决问题.培养了严谨细心认真的品质。有些问题,看起来特别小,比如闹铃电路中模6计数器设计时误把“与非门”用成了“与门”,导致了无法正常的模6计数。但这些小的细节直接影响着实验的质量与结果。让我更加深
9、刻地懂得了做任何事都要注意细节. 附录:VHDL程序 library ieee; use ieee.std_logic_1164。all; use ieee。std_logic_unsigned。all; entity szz is port(clk:in std_logic; clk1:in std_logic; md1:in std_logic; md2:in std_logic_vector(1 downto 0); speak:out std_logic; dout:out s
10、td_logic_vector(6 downto 0); selout:out std_logic_vector(2 downto 0)); end szz; architecture one of szz is signal sel:std_logic_vector(2 downto 0); signal hou1:std_logic_vector(3 downto 0); signal hou2:std_logic_vector(3 downto 0); signal min1:std_logic_vector(3 downto 0); signal min
11、2:std_logic_vector(3 downto 0); signal seth1:std_logic_vector(3 downto 0); signal seth2:std_logic_vector(3 downto 0); signal setm1:std_logic_vector(3 downto 0); signal setm2:std_logic_vector(3 downto 0); signal sec1:std_logic_vector(3 downto 0); signal sec2:std_logic_vector(3 downto 0); signa
12、l h1:std_logic_vector(3 downto 0); signal h2:std_logic_vector(3 downto 0); signal m1:std_logic_vector(3 downto 0); signal m2:std_logic_vector(3 downto 0); signal s1:std_logic_vector(3 downto 0); signal s2:std_logic_vector(3 downto 0); ———--—--——-—-——--—-—------———-——---—----———————-— begin -
13、——----———-—------—-——-—-—-—-———----—————--计数 choice:process(clk1) begin if clk1’event and clk1='1' then if sel="101” then sel〈="000”; else sel<=sel+1; end if; end if; end process choice; -——--———---—-——---—-—-—-——--——-—-———-—-—-—-——--小时十位 h110:process(clk,hou2,min1,min2,sec1,sec2,md1,
14、md2) begin if clk'event and clk='1' then if (hou1=”0010” and hou2="0011")and(min1=”0101” and min2=”1001") and (sec1="0101” and sec2="1001") then hou1〈="0000"; elsif hou1="0010”and hou2=”0011”and md1='0' and md2="01” then-—当时间为23点且处于校时状态时 hou1〈="0000"; elsif (hou2="1001”and(min1=”0101" an
15、d min2="1001”) and (sec1="0101" and sec2=”1001"))or (hou2="1001"and md1=’0' and md2=”01") then hou1〈=hou1+1; end if; end if; end process h110; --——--————-——-—--——-—--—---——---—-——-—-----——-—小时个位 h220:process(clk,min1,min2,sec1,sec2,md1,md2,hou1) begin if clk'event and clk=’1’ then if (h
16、ou1="0010” and hou2="0011")and(min1=”0101” and min2="1001") and (sec1="0101" and sec2="1001") then hou2〈=”0000"; elsif hou2=”1001”and(min1=”0101" and min2=”1001”) and (sec1=”0101" and sec2="1001”) then hou2<=”0000”; elsif (hou2="1001”and md1=’0' and md2="01")or (hou1="0010”and hou2=”0011") t
17、hen hou2〈="0000";——md<='1'; elsif ((min1=”0101” and min2="1001”) and (sec1="0101” and sec2=”1001"))or (md1=’0' and md2=”01") then hou2<=hou2+1;--speak<=clk; end if; end if; end process h220; —---—---—-—-———----—----—-—--—-—----—-—---——---分钟十位 m110:process(clk,min2,sec1,sec2,md1,md2) begin
18、if clk'event and clk=’1’ then if (min1="0101” and min2="1001”) and (sec1="0101” and sec2=”1001”) then min1〈="0000”; elsif min1="0101"and min2="1001"and (md1=’0’ and md2="00”)then min1〈=”0000”; elsif (min2=”1001"and (sec1=”0101” and sec2=”1001”)) or (min2="1001”and md1='0' and md2=”00”)then min
19、1<=min1+1; end if; end if;—-end if; end process m110; —------—----—-——-——------—-———-—--—---—--———-—分钟个位 m220:process(clk,sec1,sec2,md1,md2) begin if clk'event and clk=’1’ then if min2=”1001"and (sec1="0101” and sec2=”1001”)then min2〈=”0000”; elsif min2=”1001”and (md1='0’ and md2=”00")then
20、 min2<=”0000"; else if (sec1=”0101” and sec2=”1001”) or(md1=’0' and md2="00")then min2<=min2+1; end if; end if;end if; end process m220; --——--———————-—-——--—--—-—---——---—--—-—--———秒十位 s110:process(clk) begin if clk'event and clk=’1’ then if (sec1=”0101" and sec2="1001”)then sec1<=”
21、0000"; else if sec2=”1001"then sec1<=sec1+1; end if; end if;end if; end process s110; -———--—-———————----—————————--——--—--—--——--秒个位 s220:process(clk) begin if clk'event and clk='1' then if sec2=”1001" then sec2〈=”0000"; else sec2<=sec2+1; end if; end if; end process s220; ---—--——-
22、————----—--—-———-—--—---—---—---—时间设置小时部分 sethour1:process(clk,seth2) begin if clk'event and clk=’1' then if seth1=”0010"and seth2="0011" then seth1〈=”0000"; elsif seth2="1001” then seth1〈=seth1+1; end if; end if; end process sethour1; --—-——-----—-—-——-——-------—-----—-—--—-——- set
23、hour2:process(clk,md1,md2,seth1) begin if clk'event and clk=’1’ then if (seth1=”0010”and seth2="0011")or seth2="1001"then seth2〈="0000"; elsif md1=’1’ and md2="00" then seth2〈=seth2+1; end if; end if; end process sethour2; —-—--—--—-———-—-—--——-—----—------—-—--————时间设置分钟部分 setmin1:proces
24、s(clk,setm2) begin if clk’event and clk='1’ then if setm1="0101"and setm2=”1001”then setm1〈="0000”; elsif setm2="1001”then setm1〈=setm1+1; end if; end if; end process setmin1; -———-—-——--———------—-—-————----—-———-——--———- setmin2:process(clk,md1,md2) begin if clk'event and clk='1’then
25、 if setm2="1001”then setm2<=”0000”; elsif md1='1' and md2="01"then setm2〈=setm2+1; end if; end if; end process setmin2; ———--——-----———————-—--—-——--——-------——---— --——-—-————---—-—--—-—-------—--—-——-—-————-闹铃 speaker:process(clk1,hou1,hou2,min1,min2) begin if clk1'event and clk1=’1’the
26、n if seth1=hou1 and seth2=hou2 and setm1=min1 and setm2=min2 then speak<=clk1; else speak〈='0’; end if; end if; end process speaker; -—----—---—-——----——--—-—-—-——--—-——-———--- —-—-——————-———---———-—---————-----—-—-----— disp:process(sel,md1,hou1,hou2,min1,min2,sec1,sec2,seth1,seth2,setm1,s
27、etm2) begin if sel="000” then selout<=”000”; case h1 is when ”0000"=〉dout<="0111111"; when "0001”=〉dout<=”0000110”; when "0010"=〉dout<="1011011”; when others =>dout〈="1000000"; end case; elsif sel="001" then selout〈=”001"; case h2 is when ”0000”=>dout〈="0111111”; when ”0001”=〉dout<="00
28、00110"; 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"; when others=〉dout<=”1000000”; end case; e
29、lsif sel="010” then selout〈="010"; case m1 is 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 others=〉dout<=”1000000”; end case; elsif sel=”011" then s
30、elout〈="011”; case m2 is 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<=”11111
31、11”; when "1001"=〉dout〈=”1101111”; when others=〉dout<="1000000”; end case; elsif sel=”100” then selout<="100”; case s1 is when "0000"=>dout<="0111111”; when ”0001”=>dout<="0000110”; when "0010”=>dout〈=”1011011”; when "0011"=〉dout〈="1001111"; when "0100"=>dout<=”1100110”; when ”0101”=>dou
32、t〈="1101101”; when others=>dout〈=”1000000”; end case; elsif sel=”101” then selout〈=”101"; case s2 is 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 ”0
33、110"=>dout<=”1111101”; when ”0111”=〉dout〈="0000111"; when "1000”=〉dout〈=”1111111”; when "1001”=>dout〈="1101111"; when others=〉dout〈=”1000000"; end case; end if; if md1=’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”; end if; end process disp; ——————----—--————-----—--———--—---—--—---- end one; 21






