找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3310|回复: 0
打印 上一主题 下一主题
收起左侧

fengdong+_EINT()

[复制链接]
跳转到指定楼层
楼主
ID:262 发表于 2014-10-21 15:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "msp430G2553.h"
int tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
          0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
int temp,time;
//毫秒延迟函数
void delay(int ms)
{
  int i;
  while(ms--)
    for(i=0;i<200;i++);
}
//纳米延迟函数
void delayns(int ns)
{
  while(ns--);
}
void display(temp)//现实位置P2.0=SH;P2.1=ST;P2,2=DS
{
  int k,temp1,temp2;
   for(k=7;k>=0;k--)
     {
       temp1=1<<k;
       temp2=temp & temp1;
       if(temp2==temp1)
           {
             P2OUT |=BIT2;
           }
       else
           {
             P2OUT &=~BIT2;
           }
       P2OUT &=~BIT0;
       delayns(10);
       P2OUT |=BIT0;
     }
   P2OUT &=~BIT1;
   delayns(10);
   P2OUT |=BIT1;  
}
int main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  DCOCTL=CALDCO_16MHZ;
  BCSCTL1 = CALBC1_16MHZ;
  BCSCTL2 |=SELM_1+DIVM_0;
  P2DIR |=BIT3+BIT2+BIT1+BIT0;//P2.3电机PWM输出,P2.2,P2.1,P2.0为I2C显示输出
  P1DIR =0x41;
  P1REN |=BIT4+BIT5;
  P1OUT |=BIT4+BIT5;
  P1IE  |=BIT4+BIT5;
  P1IES |=BIT4+BIT5;
  P1IFG &=~(BIT6+BIT4+BIT5);
  _EINT();
  P1DIR |=BIT6;
  int m,time=0,temp;
    while(1)
     {
       m=P1IN;
       //显示
       temp=tab[(2*m)%10];//个位
       display(temp);
       temp=tab[(2*m)/10];//十位
       display(temp);

       P1OUT |=BIT6+BIT0;
       delay(time);
       P1OUT &=~(BIT6+BIT0);
       delay(2000);
     }
}
#pragma vector=PORT1_VECTOR
__interrupt  void ddd(void)
{
   if(P1IFG==BIT4)
   {
     //脉宽
     time +=50;
     if (time>2000)time=2000;   

   }
   P1IFG &=~BIT4;

    if(P1IFG==BIT5)
   {
      //脉宽
     time -=100;
     if (time<200)time=300;
   }
   P1IFG &=~BIT5;

    if(P1IFG==BIT6)
   {

   }
   P1IFG &=~BIT6;
}
//===========EINT()=========================//
#include "MSP430F2272.h"
int temp;     //中断中的变量要是全局变量,必须一开始就定义
int main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
P1DIR=0XFF;
P1OUT=0X00;
P2DIR=0X00;
  P2REN |=BIT0;
  P2OUT |=BIT0;
  P2IE  |=BIT0;
  P2IES |=BIT0;
  P2IFG &=~(BIT0);
  _EINT();
  while(1);
}
#pragma vector=PORT2_VECTOR
__interrupt  void ddd(void)
{   
  P1OUT=1<<temp;
  temp++;
  if(temp==8)temp=0;
   P2IFG &=~BIT0;
}


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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