DSP28335矩阵键盘的检测

本文介绍了一个基于DSP2833x设备的矩阵键盘扫描程序实现。该程序通过配置GPIO并使用延迟函数来确保准确读取按键状态。文章详细展示了初始化GPIO、设置延迟以及读取按键值的具体代码。

#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();
 }
}

转载于:https://www.cnblogs.com/luxiaolai/p/3283724.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值