MSP430 14X按键程序范例(附原理图).doc

  1. 1、本文档共5页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
MSP430 14X按键程序范例(附原理图)

/117190815/blog/item/279b44c7332db1dbd1006008.html #i nclude msp430x14x.h void Init_Port(void) { ??? //将P1口所有的管脚在初始化的时候设置为输入方式 ??? P1DIR = 0; ??? //将P1口所有的管脚设置为一般I/O口 ??? P1SEL = 0; ??? ??? // 将P1.4 P1.5 P1.6 P1.7设置为输出方向 ??? P1DIR |= BIT4; ??? P1DIR |= BIT5; P1DIR |= BIT6; ??? P1DIR |= BIT7; //先输出低电平 P1OUT = 0x00; // 将中断寄存器清零 ??? P1IE = 0; ??? P1IES = 0; ??? P1IFG = 0; ??? //打开管脚的中断功能 //对应的管脚由高到低电平跳变使相应的标志置位 ??? P1IE |= BIT0; ??? P1IES |= BIT0; ??? P1IE |= BIT1; ??? P1IES |= BIT1; P1IE |= BIT2; ??? P1IES |= BIT2; ??? P1IE |= BIT3; ??? P1IES |= BIT3; _EINT();//打开中断 ??? return; } void Delay(void) { int i; for(i = 100;i--;i 0) ;//延时一点时间 } int KeyProcess(void) { ??? int nP10,nP11,nP12,nP13; int nRes = 0; //P1.4输出低电平 P1OUT = ~(BIT4); nP10 = P1IN BIT0; if (nP10 == 0) nRes = 13; nP11 = P1IN BIT1; if (nP11 == 0) nRes = 14; nP12 = P1IN BIT2; if (nP12 == 0) nRes = 15; nP13 = P1IN BIT3; if (nP13 == 0) nRes = 16; //P1.5输出低电平 P1OUT = ~(BIT4); nP10 = P1IN BIT0; if (nP10 == 0) nRes = 9; nP11 = P1IN BIT1; if (nP11 == 0) nRes = 10; nP12 = P1IN BIT2; if (nP12 == 0) nRes = 11; nP13 = P1IN BIT3; if (nP13 == 0) nRes = 12; //P1.6输出低电平 P1OUT = ~(BIT4); nP10 = P1IN BIT0; if (nP10 == 0) nRes = 5; nP11 = P1IN BIT1; if (nP11 == 0) nRes = 6; nP12 = P1IN BIT2; if (nP12 == 0) nRes = 7; nP13 = P1IN BIT3; if (nP13 == 0) nRes = 8; //P1.7输出低电平 P1OUT = ~(BIT4); nP10 = P1IN BIT0; if (nP10 == 0) nRes = 1; nP11 = P1IN BIT1; if (nP11 == 0) nRes = 2; nP12 = P1IN BIT2; if (nP12 == 0) nRes = 3; nP13 = P1IN BIT3; if (nP13 == 0) nRes = 4; P1OUT = 0x00;//恢复以前值。 //读取各个管脚的状态 nP10 = P1IN BIT0; nP11 = P1IN BIT1; nP12 = P1IN BIT2; nP13 = P1IN BIT3; for(;;) { ?? if(nP10 == 1 nP11 == 1 nP12 == 1 nP13 == 1) ?? { ??? //等待松开按键 ??? break; ?? } } return nRes; } // 处理来自端口 1 的中断 interrupt [PORT1_VECTOR] void PORT_ISR(void) { Delay(); KeyProcess(); ??? if(P1IFG BIT0) ??? {??? ??? P1IFG = ~(BIT0);// 清除中断标志位 ??? } ??? if(P1IFG BIT1) ??? { ??? P1IFG = ~(BIT1);// 清除中断标志位 ??? } ??? if(P1IFG BIT

文档评论(0)

womei + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档