Obstacle Detector Robo
Code:
#pragma config OSC = HS
#pragma config OSCS = OFF
#pragma config PWRT = OFF
#pragma config BOR = ON
#pragma config BORV = 45
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config DEBUG = OFF
#pragma config STVR = OFF
#define m0 PORTB.F0
#define m1 PORTB.F1
#define m2 PORTB.F2
#define m3 PORTB.F3
#define buzz PORTB.F4
#define s1 PORTC.F0
#define s2 PORTC.F1
#define s3 PORTC.F2
void main()
{
TRISC= 0xff;
TRISB= 0x00;
while(1)
{
buzz=0;
while(s1==1 && s2==1 && s3==0)
{
m0=1;
m1=0;
m2=1;
m3=0;
}
while(s1==1 && s2==0 && s3==0) //rite
{
m0=0;
m1=0;
m2=1;
m3=0;
}
while(s1==0&&s2==1&&s3==0) //left
{
m0=1;
m1=0;
m2=0;
m3=0;
}
while(s1==0&&s2==0&&s3==0)
{
m0=0;
m1=0;
m2=0;
m3=0;
}
while(s1==0&&s2==0&&s3==1)
{
buzz=1;
m0=0;
m1=0;
m2=0;
m3=0;
}
while(s1==0&&s2==1&&s3==1)
{
m0=0;
m1=1;
m2=0;
m3=0;
}
while(s1==1&&s2==1&&s3==1)
{
m0=0;
m1=1;
m2=0;
m3=1;
}
}
}
0 comments:
Post a Comment
if you have any doubt please let me know