Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to control the motor speed using 89c2051 in SDCC ?

Status
Not open for further replies.

xmfa32

Newbie level 3
Joined
Sep 1, 2007
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,300
Helo everyone.

I'm newbie in micro and robotic, i try to build one, from this site. .

That's robot is worked. But I need help to re-code using sdcc. From that site is using MC51. and this is original code :

#include d:\mc51\8051io.h
#include d:\mc51\8051reg.h
extern register unsigned char speedleft,speedright;
register unsigned char high,low,flag,time;

main()
{
P1=0x40;
P3=0xff;
high = 80;
low = 30;
flag = 0;
time = 50;
Start();
while(1) {
P3|= 0x0f;
Run();
}
}

Start()
{
char exit,key;
exit =1;
while(exit)
{
key = P1;
if((key & 0x40)==0) exit=0;
}
}

Run()
{
char sensors;
sensors = (P3 &=0x0f);

if((sensors & 0x01)==0) {
TurnRight();
flag = 1; }

else if((sensors & 0x08)==0) {
TurnLeft();
flag = 2; }
else if(sensors == 0x09) {
Forward(high);
flag = 0; }

else if(((sensors==0x0b)||(sensors==0x0d))&&(flag==0))
Forward(low);

}

Forward(char speed)
{
P1=0x64;
speedright = speed+10;
speedleft = speed;
delay(time);
}

TurnRight()
{
P1=0x68;
speedright = low+5;
speedleft = low;
delay(time);
}

TurnLeft()
{
P1=0x54;
speedright = low+5;
speedleft = low;
delay(time);
}

Reverse(char speed)
{
P1=0x58;
speedright = speed;
speedleft = speed+5;
delay(time);
}

In bold text, i guess that is function to generate speed of motor, but i still understand about tha function maybe it's PWM ?.

Can anybody explain me how to control speed the motor using 89c2051 in SDCC ?

sorry about my english :D
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top