色婷婷AⅤ一区二区三区|亚洲精品第一国产综合亚AV|久久精品官方网视频|日本28视频香蕉

          新聞中心

          AVR128的程序——矩陣按鍵

          作者: 時(shí)間:2016-11-22 來(lái)源:網(wǎng)絡(luò) 收藏
          #include
          #include
          #define uchar unsigned char
          #define uint unsigned int
          void Delayms(uint MS);
          uchar key_scan(void);
          void init_io(void);
          uchar led_discode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
          0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};
          uchar key_val=0;
          void main (viod)
          {
          uchar key_io;
          init_io();
          while(1)
          {
          PORTD=0XF0;
          Delayms(5);
          key_io=PIND & 0xf0;
          if(key_io !=0xf0)
          {
          PORTD=0XF0;
          Delayms(1);
          key_io=PIND & 0xf0;
          if(key_io !=0xf0)
          {
          key_val=key_scan();
          key_val |= key_io ;
          }
          switch(key_val)
          {
          case 0xee: key_val=0x00; break; //按鍵K1
          case 0xde: key_val=0x01; break; //按鍵K2
          case 0xbe: key_val=0x02; break; //按鍵K3
          case 0x7e: key_val=0x03; break; //按鍵K4
          case 0xed: key_val=0x04; break; //按鍵K5
          case 0xdd: key_val=0x05; break; //按鍵K6
          case 0xbd: key_val=0x06; break; //按鍵K7
          case 0x7d: key_val=0x07; break; //按鍵K8
          case 0xeb: key_val=0x08; break; //按鍵K9
          case 0xdb: key_val=0x09; break; //按鍵K10
          case 0xbb: key_val=0x0a; break; //按鍵K11
          case 0x7b: key_val=0x0b; break; //按鍵K12
          case 0xe7: key_val=0x0c; break; //按鍵K13
          case 0xd7: key_val=0x0d; break; //按鍵K14
          case 0xb7: key_val=0x0e; break; //按鍵K15
          case 0x77: key_val=0x0f; break; //按鍵K16
          }
          }
          PORTD=0XF0;
          key_io=PIND & 0xf0;
          while(key_io !=0xf0)
          {
          key_io=PIND & 0xf0;
          }
          PORTC=led_discode[key_val];
          }
          }
          void init_io(void)
          {
          DDRA=0XFF;
          PORTA=0XFF;
          DDRB=0XFF;
          PORTB=0XFF;
          DDRC=0XFF;
          PORTC=0XFF;
          DDRD=0X0F;
          PORTD=0XF0;
          DDRF=0X0E;
          PORTF=0X0E;
          PORTF&=0XF7;
          DDRB |=0X10;
          PORTB|=0X10;
          }
          uchar key_scan(void)
          {
          uchar m,temp=0xf7;
          for(m=0;m<4;m++)
          {
          PORTD=temp | 0xf0;
          Delayms(1);
          if((PIND & 0XF0)!=0XF0)
          return(temp & 0x0f);
          temp>>=1;
          }
          }
          void Delayms(uint MS)
          {
          uint i,j;
          for( i=0;i
          for(j=0;j<1141;j++);
          }


          關(guān)鍵詞: AVR128矩陣按

          評(píng)論


          技術(shù)專(zhuān)區(qū)

          關(guān)閉