zoukankan      html  css  js  c++  java
  • 4x4矩阵键盘 扫描程序

    一:不排除第四位异常处理

    uchar JuzhenkeyScan()
    {
    //    P3=0xfe;
    //    temp=P3;
    //    while(temp!=0xfe)
    //    {
    //        temp=P3;
    //        switch(temp)
    //    {
    //        case 0xee:num=10;
    //        break;
    //        case 0xde:num=3;
    //        break;
    //        case 0xbe:num=2;
    //        break;
    //        case 0x7e:num=1;
    //        break;
    //    }
    //    delayms(10);
    //    }
    
        P3=0xfd;//1111 1110
        temp=P3;
        while(temp!=0xfd)
        {
        temp=P3;
        switch(temp)
        {
            case 0xed:num=11;
            break;
            case 0xdd:num=6;
            break;
            case 0xbd:num=5;
            break;
            case 0x7d:num=4;
            break;
        }
        delayms(10);
        }
        
    
        P3=0xfb;
        temp=P3;
        while(temp!=0xfb)
        {
        temp=P3;
        switch(temp)
        {
            case 0xeb:num=12;
            break;
            case 0xdb:num=9;
            break;
            case 0xbb:num=8;
            break;
            case 0x7b:num=7;
            break;
        }
        delayms(10);
        }
        
        P3=0xf7;
        temp=P3;
        while(temp!=0xf7)
        {
        temp=P3;
        switch(temp)
        {
            case 0xe7:num=13;
            break;
            case 0xd7:num=14;
            break;
            case 0xb7:num=0;
            break;
            case 0x77:num=14;
            break;
        }
        delayms(10);
        }
        return num;
    }
    View Code

    二:排除第四位异常处理

      1 uchar keyscan()
      2 {
      3     P3=0xfe;
      4     tempkey=P3;
      5     tempkey=tempkey&0xf0;
      6     while(tempkey!=0xf0)
      7     {
      8         delayms(5);
      9         tempkey=P3;
     10         tempkey=tempkey&0xf0;
     11         while(tempkey!=0xf0)
     12         {
     13             tempkey=P3;
     14             switch(tempkey)
     15             {
     16                 case 0xee:num=10; //A
     17                 break;
     18                 case 0xde:num=3;
     19                 break;
     20                 case 0xbe:num=2;
     21                 break;
     22                 case 0x7e:num=1;
     23                 break;
     24             }
     25             while(tempkey!=0xf0)
     26             {
     27                 tempkey=P3;
     28                 tempkey=tempkey&0xf0;
     29             }
     30 
     31         }
     32     }
     33 
     34     
     35     
     36     
     37             P3=0xfd;
     38             tempkey=P3;
     39             tempkey=tempkey&0xf0;
     40             while(tempkey!=0xf0)
     41                 {
     42                     delayms(5);
     43                     tempkey=P3;
     44                     tempkey=tempkey&0xf0;
     45                     while(tempkey!=0xf0)
     46                     {
     47                         tempkey=P3;
     48                     switch(tempkey)
     49                         {
     50                             case 0xed:num=11;//B
     51                                 break;
     52                             case 0xdd:num=6;
     53                                 break;
     54                             case 0xbd:num=5;
     55                                 break;
     56                             case 0x7d:num=4;
     57                                 break;
     58                         }
     59                     while(tempkey!=0xf0)
     60                         {
     61                             tempkey=P3;
     62                             tempkey=tempkey&0xf0;
     63                         }
     64 
     65                     }
     66                 }
     67 
     68 
     69             P3=0xfb;
     70             tempkey=P3;
     71             tempkey=tempkey&0xf0;
     72             while(tempkey!=0xf0)
     73                 {
     74                     delayms(5);
     75                     tempkey=P3;
     76                     tempkey=tempkey&0xf0;
     77                     while(tempkey!=0xf0)
     78                     {
     79                         tempkey=P3;
     80                     switch(tempkey)
     81                         {
     82                             case 0xeb:num=12; //C
     83                                 break;
     84                             case 0xdb:num=9;
     85                                 break;
     86                             case 0xbb:num=8;
     87                                 break;
     88                             case 0x7b:num=7;
     89                                 break;
     90                         }
     91                     while(tempkey!=0xf0)
     92                         {
     93                             tempkey=P3;
     94                             tempkey=tempkey&0xf0;
     95                         }
     96     
     97                     }
     98                 }
     99 
    100 
    101             P3=0xf7;
    102             tempkey=P3;
    103             tempkey=tempkey&0xf0;
    104             while(tempkey!=0xf0)
    105                 {
    106                     delayms(5);
    107                     tempkey=P3;
    108                     tempkey=tempkey&0xf0;
    109                     while(tempkey!=0xf0)
    110                     {
    111                         tempkey=P3;
    112                     switch(tempkey)
    113                         {
    114                             case 0xe7:num=13;
    115                                 break;
    116                             case 0xd7:num=14;
    117                                 break;
    118                             case 0xb7:num=0;
    119                                 break;
    120                             case 0x77:num=14;
    121                                 break;
    122                         }
    123                     while(tempkey!=0xf0)
    124                         {
    125                             tempkey=P3;
    126                             tempkey=tempkey&0xf0;
    127                         }
    128                     }  
    129                 }
    130 
    131 
    132 }
    View Code
  • 相关阅读:
    setInterval的停止与启动
    postgresql常用
    STM32学习笔记(四) RCC外设的学习和理解
    STM32学习笔记(九) 外部中断,待机模式和事件唤醒
    STM32的优先级的理解及其使用
    基于STM32的红外遥控重点解析
    红外协议之NEC协议
    常用运放选型一览表
    运放参数解释及常用运放选型
    算放大器分析----虚短和虚断(转载)
  • 原文地址:https://www.cnblogs.com/zjvskn/p/4261216.html
Copyright © 2011-2022 走看看