//chuong trinh di thang theo vach
#include <AT89x52.H>
#include<intrins.h>
#define EN12 P1_0
#define EN34 P1_1
#define IN1 P1_2
#define IN2 P1_3
#define IN3 P1_4
#define IN4 P1_5
#define S_phai P3_3
#define S_trai P3_0
#define S_truoc P3_2
#define S_sau P3_1
#define nen 0
#define vach 1
void dithang()
{EN12=EN34=IN1=IN3=vach;IN2=IN4=nen; }
void re_phai()
{EN12=IN1=vach;IN2=EN34=nen;}
void re_trai()
{EN12=IN4=nen;EN34=IN3=vach;}
void stop()
{EN12=EN34=nen;}
void kiem_tra_vach()
{
if ((S_phai==nen&&S_trai==nen)) {dithang();} // va^~n cái dòng quái quy? này!
else if ((S_phai==vach&&S_trai==nen)) {re_phai();}
else if (S_phai==nen&&S_trai==vach) {re_trai();}
else if (S_truoc==S_sau==nen) {stop();};
}
void main()
{
while (1)
{
kiem_tra_vach();
}
}
#include <AT89x52.H>
#include<intrins.h>
#define EN12 P1_0
#define EN34 P1_1
#define IN1 P1_2
#define IN2 P1_3
#define IN3 P1_4
#define IN4 P1_5
#define S_phai P3_3
#define S_trai P3_0
#define S_truoc P3_2
#define S_sau P3_1
#define nen 0
#define vach 1
void dithang()
{EN12=EN34=IN1=IN3=vach;IN2=IN4=nen; }
void re_phai()
{EN12=IN1=vach;IN2=EN34=nen;}
void re_trai()
{EN12=IN4=nen;EN34=IN3=vach;}
void stop()
{EN12=EN34=nen;}
void kiem_tra_vach()
{
if ((S_phai==nen&&S_trai==nen)) {dithang();} // va^~n cái dòng quái quy? này!
else if ((S_phai==vach&&S_trai==nen)) {re_phai();}
else if (S_phai==nen&&S_trai==vach) {re_trai();}
else if (S_truoc==S_sau==nen) {stop();};
}
void main()
{
while (1)
{
kiem_tra_vach();
}
}
Comment