Edge 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 s0 PORTC.F0
#define s1 PORTC.F1
#define m0 PORTB.F0
#define m1 PORTB.F1
#define m2 PORTB.F2
#define m3 PORTB.F3
int count=0;
void left()
{
m0=0;
m1=0;
m2=1;
m3=0;
count=1;
}
void right()
{
m0=1;
m1=0;
m2=0;
m3=0;
count=0;
}
void forw()
{
m0=1;
m1=0;
m2=1;
m3=0;
}
void back()
{
m0=0;
m1=1;
m2=0;
m3=1;
}
void main(void)
{
// int count=0;
TRISC= 0x00;
TRISD= 0xff;
while(1)
{
if(s0==1&&s1==1)
{
forw();
}
if(s0==1&&s1==0)
{
right();
}
if(s0==0&&s1==1)
{
left();
}
if(s0==0&&s1==0)
{
back();
delay_ms(1000);
if(count==0)
{
left();
delay_ms(250);
}
else
{
right();
delay_ms(250);
}
}
}
}
0 comments:
Post a Comment
if you have any doubt please let me know