Học liệu

CODE LẬP TRÌNH ĐIỀU KHIỂN XE TỰ HÀNH VỚI MSP430

  • 18/03/2020
  • Học liệu

#include "msp430f2013.h"

#define Trai (_P1_IN->_BIT.b5)
#define Phai (_P1_IN->_BIT.b6)

#define IN1 (_P1_OUT->_BIT.b0)
#define IN2 (_P1_OUT->_BIT.b1)


#define IN3 (_P1_OUT->_BIT.b2)
#define IN4 (_P1_OUT->_BIT.b3)
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;
IN2=0;

IN3=1;
IN4=0;

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

//__delay_cycles(200000);
IN1=1;
IN2=0;

IN3=0;
IN4=1;
// __delay_cycles(200000);

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

IN3=1;
IN4=0;
}
}
void chay_lui(void)

{
if((Trai==0)&&(Phai==0))
{ IN1=1;
IN2=0;

IN3=0;
IN4=1;
__delay_cycles(200000);

//{
// IN1=1;
// IN2=0;

//IN3=0;
// IN4=1;
// __delay_cycles(200000);
// }
// IN1=0;
// IN2=1;

// IN3=0;
//IN4=1;
// __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