📄 main.c
字号:
P2IE|=BIT1;
P2IES&=~BIT1;
P2IE|=BIT0;
P2IES&=~BIT0;
}
void init_timer_a()
{
TACTL=TASSEL0+MC0+TACLR;
TACCTL0=CCIE;
TACCR0=300;
}
void init_timer_b()
{
TBCTL=TBSSEL0+MC0+TBCLR;//ACLK 连续计数模式
TBCCTL0=CCIE;
TBCCR0=8192; //32768;
}
#pragma vector=TIMERA0_VECTOR
__interrupt void timer_a0_isr()
{
temp7=rd_front(); //前排灯数据
temp8=rd_back(); //后排灯数据
counter=counter_table(); //数格
}
#pragma vector=PORT2_VECTOR
__interrupt void port2_isr()
{
P2IE&=~BIT1;
P2IE&=~BIT0;
if(P2IFG&BIT1)
{sign_position++;}
if(P2IFG&BIT0)
{hand_sign++;}
P2IFG&=~BIT1;
P2IFG&=~BIT0;
}
#pragma vector=TIMERB0_VECTOR
__interrupt void timerb0_isr()
{
t++;
if(t==1)
{
t=0;
t1=0;
}
}
void delay2s()
{
init_timer_b();
_EINT();
while(t1);
t1=1;
TBCCTL0&=~CCIE;
}
void stop()//pwm=0刹车
{
P5OUT&=~BIT2;
P5OUT&=~BIT3;
check_busy();
wr_cmd(LTRJ);
DELAY();
check_busy();
wr_data(0x04);
DELAY();
check_busy();
wr_data(0x00);
DELAY();
//v
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(0x00);
DELAY();
//position
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_cmd(STT);
DELAY();
P5OUT|=BIT2;
P5OUT|=BIT3;
}
unsigned int rd_front()
{
P6OUT&=~BIT7;
P6OUT|=BIT6;
DELAY();
temp1=P2IN;
temp2=P3IN;
temp1&=0xe0;
temp3=(int)temp1;
temp4=(int)temp2;
temp5=(temp4<<8)+temp3;//前排灯的数据
return temp5;
}
unsigned char rd_back()
{
P6OUT&=~BIT6;
P6OUT|=BIT7;
DELAY();
temp2=P3IN;
temp6=temp2&0xfe; //后排灯数据
return temp6;
}
unsigned char counter_table()
{
P6OUT|=BIT6;
P6OUT&=~BIT7;
DELAY();
counter1=0;
temp1=P2IN;
temp2=P3IN;
temp1&=0xe0;
temp3=(int)temp1;
temp4=(int)temp2;
temp5=(temp4<<8)+temp3;//前排灯的数据
counter1=((temp5&0x8000)>>15)+((temp5&0x4000)>>14)+((temp5&0x2000)>>13)+((temp5&0x1000)>>12)+((temp5&0x0800)>>11)+((temp5&0x0400)>>10)+((temp5&0x0200)>>9)+((temp5&0x0100)>>8)+((temp5&0x0080)>>7)+((temp5&0x0040)>>6)+((temp5&0x0020)>>5);
if(counter1<=6){sign=1;}
if((sign==1)&(counter1>8))
{counter2++;sign=0;}
return counter2;
}
void turn_left(unsigned char v1,unsigned char v2,unsigned char v3 )
{
P5OUT&=~BIT3;//CS=0
check_busy();
wr_cmd(RSTI);
DELAY();
check_busy();
filter_sel();
DELAY();
check_busy();
traj_sel2( v1, v2, v3,0x00,0xff,0xff,0xff);
DELAY();
P5OUT|=BIT3;//CS=1
DELAY();
P5OUT&=~BIT2;//CS=0
check_busy();
wr_cmd(RSTI);
DELAY();
check_busy();
filter_sel();
DELAY();
check_busy();
traj_sel2(0x00,0xa0,0xFF,0x00,0xff,0xff,0xff);
DELAY();
P5OUT|=BIT2;//CS=1
}
void turn_right(unsigned char v4,unsigned char v5,unsigned char v6)
{
P5OUT&=~BIT2;//CS=0
check_busy();
wr_cmd(RSTI);
DELAY();
check_busy();
filter_sel();
DELAY();
check_busy();
traj_sel2( v4, v5, v6,0x00,0xff,0xff,0xff);
DELAY();
P5OUT|=BIT2;//CS=1
DELAY();
P5OUT&=~BIT3;//CS=0
check_busy();
wr_cmd(RSTI);
DELAY();
check_busy();
filter_sel();
DELAY();
check_busy();
traj_sel2(0x00,0xa0,0xFF,0x00,0xff,0xff,0xff);
DELAY();
P5OUT|=BIT3;//CS=1
}
void run_stright()
{
P5OUT&=~BIT2;//CS=0
check_busy();
wr_cmd(RSTI);
DELAY();
filter_sel();
DELAY();
traj_sel2(0x00,0xb5,0xFF,0x00,0xff,0xff,0xff);
DELAY();
P5OUT|=BIT2;//CS=1
P5OUT&=~BIT3;//CS=0
wr_cmd(RSTI);
DELAY();
filter_sel();
DELAY();
traj_sel2(0x00,0xb5,0xFF,0x00,0xff,0xff,0xff);
DELAY();
P5OUT|=BIT3;//CS=1
}
void run_back()
{
P5OUT&=~BIT7;
DELAY();
P5OUT|=BIT7;
P5OUT&=~BIT2;//CS=0
check_busy();
wr_cmd(RSTI);
DELAY();
filter_sel();
DELAY();
traj_sel2(0x00,0x80,0xff,0xc0,0xff,0xff,0xff);
DELAY();
P5OUT|=BIT2;//CS=1
P5OUT&=~BIT3;//CS=0
wr_cmd(RSTI);
DELAY();
filter_sel();
DELAY();
traj_sel2(0x00,0x80,0xff,0xc0,0xff,0xff,0xff);
DELAY();
P5OUT|=BIT3;//CS=1
}
void traj_sel2(unsigned char a,unsigned char b,unsigned char c,unsigned char h,unsigned char d,unsigned char e,unsigned f)
{
check_busy();
wr_cmd(LTRJ);
DELAY();
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(0x0a);
DELAY();
//v
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(a);
DELAY();
check_busy();
wr_data(b);
DELAY();
check_busy();
wr_data(c);
DELAY();
//position
check_busy();
wr_data(h);
DELAY();
check_busy();
wr_data(d);
DELAY();
check_busy();
wr_data(e);
DELAY();
check_busy();
wr_data(f);
DELAY();
check_busy();
wr_cmd(STT);
DELAY();
}
void turn_position_left_two(unsigned char a,unsigned char b,unsigned char c,unsigned char d)
{
unsigned char ps1,ps2,ps3,ps4, ps5,ps6,ps7,ps8,dec_ps8=0,dec_ps7=0, state_left;
unsigned int ps9,psa;
P5OUT&=~BIT3;//CS=0
check_busy();
wr_cmd(RDRP);
DELAY();
check_busy();
ps1=rd_data();
DELAY();
check_busy();
ps2=rd_data();
DELAY();
check_busy();
ps3=rd_data();
DELAY();
check_busy();
ps4=rd_data();
if((ps4+b)>0xff)
{ps3++;}
if((ps3+a)>0xff)
{ps2++;}
check_busy();
wr_cmd(RSTI);
DELAY();
check_busy();
filter_sel();
DELAY();
check_busy();
wr_cmd(LTRJ);
DELAY();
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(0x0a);
DELAY();
//v
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(0X00);
DELAY();
check_busy();
wr_data(0Xde);
DELAY();
check_busy();
wr_data(0Xff);
DELAY();
//position
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(ps2);
DELAY();
check_busy();
wr_data(ps3+a);
DELAY();
check_busy();
wr_data(ps4+b);
DELAY();
P5OUT|=BIT3;//CS=1
P5OUT&=~BIT2;//CS=0
check_busy();
wr_cmd(RDRP);
DELAY();
check_busy();
ps5=rd_data();
DELAY();
check_busy();
ps6=rd_data();
DELAY();
check_busy();
ps7=rd_data();
DELAY();
check_busy();
ps8=rd_data();
if(ps8<d)
{
dec_ps8=1;
ps9=(int)ps8+0xff;
ps9=ps9-(int)d;
ps8=(unsigned char)ps9;
ps7-=0x01;
}
if(ps7<c)
{
dec_ps7=1;
psa=(int)ps7+0xff;
psa=psa-(int)c;
ps7=(unsigned char)psa;
ps6-=0x01;
}
check_busy();
wr_cmd(RSTI);
DELAY();
check_busy();
filter_sel();
DELAY();
check_busy();
wr_cmd(LTRJ);
DELAY();
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(0x0a);
DELAY();
//v
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(0X00);
DELAY();
check_busy();
wr_data(0Xde);
DELAY();
check_busy();
wr_data(0Xff);
DELAY();
//position
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(ps6);
DELAY();
if(dec_ps7==1)
{
dec_ps7=0;
check_busy();
wr_data(ps7);
}
else
{
check_busy();
wr_data(ps7-c);
}
DELAY();
if(dec_ps8==1)
{
dec_ps8=0;
check_busy();
wr_data(ps8);
}
else
{
check_busy();
wr_data(ps8-d);
}
DELAY();
P5OUT|=BIT2;//CS=1
DELAY();
P5OUT&=~BIT2;//CS=0
P5OUT&=~BIT3;//CS=0
check_busy();
wr_cmd(STT);
DELAY();
check_busy();
P5OUT|=BIT2;
P5OUT|=BIT3;
P5OUT&=~BIT3;
do
{state_left= rd_st();}
while((state_left&0x04)==0);
P5OUT|=BIT3;
access_sign_left_two++;
sign_clockwise=1;
}
void turn_position_right_two(unsigned char e,unsigned char f,unsigned char g,unsigned char h)
{
unsigned char ps1,ps2,ps3,ps4, ps5,ps6,ps7,ps8,dec_ps3,dec_ps4,state_right;
unsigned int ps9,psa;
P5OUT&=~BIT2;//CS=0
check_busy();
wr_cmd(RDRP);
DELAY();
check_busy();
ps5=rd_data();
DELAY();
check_busy();
ps6=rd_data();
DELAY();
check_busy();
ps7=rd_data();
DELAY();
check_busy();
ps8=rd_data();
if((ps8+f)>0xff)
{ps7++;}
if((ps7+e)>0xff)
{ps6++;}
check_busy();
wr_cmd(RSTI);
DELAY();
check_busy();
filter_sel();
DELAY();
check_busy();
wr_cmd(LTRJ);
DELAY();
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(0x0a);
DELAY();
//v
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(0X00);
DELAY();
check_busy();
wr_data(0Xde);
DELAY();
check_busy();
wr_data(0Xff);
DELAY();
//position
check_busy();
wr_data(0x00);
DELAY();
check_busy();
wr_data(ps6);
DELAY();
check_busy();
wr_data(ps7+e);
DELAY();
check_busy();
wr_data(ps8+f);
DELAY();
P5OUT|=BIT2;//CS=1
P5OUT&=~BIT3;//CS=0
check_busy();
wr_cmd(RDRP);
DELAY();
check_busy();
ps1=rd_data();
DELAY();
check_busy();
ps2=rd_data();
DELAY();
check_busy();
ps3=rd_data();
DELAY();
check_busy();
ps4=rd_data();
if(ps4<h)
{
dec_ps4=1;
ps9=(int)ps4+0xff;
ps9=ps9-(int)h;
ps4=(unsigned char)ps9;
ps3-=0x01;
}
if(ps3<g)
{
dec_ps3=1;
psa=(int)ps3+0xff;
psa=psa-(int)g;
ps3=(unsigned char)psa;
ps2-=0x01;
}
check_busy();
wr_cmd(RSTI);
DELAY();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -