利用外部中断来获取键值,避免了逐行扫描,减少了cpu的占用。准确的获取键值,运用二维数组来存放键值,让5*5的矩阵键盘输出键值,这个设定的二维数组char xianshi[5][5]={{'(','/','*','-','+'},{')','3','2','1',0},{'6','5','4','0',0},{10,'9','8','7',0},{'=','.','0',11,12}};这位检查行和列:
while(1) {
if(linflag==0)
{
row0(1);row1(1);row2(1);row3(1);row4(1);
if(endflag==0)
{
rowflag=0; row0(0);row1(1);row2(1);row3(1);row4(1);
delay_nms(10);
}
if(endflag==0)
{
rowflag=1;
row0(1);row1(0);row2(1);row3(1);row4(1);
delay_nms(10);
}
if(endflag==0)
{
rowflag=2;row0(1);row1(1);row2(0);row3(1);row4(1);
delay_nms(10);
}
if(endflag==0)
{
rowflag=3;row0(1);row1(1);row2(1);row3(0);row4(1);
delay_nms(10);
}
if(endflag==0)
{
rowflag=4;row0(1);row1(1);row2(1);row3(1);row4(0);
delay_nms(10);
}
row0(0);row1(0);row2(0);row3(0);row4(0);
endflag=0;
linflag=1;
}
检查列:
if(linflag==1)
{
if (EXTI_GetITStatus(EXTI_Line11)!=RESET)
{
lin=0;
EXTI_ClearFlag(EXTI_Line11);
}
if (EXTI_GetITStatus(EXTI_Line12)!=RESET)
{
lin=1;
EXTI_ClearFlag(EXTI_Line12);
}
if (EXTI_GetITStatus(EXTI_Line13)!=RESET)
{
lin=2;
EXTI_ClearFlag(EXTI_Line13);
}
if (EXTI_GetITStatus(EXTI_Line14)!=RESET)
{
lin=3;
EXTI_ClearFlag(EXTI_Line14);
}
if (EXTI_GetITStatus(EXTI_Line15)!=RESET)
{
lin=4;
EXTI_ClearFlag(EXTI_Line15);
}
linflag=0;
}
else if(endflag==1)
{
if (EXTI_GetITStatus(EXTI_Line11)!=RESET)
EXTI_ClearFlag(EXTI_Line11);
if (EXTI_GetITStatus(EXTI_Line12)!=RESET)
EXTI_ClearFlag(EXTI_Line12);
if (EXTI_GetITStatus(EXTI_Line13)!=RESET)
EXTI_ClearFlag(EXTI_Line13);
if (EXTI_GetITStatus(EXTI_Line14)!=RESET)
EXTI_ClearFlag(EXTI_Line14);
if (EXTI_GetITStatus(EXTI_Line15)!=RESET)
EXTI_ClearFlag(EXTI_Line15);
}
else
{
if (EXTI_GetITStatus(EXTI_Line11)!=RESET)
{
row=rowflag;
rowflag=5;
endflag=1;
EXTI_ClearFlag(EXTI_Line11);
}
if (EXTI_GetITStatus(EXTI_Line12)!=RESET)
{
row=rowflag;
rowflag=5;
endflag=1;
EXTI_ClearFlag(EXTI_Line12);
}
if (EXTI_GetITStatus(EXTI_Line13)!=RESET)
{
row=rowflag;
rowflag=5;
endflag=1;
EXTI_ClearFlag(EXTI_Line13);
}
if (EXTI_GetITStatus(EXTI_Line14)!=RESET)
{
row=rowflag;
rowflag=5;
endflag=1;
EXTI_ClearFlag(EXTI_Line14);
}
if (EXTI_GetITStatus(EXTI_Line15)!=RESET)
{
row=rowflag;
rowflag=5;
endflag=1;
EXTI_ClearFlag(EXTI_Line15);
}
if(xianshi[row][lin]!='=')
{ str[m++]=xianshi[row][lin];
g=xianshi[row][lin];}
else
s=displaynum(str,m);
}
利用巧妙的算法来进行计算器的计算,准确输出到12864屏幕上。想要的可以下载。
全部资料51hei下载地址:
33.7z
(49.52 KB, 下载次数: 20)
|