zoukankan      html  css  js  c++  java
  • DSP28335矩阵键盘的检测

    #include "DSP2833x_Device.h"
    #include "DSP2833x_Examples.h"
    char temp;
    void gpio_init(void)
    {
     EALLOW;
     GpioCtrlRegs.GPBMUX2.all=0x0000;
     GpioCtrlRegs.GPBDIR.bit.GPIO50=1;
     GpioCtrlRegs.GPBDIR.bit.GPIO49=1;
     GpioCtrlRegs.GPBDIR.bit.GPIO48=1;
     GpioCtrlRegs.GPBPUD.bit.GPIO53=1;
     GpioCtrlRegs.GPBPUD.bit.GPIO52=1;
     GpioCtrlRegs.GPBPUD.bit.GPIO51=1;
     GpioCtrlRegs.GPBDIR.bit.GPIO53=0;
     GpioCtrlRegs.GPBDIR.bit.GPIO52=0;
     GpioCtrlRegs.GPBDIR.bit.GPIO51=0;
     GpioCtrlRegs.GPAMUX1.all=0x0000;
     GpioCtrlRegs.GPADIR.all=0xffff;
     EDIS;
    }
    void delay(void)
    {
     long int i,j;
     for(i=0;i<20;i++)
      for(j=0;j<10;j++);
    }

    void delay1(void)
    {
     long int i,j;
     for(i=0;i<200;i++)
      for(j=0;j<100;j++);
    }
    void all_on(void)
    {
     GpioDataRegs.GPBCLEAR.bit.GPIO50=1;
     GpioDataRegs.GPBCLEAR.bit.GPIO49=1;
     GpioDataRegs.GPBCLEAR.bit.GPIO48=1; 
    }
    char matrix_key(void)
    {
     all_on();
     if(GpioDataRegs.GPBDAT.bit.GPIO53==0)
     {
      delay1();
      if(GpioDataRegs.GPBDAT.bit.GPIO53==0){
      GpioDataRegs.GPBSET.bit.GPIO50=1;
      delay();
      if(GpioDataRegs.GPBDAT.bit.GPIO53==1)   
       temp=1;
      else temp=temp;
      all_on();
      GpioDataRegs.GPBSET.bit.GPIO48=1;
      delay();
      if(GpioDataRegs.GPBDAT.bit.GPIO53==1)   
       temp=2;
      else temp=temp;
      all_on();
      GpioDataRegs.GPBSET.bit.GPIO49=1;
      delay();
      if(GpioDataRegs.GPBDAT.bit.GPIO53==1)   
       temp=3;
      else temp=temp;
      }
     }
     all_on();
     if(GpioDataRegs.GPBDAT.bit.GPIO52==0)
     {
      delay1();
      if(GpioDataRegs.GPBDAT.bit.GPIO52==0){
      GpioDataRegs.GPBSET.bit.GPIO50=1;
      delay();
      if(GpioDataRegs.GPBDAT.bit.GPIO52==1)   
       temp=4;
      else temp=temp;
      all_on();
      GpioDataRegs.GPBSET.bit.GPIO48=1;
      delay();
      if(GpioDataRegs.GPBDAT.bit.GPIO52==1)   
       temp=5;
      else temp=temp;
      all_on();
      GpioDataRegs.GPBSET.bit.GPIO49=1;
      delay();
      if(GpioDataRegs.GPBDAT.bit.GPIO52==1)   
       temp=6;
      else temp=temp;
      }
     }
     all_on();
     if(GpioDataRegs.GPBDAT.bit.GPIO51==0)
     {
      delay1();
      if(GpioDataRegs.GPBDAT.bit.GPIO51==0){
      GpioDataRegs.GPBSET.bit.GPIO50=1;
      delay();
      if(GpioDataRegs.GPBDAT.bit.GPIO51==1)   
       temp=7;
      else temp=temp;
      all_on();
      GpioDataRegs.GPBSET.bit.GPIO48=1;
      delay();
      if(GpioDataRegs.GPBDAT.bit.GPIO51==1)   
       temp=8;
      else temp=temp;
      all_on();
      GpioDataRegs.GPBSET.bit.GPIO49=1;
      delay();
      if(GpioDataRegs.GPBDAT.bit.GPIO51==1)   
       temp=9;
      else temp=temp;
      }
     }
     return temp;
    }
    void main(void)
    {
     gpio_init();
     temp=0;
     for(;;)
     {
     // matrix_key();
     // GpioDataRegs.GPADAT.all=temp;
     // delay();
      GpioDataRegs.GPADAT.all=~matrix_key();
     }
    }

  • 相关阅读:
    React-使用combineReducers完成对数据对拆分管理
    Linux
    Linux
    linux
    linux
    Linux
    Linux
    Linux
    Linux
    Linux 系统基础优化和常用命令
  • 原文地址:https://www.cnblogs.com/luxiaolai/p/3283724.html
Copyright © 2011-2022 走看看