1. 设计要求
设计一个以单片机为核心的单词记忆测试器: ①实现单词的录入(为使程序具有可演示性,单词不少于10个)。 ②单词用按键控制依次在屏幕上显示,按键选择认识还是不认识,也可以直接进入下一个或者上一个。 ③单词背完后给出正确率。
2.proteus仿真图
3.程序
#include "reg52.h"
#include "lcd.h"
typedef unsigned int u16;
typedef unsigned char u8;
sbit k1 = P1^0;
sbit k2 = P1^1;
sbit k3 = P1^2;
sbit k4 = P1^3;
u8 code Init[2][16]={ {" H.I.T. CHINA "},{" welcome "} };
u8 over[2][16] = {{" result "},{" 0% "}};
u8 code word[10][16] = {
{" radius "},
{" symmetry "},
{" triple "},
{" audinle "},
{" compatible "},
{" derive "},
{" electronic "},
{" ideology "},
{" input "},
{" parallel "},
};
void delay(u16 i)
{
while(i--);
}
u8 i = 0;
u8 time = 0;
u8 num = 1;
void keybroad()
{
if(k1==0)
{
delay(1000);
if(k1==0)
{
time = 0;
num = 1;
Lcdshow_str(0,1,word[i]);
}
while(!k1);
}
if(num<=10)
{
if(k2==0)
{
delay(1000);
if(k2==0)
{
if(i==0)
{
i = 10-1;
}
else
i--;
Lcdshow_str(0,1,word[i]);
num++;
}
while(!k2);
}
if(k3==0)
{
delay(1000);
if(k3==0)
{
if(i==9)
i=0;
else
i++;
Lcdshow_str(0,1,word[i]);
num++;
}
while(!k3);
}
if(k4==0)
{
delay(1000);
if(k4==0)
{
if(i==9)
i=0;
else
i++;
time++;
Lcdshow_str(0,1,word[i]);
num++;
}
while(!k4);
}
}
}
void main(void)
{
LcdInit();
Lcdshow_str(0,0,Init[0]);
Lcdshow_str(0,1,Init[1]);
while(1)
{
keybroad();
if(num>10)
{
if(time==10)
over[1][5] = 1+0x30;
over[1][6] = time%10+0x30;
Lcdshow_str(0,0,over[0]);
Lcdshow_str(0,1,over[1]);
}
}
}
仿真文件、程序
proteus、51工程文件 ps:有需要可私信要文件
|