可编程微波炉控制器系统的计
3.9 8路拨码开关输入
通过拨码开关可做相应的输入等实验,拨码开关和按键的用途差不多,只不过拨码开关可以固定电平,而按键一松手又回到以前的状态了。
第4章 系统软件设计
4.1 分频程序设计
在接口电路中,时钟信号的作用至关重要,一般CPLD的外部时钟信号可达到几十MHZ,但是由于一些接口电路的特性所致,这样高频率的时钟不适合电路工作,所以应该引入时钟分频电路产生适合接口的工作频率。时钟发生器的输入是全局时钟clk,是从50MHZ的晶振得到的信号。为了产生合适的扫描时钟、计数时钟和闪烁时钟,所以要让50MHZ信号变成clk1为50000hz和 clk2为1hz。
具体程序如下:
--***********50000hz分频信号***********----------
process(clk)
variable cntt : integer range 1 to 500; begin
if(clk'event and clk='1')then if cntt=500 then
cntt:=1; clk1<= not clk1; else
cntt:=cntt+1; end if; end if; end process;
---***************1hz钟信号 ****************------
process(clk1)
10
可编程微波炉控制器系统的计
variable cnt : integer range 1 to 25000; begin
if(clk1'event and clk1='1')then if cnt =25000 then
cnt:=1;clk2<= not CLK2; else
cnt:=cnt+1; end if; end if; end process;
在产生1HZ信号的进程中之所以用了上一个进程中产生的5000hz的clk1,这样用的目的是为让系统剩下资源,因为EPM240的系统资源本来就是很少的,为了更好的实现更加智能化,所以要尽量节约系统资料。所以用clk1来产生clk2。
4.2数码管显示设计程序设计
根据要求,通过数码管的显示来显示倒计时的其实时间,客户调节时间的显示,调节火候的显示,所以程序必须设计一个可以进行倒计时的计数器,一个调节时间功能的进程。让用户通过调节时间来制定要进行倒计时的开始时间。
一开始时我原本打算通过设计一个4*4矩阵键盘来实现更加智能化设计,让用户可以很轻松通过键盘上的数字按键来控制显示数字来设置全自动时间以及其他功能。程序及硬件电路图都设计好了,但是由于EPM240的系统资源极其有限,矩形键盘所需的系统资源大。所以让我不得不放弃用矩形键盘来控制。所以最终选择用6个独立按键来控制。再说EPM240的端口又多,6个端口对它也只是小菜一碟。
整个程序中需要一个倒计时进程来控制数码管到显示计时,原理很简单就是相当计时秒表一样,只是把条件的当0就变为9,变成当9变为0就好了,这样就能实现数码管倒计时功能了。
为了控制指示灯和防止用户忘记关门就直接开始工作导致微波伤害人体健康,所以在进行倒计时工作时我加上了一个条件判断是否要进行计时工作。
为了实现假如用户调节时间的时候不用一定要调节四位,就直接可以按开始按钮,数码管就不会不停止那里闪烁。所以又要在工作计时时加上一个判断条件。
具体程序如下
ELSIF(CLK2'EVENT AND CLK2='1') THEN
if (L='0' and kaimeng='0')then ----------为了控制指示灯和防止用户忘
记关门就直接开始工作导致微波伤害人体健康----------
cnt1<=0; ---------------为了实现假如用户调节时
间的时候不用一定要调节四位,就直接可以按开始按钮,数码管就不会不停止那里闪烁。
case led3 is
when\
11
可编程微波炉控制器系统的计
case led4 is
when\ case led5 is
when\ case led6 is
when\ led5<=\ led4<=\
led3<=\
when others=>led6<=led6-1; end case;
when others=> led5<=led5-1; end case;
when others=>led4<=led4-1; end case;
when others=>led3<=led3-1; end case; end if;
在写这段程序是要对全局思路要很清晰,特别是这里用到信号量最多,每个信号要知道它的具体作用。
调节时间进程我的主要思路是利用一个移位和两个分别为递增和递减的按键来控制,利用case 语句来控制数码管的位置,利用case语句也有一个好处就是能够节约系统资源。
例如实现递增功能的程序如下:
elsif (dizeng='0') THEN -----dizeng=0时递增调时
case cnt1 is
when 4=>case led3 is
when\ when others=> led3<=led3+1; end case;
when 3=>case led4 is
when\ when others=> led4<=led4+1; end case;
when 2=>case led5 is
when\ when others=> led5<=led5+1; end case;
when 1=>case led6 is
when\
12
可编程微波炉控制器系统的计
when others=> led6<=led6+1; end case;
when others => null; end case;
同理就可以编写实现递减功能的程序。
因为我的数码管到管脚是统一连在一起的,目的是为了节约IO口,所以要用不断扫描数码管才能让数码管显示你想要的数字,扫描数码管到方法有很多种,为了让用户知道他调节时间时所控制数码管到位置,所以我加上了当那个数码管受到控制时,还会不断闪烁,加以显示。这因为加上了这个功能,所以要打破传统的扫描方法。顺便节约系统资源。编写程序如下:
--********-调整闪烁时间*******************---- process(cnt,en_xhdl,data4) begin
if(clk1'event and clk1='1')then if cnt=4 then cnt<=0; else
cnt<=cnt+1; end if; end if; case cnt is
when 0 => en_xhdl<=\
when 1 => case cnt1 is when 4=>
en_xhdl<=(2=>clk2,others=>'1');dian<='1'; when others=>
en_xhdl<=\为0时数码管的小数点就不
显示------
end case;
when 2 =>
case cnt1 is when 3=>
en_xhdl<=(3=>clk2,others=>'1');dian<='1'; when others=>
en_xhdl<=\ end case; when 3 =>
case cnt1 is when 2=>
en_xhdl<=(4=>clk2,others=>'1');dian<='0';
13
可编程微波炉控制器系统的计
when others=>
en_xhdl<=\ end case; when 4 =>
case cnt1 is when 1=>
en_xhdl<=(5=>clk2,others=>'1');dian<='1'; when others=>
en_xhdl<=\ end case; when others => null; end case;
case en_xhdl is
when \ when \ when '1'=>DATA4<=led31 ; when others=>data4<=led3; end case;
when \ when '1'=>DATA4<=led41 ; when others=>data4<=led4; end case;
when \ when '1'=>DATA4<=led51 ; when others=>data4<=led5; end case;
when \ when '1'=>DATA4<=led61 ; when others=>data4<=led6; end case;
when others => null; end case; END PROCESS;
前面完成编码后肯定要完成译码显示,所以一定要一个译码进程来通过对数码管管脚的输出进行编码。我选择的数码管是8段共阴极。当为“1”时该管对应的段显示变亮。
具体程序
--*******************---译码----******************----- process(data4) begin
14
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库微波炉可编程逻辑控制系统设计(3)在线全文阅读。
相关推荐: