北邮数电实验报告(猜数字) 联系客服

发布时间 : 星期四 文章北邮数电实验报告(猜数字)更新完毕开始阅读

x2<=key1; count1:=2;

else null; end if;

if key1 /= x2 and key1 /= x1 then

x3<=key1; count1:=3; else null; end if;

if key1 /= x3 and key1 /= x1 and key1 /= x2 then

x4<=key1; count1:=0; else null; end if;

when 2 =>

when 3 =>

when others => null;

end case;

如上是将矩阵键盘输入的数字显示在数码管上的代码,同时判断输入的数字不能出现重复,相当于消除了键盘抖动的问题。

count_a:=0; count_b:=0;

if x1=y1 then count_a:=count_a+1;end if; if x2=y2 then count_a:=count_a+1;end if; if x3=y3 then count_a:=count_a+1;end if; if x4=y4 then count_a:=count_a+1;end if; if x1=y2 then count_b:=count_b+1;end if; if x1=y3 then count_b:=count_b+1;end if; if x1=y4 then count_b:=count_b+1;end if; if x2=y1 then count_b:=count_b+1;end if; if x2=y3 then count_b:=count_b+1;end if; if x2=y4 then count_b:=count_b+1;end if; if x3=y1 then count_b:=count_b+1;end if; if x3=y2 then count_b:=count_b+1;end if; if x3=y4 then count_b:=count_b+1;end if; if x4=y1 then count_b:=count_b+1;end if; if x4=y2 then count_b:=count_b+1;end if; if x4=y3 then count_b:=count_b+1;end if;

如上是对A、B的计数,用基本的if语句。

详细程序见附件。

五、 功能说明及资源利用情况

按BTN6按键开始游戏,即可开始用矩阵键盘输入数字,数字不能出现重复(输入了重复的数字时将不会算作输入了数字),如图,输入了6312:

按BTN1按键确定输入的数字即可开始游戏,开始计时:

用矩阵键盘输入猜的数字,数字不允许出现重复,按BTN2按键确定,如图输入1234,出现0和3表示0A3B,并且点阵显示X、蜂鸣器警报表示猜的不对:

当时间结束时仍没有猜对数字时,点阵显示囧表示到时间了:

如果在64秒内猜对了数字,则点阵显示笑脸表示猜对了:

在整个猜数字的过程中均可按BTN7按键重置游戏,再次按BTN6开始。 矩阵键盘顺序: 1 2 3 4 5 6 7 8