Home > other >  For single chip microcomputer msp430g2553 problem. Urgent solution.
For single chip microcomputer msp430g2553 problem. Urgent solution.

Time:10-02


# include "msp430g2553. H"
# define uchar unsigned char
# define uint unsigned int

# define hongwai1 P1IN & amp; BIT5
# define hongwai2 P1IN & amp; BIT7




# define IN1_H P1OUT |=BIT3//motor input IN1 high level
# define IN1_L P1OUT & amp;=(~ BIT3)//IN1 L
# define IN2_H P1OUT |=BIT4//IN2 H
# define IN2_L P1OUT & amp;=(~ BIT4)//motor input IN2 low level
# define IN3_H P1OUT |=BIT6//motor input IN3 high level
# define IN3_L P1OUT & amp;=(~ BIT6)//IN3 L
# define IN4_H P2OUT |=BIT5//IN4 H
# define IN4_L P2OUT & amp;=(~ BIT5)//motor input IN4 low level
# define uchar unsigned char
Void xunji ();
Void kong_zhi (uchar uchar uchar uchar a0, a1, a2, a3);
Unsigned int buf=0;
Void delay (unsigned int I)//delay subroutine
{
Unsigned int j, k;
for(j=0; JFor (k=0; K<10; K++);

}
Int main (void)
{
WDTCTL=WDTPW + WDTHOLD;//off guard dog

TA0CCTL1=OUTMOD_7;//PWM reset/setting mode
TA1CCTL1=OUTMOD_7;//count ceiling, count to counter reset when the value, the output setting
TA0CCR0=0 x0500;
TA0CCR1=0 x0000;
TA1CCR0=0 x0500;
TA1CCR1=0 x0000;
//count to the reset output value is
TA0CTL=TASSEL_2 + MC_1;//set Timer0
P1DIR |=BIT3 + BIT4;
P1DIR |=BIT2 + BIT6;//1.2 and 1.6 set to output
P2DIR |=BIT1 + BIT5;//2.1 and 2.5 set to output
P1SEL |=BIT2;//open the second function
1.2//P1DIR |=0 x40;//P1.6 output PWM
//P1SEL |=0 x40;
TA1CTL=TASSEL_2 + MC_1;

P2SEL |=BIT1;//2.1 open the second function
P2SEL2 & amp;=~ BIT1;//P2SEL2 port p2 choice 2
P1DIR & amp;=(~ BIT5) + (~ BIT7);
P1OUT |=BIT5 + BIT7;//1.5 1.7 high level output
P1REN |=BIT5 + BIT7;//resistance can make
While (1)
{xunji ();
delay(10);
For (buf=0; Buf<0 x500; Buf++)//change the duty ratio, form breathing light effect
{
TA0CCR1=buf;
delay(10);
}
For (buf=0 x500; Buf> 0; Buf -)
{
TA0CCR1=buf;
TA1CCR1=buf;
delay(10);
}
}
}



Void kong_zhi (uchar uchar uchar uchar a0, a1, a2, a3)
{

If (a0==1)
IN1_H;
The else
IN1_L;
If (a1==1)
IN2_H;
The else
IN2_L;
If (a2==1)
IN3_H;
The else
IN3_L;
If (a3==1)
IN4_H;
The else
IN4_L;

}
Void xunji ()//tracking subprogram
{

If ((P1IN & amp; BIT5)==0 x00 & amp; & (P1IN & amp; BIT7)==0 x00)
{
,0,1,0 kong_zhi (1);//all the white line is detected, the car forward
}

If ((P1IN & amp; BIT5)==0 x00 & amp; & (P1IN & amp; BIT7)!=0 x00)
{
,0,0,1 kong_zhi (1);//if 7 inspection to the black and white lines to the left, the car turn right
}

If ((P1IN & amp; BIT5)!=0 x00 & amp; & (P1IN & amp; BIT7)==0 x00)
{
,1,1,0 kong_zhi (0);//if (4) to detect the black thread, (3) (5) was detected in 6 white line slants to the right, the car turn left
}
If ((P1IN & amp; BIT5)!=0 x00 & amp; & (P1IN & amp; BIT7)!=0 x00)
{-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
,0,1,0 kong_zhi (1);
}


}
Want to ask next the output pin of receiving l298n and l298n can make termination, urgent for the answer thank
  • Related