Puzhong 51-single core-A3&A4 development board schematic diagram Use
digital tube, LED, matrix button
Description:
(1) Button is 0 to 15
(2) Button 0 7 corresponds to light 0 7
(3) There are three lights The pin of and the pin of the nixie tube drive are duplicated, so actually only 5 small lights are used.
(4) In the initial state, the score of the technology of the digital tube is 0 when all 8 small lights are on.
(5) Press 8 to start the game, and 5 small lights will light up randomly. Within 4 seconds, the user needs to give the corresponding button to hit the mole. If the user hasn't hit the mole after 4 seconds, another small light will be randomly lit.
(6) No points will be deducted if the small light has not been scored for 4 seconds. There is no penalty for hitting a mole. But you can also add logic to meet the deduction requirements.
(7) Press 9 to end the game, all the small lights will light up and return to the initial state.
Simulation diagram:
Part of the code:
if ( counter_Whac == 0 ) /* 游戏只有一次不然只有复位 结束游戏后这个变量要变 */
{
randomNumber = ramdomSeed % 5; /* 生成随机数 */
ledpTempV = (unsigned char) (0x01 << randomNumber); /* 随机数 亮某一个灯 */
ledpTempV = ( (ledpTempV & 0x1c) << 3) + (ledpTempV & 0x03);
P2 = ~ledpTempV; /* 点亮随机灯 */
timeifg_Whac = 0;
time_Whac = 0;
KeyValue = 66; /*按键初始化 */
while ( !timeifg_Whac ) /* 4s后timeifg_Whac会成为1 */
{
KeyScan(); /* KeyValue 的值改变为0 到7 */
if ( KeyValue != 66 ) /*按键值一旦改变就说明按下了 */
{
if ( randomNumber == map[KeyValue] ) /* 如果是随机数的值 */
{
score_Whac++; /* 加一分 */
seg_disp[0] = score_Whac / 1000; /* 整除 取下千位数字 */
seg_disp[1] = score_Whac % 1000 / 100;
seg_disp[2] = score_Whac % 100 / 10;
seg_disp[3] = score_Whac % 10;
P2 = 0xff;
break; /* 继续游戏 */
}else if ( KeyValue == 9 )
{
counter_Whac = 1; /* 结束游戏 */
P2 = 0x1c; /* 小灯全部点亮 表示游戏结束 */
break;
}else{
/*按错按键不处理 */
break;
}
}
}
if ( timeifg_Whac == 1 ) /* 打地鼠超时 不处理 */
{
}
}