极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 20128|回复: 1

【大赛原创经验贴】P1口中断控制P2口LED灯点亮

[复制链接]
发表于 2012-7-18 09:23:56 | 显示全部楼层 |阅读模式
用P1口的中断控制P2口的LED灯
  1. #include <msp430x24x.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. uchar table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
  5. uchar key;

  6. void delay(int v)   //延时
  7. {
  8.   while(v!=0)
  9.     v--;
  10. }
  11. void main()
  12. {
  13.   WDTCTL=WDTPW+WDTHOLD;
  14.   P1DIR=0X00;
  15.   P2DIR=0XFF;
  16.   P1IFG=0X00;
  17.   P1IES=0XFF;
  18.   P1IE=0XFF;
  19.   P2OUT=0XFF;
  20.   _EINT();
  21.   while(1)
  22.   {
  23.     P2OUT=table[key];
  24.   }
  25. }
  26. #pragma vector=PORT1_VECTOR
  27. __interrupt void timer()
  28. {
  29.   uchar temp;
  30.   delay(2666);
  31.   if((P1IN&0XFF)==0XFF)//判断是否有中断
  32.   {
  33.     temp=P1IFG;
  34.     switch(temp)
  35.     {
  36.     case 1  :key=0 ;break;
  37.     case 2  :key=1 ;break;
  38.     case 4  :key=2 ;break;
  39.     case 8  :key=3 ;break;
  40.     case 16 :key=4 ;break;
  41.     case 32 :key=5 ;break;
  42.     case 64 :key=6 ;break;
  43.     case 128:key=7 ;break;
  44.     }
  45.   }
  46.   P1IFG=0X00;
  47. }
复制代码
回复

使用道具 举报

发表于 2012-9-28 14:16:39 | 显示全部楼层
为什么看不明白呢?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-18 14:17 , Processed in 0.043035 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表