网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
05月05日漏签0天
msp430吧 关注:7,565贴子:16,091
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 0回复贴,共1页
<<返回msp430吧
>0< 加载中...

2553用149的4X4按键矩阵程序,出现一点问题,请帮我看看哪儿出问

  • 只看楼主
  • 收藏

  • 回复
  • 卟崤ぃ
  • 默默无闻
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include <msp430g2553.h>
//端口初始化程序
void Init_Port(void)
{
//将P1口所有的管脚在初始化的时候设置为输入方式
P1DIR = 0;
//将P1所有的管脚设置为一般
P1SEL = 0;
//将P1.4 5 6 7 设置为输出方式
P1DIR |= BIT4;
P1DIR |= BIT5;
P1DIR |= BIT6;
P1DIR |= BIT7;
//先输出低电平
P1OUT =0x00;
return;
}
void Delay(void)
{
int i;
for (i=100;i>0;i--);
}
//按键分析程序
int KeyProcess(void)
{
int nP10=0,nP11=0,nP12=0,nP13=0;
int nRes=0;
//P1.4输出低电平
P1OUT&=~(BIT4);
nP10=P1IN&BIT0;
if (nP10==0) nRes=13;
nP11=(P1IN&BIT1)>>1;
if (nP11==0) nRes=14;
nP12=(P1IN&BIT2)>>2;
if (nP12==0) nRes=15;
nP13=(P1IN&BIT3)>>3;
if (nP13==0) nRes=16;
//P1.5输出低电平
P1OUT&=~(BIT5);
nP10=P1IN&BIT0;
if (nP10==0) nRes=9;
nP11=(P1IN&BIT1)>>1;
if (nP11==0) nRes=10;
nP12=(P1IN&BIT2)>>2;
if (nP12==0) nRes=11;
nP13=(P1IN&BIT3)>>3;
if (nP13==0) nRes=12;
//P1.6输出低电平
P1OUT&=~(BIT6);
nP10=P1IN&BIT0;
if (nP10==0) nRes=5;
nP11=(P1IN&BIT1)>>6;
if (nP11==0) nRes=6;
nP12=(P1IN&BIT2)>>2;
if (nP12==0) nRes=7;
nP13=(P1IN&BIT3)>>3;
if (nP13==0) nRes=8;
//P1.7输出低电平
P1OUT&=~(BIT7);
nP10=P1IN&BIT0;
if (nP10==0) nRes=1;
nP11=(P1IN&BIT1)>>1;
if (nP11==0) nRes=2;
nP12=(P1IN&BIT2)>>2;
if (nP12==0) nRes=3;
nP13=(P1IN&BIT3)>>3;
if (nP13==0) nRes=4;
P1OUT = 0x00; //恢复以前值
//读取各个管脚的状态
nP10=P1IN&BIT0;
nP11=(P1IN&BIT1)>>1;
nP12=(P1IN&BIT2)>>2;
nP13=(P1IN&BIT3)>>3;
for(;;)
{
if(nP10==1&&nP11==1&&nP12==1&&nP13==1)
{
//有按键被按下,跳出,执行下边程序
break;
}
}
return nRes;
}
//键盘扫描程序
void KeyScan (void)
{
int nP10=0,nP11=0,nP12=0,nP13=0;
int nRes=0;
//是否有按键被按下
while (nP10==0||nP11==0||nP12==0||nP13==0)
{
//有按键被按下,跳出,执行下边程序
break;
}
Delay();
//读取各个管脚的状态
nP10=P1IN&BIT0;
nP11=(P1IN&BIT1)>>1;
nP12=(P1IN&BIT2)>>2;
nP13=(P1IN&BIT3)>>3;
}
//是否有按键被按下
if (nP10==0||nP11==0||nP12==0||nP13==0)
{
//如果没有
nRes = KeyProcess();
}
else return -1;//没有输入,为干扰
return nRes;
}
//请帮忙看看问题都出在哪里


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 0回复贴,共1页
<<返回msp430吧
分享到:
©2026 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示