stm32vet6外部中断扫描矩阵键盘

利用stm32f103vet6外部中断来获取矩阵键盘键值外加可精确到小数点后6位计算器源程序

利用外部中断来获取键值,避免了逐行扫描,减少了cpu的占用。准确的获取键值,运用二维数组来存放键值,让55的矩阵键盘输出键值,这个设定的二维数组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(endflag0)
{
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);

}

插入链接与图片

链接: https://download.csdn.net/download/weixin_43720264/11454513.

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页