引用: hczhang03 发表于 2014-3-27 15:48 求代码
#include"ioCC2530.h"
#define d1 P1_1
#define d2 P1_0
#define d3 P1_4
#define d4 P1_3
#define n1 P1_2
#define n2 P0_1
int flag=0;
void ys(int t)
{
int i,j;
for(i=0;i<t;i++)
{
for(j=0;j<240;j++)
{
asm("NOP");
asm("NOP");
asm("NOP");
//while(flag);
}
}
}
#pragma vector = P1INT_VECTOR
__interrupt void Int1_Sevice()
{
if(P1IFG & 0x04)
{
while(n1==0)break;
ys(50);
while(n1==1)break;
if(flag==0)
{
flag=1;
P1SEL |=0x80;
P1DIR &=~0x80;
P2SEL |=~0x01;
P2DIR &=~0x01;
}
while(n2==0);
{
ys(50);
while(n2==1);
{
flag=0;
}
}
P1IFG &=~0x04;
}
P1IF=0;
}
void main()
{
//继电器
/*P1SEL &=~0x80;
P1DIR |= 0x80;
P2SEL &=~0x01;
P2DIR |=0x01;*/
P1SEL &= ~0x5F;
P1DIR |= 0x5B;
P1DIR &= ~0x04;
P0SEL &= ~0x02;
P0DIR &= ~0x02;
IEN2 |= 0x10;
P1IEN |= 0x04;
PICTL |= 0x02;
EA=1;
d1=1;d2=0;d3=0;d4=0;
while(flag==0)
{
if(n2==0)
{
ys(50);
if(n2==0)
{
while(1)
{
P1SEL &=~0x80;
P1DIR |= 0x80;
P2SEL &=~0x01;
P2DIR |=0x01;
d1=1;d2=0;d3=0;d4=0;
ys(500);
d1=0;d2=1;d3=0;d4=0;
ys(500);
d1=0;d2=0;d3=1;d4=0;
ys(500);
d1=0;d2=0;d3=0;d4=1;
ys(500);
}
}
}
}
}