邵阳学院课程设计
end if;
end process p1;--结束进程p1 p2:process(clk);--进程p2
variable count2:integer range 0 to 99999; begin
if(clk'event and clk='1')then count2:=count2+1;--在clk上升沿计数 if count2<=49999 then clk2ms<='0';
elsif count2<=99999 then clk2ms<='1';--产生周期为2ms的扫描信号 end if; end if;
end process p2;--结束进程p2 p3:process(clk); --进程p3
variable count3:integer range 0 to 24999999; begin
if(clk'event and clk='1')then count3:=count3+1; --在clk上升沿计数 if count3<=12499999 then end if; end if; end process p3;
----------------------------------------------按键去抖动模块qudou
p4:process(clk,k1,k2,k3,k4)
variable cant1:integer; variable cant2:integer; variable cant3:integer; variable cant4:integer; begin
if k1='1' then cant1:=0; end if;--设置计数初值
if clk'event and clk='1' then
if k2='1' then cant2:=0; end if; --设置计数初值
20
邵阳学院课程设计
if k3='1' then cant3:=0;--设置计数初值 if k4='1' then cant4:=0; if cant1>2499999 then o1<='0'; else o1<='1';--延时0.5s end if;
if cant2>2499999 then o2<='0'; else o2<='1'; --延时0.5s end if;
if cant3>2499999 then o3<='0';
end if;
end if; --设置计数初值
else o3<='1'; --延时0.5s end if;
if cant4>2499999 then o4<='0'; else o4<='1'; --延时0.5s end if;
cant1:=cant1+1; --加一计数 cant2:=cant2+1; --加一计数 cant3:=cant3+1; --加一计数 cant4:=cant4+1; --加一计数 end if; end process p4;
----------------------------------------------按键控制模块self1
p5:process(ok2,ok3,c1); --ok2和ok3触发进程 begin
if ok2'event and ok2='0' then m<=not m;--由ok2 的动作产生m的电平
信号
end if;
if m='1' then ck<=not(ok3);--把按键ok3的脉冲信号给输出 else ck<=c1;--否则把正常计数时钟给输出 end if;
21
邵阳学院课程设计
end process p5;--结束进程
----------------------------------------------六十进制模块cantsixty
p6:process(clk,reset1) begin
if(reset1='0')then ss1<=\ elsif(clk'event and clk='1')then
if (ss1=\--当计数到59时产生进位信号 else c2<='0';--否则不产生 end if;
if ss1=\ if ss2=\ else ss2<=ss2+1; end if;
else ss1<=ss1+1;--计数过程 end if; end if;
end process p6;--结束进程
out1<=ss1;out2<=ss2;--把信号送输出
----------------------------------------------二十四进制模块hourtwenty
p7:process(clk,reset2) begin
if(reset2='0')then hh1<=\ elsif(clk'event and clk='1')then
if (hh1=\hh2<=\end if;
if (hh1=\hh2<=hh2+1; end if; end if; end process p7;
22
邵阳学院课程设计
p8:process(clk,reset2) begin
if(reset2='0')then hh1<=\ elsif(clk'event and clk='1')then
if (hh1=\hh1<=\end if;
if (hh1=\if (hh1=\hh1<=\else hh1<=hh1+1; end if; end if; end if; end process p8;
out3<=hh1;out4<=hh2;--把信号送输出
----------------------------------------------数码管显示模块qudong
p9:process(clk2ms) begin
if clk2ms'event and clk2ms='1' then sel<=sel+1;t2<=t2+1; if t2=\end if; end if;
f<=t2(11)&t2(10);
if f=\ then led(3)<='0';else led(3)<='1'; end if;
if f=\ then led(2)<='0';else led(2)<='1'; end if;
if f=\end if;--led的循环显示设计
23

