Nghiên cứu Khoa học

Chương trình cho Robot phục vụ

  • 18/03/2024
  • Nghiên cứu Khoa học

 #include "msp430f2013.h"

#define Trai (_P1_IN->_BIT.b5)//DINH NGHIA cam bien Trai tai P1.5
#define Phai (_P1_IN->_BIT.b6)//DINH NGHIA cam bian Phai tai P1.6

#define IN1 (_P1_OUT->_BIT.b0)//DINH NGHIA IN1 LA NGA VAO DONG CO
#define IN2 (_P1_OUT->_BIT.b1)//DINH NGHIA IN2 LA NGA VAO DONG CO


#define IN3 (_P1_OUT->_BIT.b2)//DINH NGHIA IN3 LA NGA VAO DONG CO
#define IN4 (_P1_OUT->_BIT.b3)//DINH NGHIA IN4 LA NGA VAO DONG CO
void ___no_operation(void);
void __delay_cycles(unsigned long __cycles);

union reg{//dinh nghia bit
struct bit {
unsigned char b0:1;
unsigned char b1:1;
unsigned char b2:1;
unsigned char b3:1;
unsigned char b4:1;
unsigned char b5:1;
unsigned char b6:1;
unsigned char b7:1;
}_BIT;
unsigned char_BYTE;
};

union reg* _P1_DIRECT=(union reg*)0x22;
union reg* _P1_OUT=(union reg*)0x21;

union reg* _P1_IN=(union reg*)0x20;

void chay_toi(void)
{
if((Trai==1)&&(Phai==1))
{ IN1=1;//2 MOTOR QUAY THUAN
IN2=0;// chay toi


IN3=1;
IN4=0;

}
}
void re_phai(void)
{
if((Trai==0)&&(Phai==1))
{

//__delay_cycles(200000);
IN1=1;// MOTOR TRAI QUAY TOI
IN2=0;

IN3=0;
IN4=1;//MOTOR PHAI LUI
// __delay_cycles(200000);

}
}
void re_trai(void)
{
if((Trai==1)&&(Phai==0))
{ IN1=0;// MOTOR trai LUI
IN2=1;

IN3=1;
IN4=0;//MOTOR PHAI CHAY TOI
}
}
void chay_lui(void)

{
if((Trai==0)&&(Phai==0))
{ IN1=1;// MOTOR trai tien
IN2=0;

IN3=0;
IN4=1;//MOTOR PHAI lui
__delay_cycles(200000);

//{
// IN1=1;// MOTOR trai LUI
// IN2=0;

//IN3=0;
// IN4=1;//MOTOR PHAI chay toi
// __delay_cycles(200000);
// }
// IN1=0;// MOTOR trai LUI
// IN2=1;

// IN3=0;
//IN4=1;//MOTOR PHAI chay toi
// __delay_cycles(200000);
// }

}
}

void main( void )
{ // Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;

_P1_DIRECT->_BIT.b5=0;
_P1_DIRECT->_BIT.b6=0;

_P1_DIRECT->_BIT.b0=1;
_P1_DIRECT->_BIT.b1=1;
_P1_DIRECT->_BIT.b2=1;
_P1_DIRECT->_BIT.b3=1;




while(1)
{
chay_toi();
__delay_cycles(500);

re_phai();

__delay_cycles(500);
re_trai();

__delay_cycles(500);
chay_lui();

}
}

Các tin khác