华东交通大学
新客户 No newcustom_lh<”1001” newcustom_ll< ” 1001 ” No Yes newcustom_hl<”1001” newcustom_lh<=newcustom_lh+1 No newcustom_ll<=”0000” Yes newcustom_hh<”1001” Yes No newcustom_hl<=newcustom_hl+1 newcustom_lh<=”0000” newcustom_ll<=newcustom_ll+1 Yes Yes newcustom_hh<=newcustom_hh+1 newcustom_hl<=”0000” newcustom_ll<=”0000” newcustom_ll<=”0000” newcustom_ll<=”0000” newcustom_ll<=”0000” waitcustom_ll<”1001” No waitcustom_lh<”1001” Yes No waitcustom_hl<”1001” No waitcustom_ll<=waitcustom_ll+1 Yes waitcustom_hh<”1001” Yes waitcustom_lh<=waitcustom_lh+1 No waitcustom_ll<= ” 0000 ” Yes waitcustom_hh<=waitcustom_hh+1 waitcustom_hl<=”0000” waitcustom_hl<=waitcustom_hl+1 Waitcustom_lh<=”0000” 图三:客户取号时各变量计算流程图 第 4 页 共 22 页 waitcustom_ll<=”0000” waitcustom_lh<=”0000” waitcustom_hl<=”0000” waitcustom_hh<=”0000” 华东交通大学
进程P2:当前柜台服务人员号码的计算
当柜台准备好为客人提供服务时,变量newcustom,curcustom和length的值也会随之发生变化,只有在复位rst=1,clk在上升沿并且waiter=1时,即柜台有按钮waiter=1时,curcustom才能加1。该模块实现的主要代码如下:
If rst='0' then curcustom四位都为0
elsif clk'event and clk='1' then ——时钟上升沿 if waiter<='0' then curcustom中四位都为0
elsif waiter<='1' then ——柜台可以为客人服务
if curcustom_ll<\ elsif curcustom_lh<\——顾客编号都小于9999 curcustom_lh<=curcustom_lh+1;curcustom_ll<=\ elsif curcustom_hl<\
curcustom_hl<=curcustom_hl+1;curcustom_lh<=\ elsif curcustom_hh<\
curcustom_hh<=curcustom_hh+1;curcustom_hl<=\ elsif (curcustom_ll<=\ curcustom_hl<=\ curcustom中四位都为0 ——当前顾客的编号都大于9999;全都至为0000
end if; end if; end if;
进程P3:十进制计数器加至7。
随着时钟上升沿的到来,cnt4加1具体程序解释如下:
if rst='0' then cnt4<=0; ————当复位rst=0时,cnt4=0;
elsif tmpclk'event and tmpclk='1' then ————时钟上升沿 if cnt4<8 then cnt4<=cnt4+1; ——cnt4<8,cnt4的值为cnt4加1, else cnt4<=0; 一直加到7; end if; end if;
进程P4:数码管动态扫描电路
8个数码管分别由三个选通信号通过译码器得到的8个信号来选择。当三个选通信号sel<=”000”时,cnt4=0的被选通显示数据,其余的关闭;当sel<=”001”时,cnt4=1的被选通显示数据,其余的关闭.......通过sel的动态变化到达多位数字的显示。
具体程序解释如下:
begin
if rst='0' then q<=(OTHERS=>'0'); elsif clk'event and clk='1' then
q<=q+1; end if; end process p4; selout<=sel;
sel<=\ ——倒数第一个数码管cnt4=0; \ ——倒数第二个数码管cnt4=1; \ ——倒数第三个数码管cnt4=2;
第 5 页 共 22 页
华东交通大学
\ ——倒数第四个数码管cnt4=3; \ ——第四个数码管cnt4=4; \ ——第三个数码管cnt4=5; \ ——第二个数码管cnt4=6 \ ——第一个数码管cnt4=7; \
进程P5:二倍分频电路生成 tmpclk
输入fi为clk,我们所要的tmpclk就为fi/2,
具体的程序如下:
if rst='0' then cnt10<=\ ——复位为0,其他都为0; elsif clk'event and clk='1' then
if cnt10<3 then cnt10<=cnt10+1; else cnt10<=\.......
tmpclk<=cnt10(0);
进程P6:队长length的计算方法
队长=新客户的号码—当前服务的顾客的号码
即:length<=newcustom—curcustom
Length分为个位length_ll、十位length_lh、百位length_hl、千位length_hh。 四位分别计算。。。。。。 具体程序解释如下:
if rst='0' then ——复位为零,其他均设为零; Length四位均为零;
elsif clk'event and clk='1' then ——上升沿到时,队长开始计算; if waiter<='0' then length_ll<=\ length_hl<=\ elsif waiter<='1' then ——柜台已经服务完上一任顾客,有空位时 length_ll<=newcustom_ll-curcustom_ll; ——四位分别相减; length_lh<=newcustom_lh-curcustom_lh; length_hl<=newcustom_hl-curcustom_hl; length_hh<=newcustom_hh-curcustom_hh;
此时,length=length_hh & length_hl & length_lh & length_ll
进程P7:设定各个数码管显示哪一组数据
计算出变量length_ll,length_lh,length_hl,length_hh,curcustom_ll,curcustom_lh,
第 6 页 共 22 页
华东交通大学
curcustom_hl,curcustom_hh的值后,需要一次送至图二中的八位数码管相应位显示。由于该数码管段选位公共,位选位各自独立,需要采用轮询的方式将各段选信号和位选信号配合起来送至数码管的各引脚。 具体程序解释如下:
case cnt4 is
when 0=> selbit <=\ tmpbcdnum<=curcustom_ll; when 1=> selbit <=\
tmpbcdnum<=curcustom_lh; when 2=> selbit <=\
tmpbcdnum<=curcustom_hl; when 3=> selbit <=\
tmpbcdnum<=curcustom_hh; when 4=> selbit <=\ tmpbcdnum<=length_ll; when 5=> selbit <=\ tmpbcdnum<=length_lh; when 6=> selbit <=\ tmpbcdnum<=length_hl; when 7=> selbit <=\ tmpbcdnum<=length_hh; when others=>selbit<=\ end case; 赋完值后,应如下图:
进程P8:四位二进制数转换为七段数码管
设计一个特殊译码器将四位二进制数转换为七段译码。 具体程序解释如下:
case tmpbcdnum is
when \ ——段选位显示“0”的字样; when \ ——段选位显示“1”的字样; when \ ——段选位显示“2”的字样; when \ ——段选位显示“3”的字样; when \ ——段选位显示“4”的字样; when \ ——段选位显示“5”的字样;
第 7 页 共 22 页
华东交通大学
when \ ——段选位显示“6”的字样; when \ ——段选位显示“7”的字样; when \ ——段选位显示“8”的字样; when \ ——段选位显示“9”的字样; when others=>lednum<=\ ——段选位无任何输出; end case;
至此,八位数码管各位待显示的值均已求出,并译码成七段的形式轮询送往该数码管的各段选及位选引脚,数码管上即能动态显示各字段的值。
二:波 形 仿 真 图
(一)波形仿真图设置
(二)当waiter为1时,数码管会随着newcustom的变化而变化。
(三)当waiter为0时,数码管也显示为0。
第 8 页 共 22 页

