Discussion in "Project Doubts" started by    liverpool_fan    Dec 29, 2010.
Fri Jan 07 2011, 03:26 pm
#31
oooo...ic..so the third pin,the base dun have to be connected rite?im using the 2 pin phototransistor..il upload d image soon..thankz majoka
Fri Jan 07 2011, 07:43 pm
#32

Hey guys, i found the register declarations for the 8051 and is these codes enuf or sufficient?or do i have to declare any other ports?and im using AT89C2051 microprocessor,so should i declare the registers for it as well,or is that sufficient?


#ifndef REG51_H
#define REG51_H

#warning This file (reg51.h) is obsolete, depending on your harware
#warning use include <8051.h>, or include <8052.h>!

/* BYTE Register */
sfr at 0x80 P0 ;
sfr at 0x90 P1 ;
sfr at 0xA0 P2 ;
sfr at 0xB0 P3 ;
sfr at 0xD0 PSW ;
sfr at 0xE0 ACC ;
sfr at 0xF0 B ;
sfr at 0x81 SP ;
sfr at 0x82 DPL ;
sfr at 0x83 DPH ;
sfr at 0x87 PCON ;
sfr at 0x88 TCON ;
sfr at 0x89 TMOD ;
sfr at 0x8A TL0 ;
sfr at 0x8B TL1 ;
sfr at 0x8C TH0 ;
sfr at 0x8D TH1 ;
sfr at 0x8E AUXR ;
sfr at 0xA8 IE ;
sfr at 0xB8 IP ;
sfr at 0x98 SCON ;
sfr at 0x99 SBUF ;


/* BIT Register */
/* PSW */
sbit at 0xD7 CY ;
sbit at 0xD6 AC ;
sbit at 0xD5 F0 ;
sbit at 0xD4 RS1 ;
sbit at 0xD3 RS0 ;
sbit at 0xD2 OV ;
sbit at 0xD0 P ;

/* TCON */
sbit at 0x8F TF1 ;
sbit at 0x8E TR1 ;
sbit at 0x8D TF0 ;
sbit at 0x8C TR0 ;
sbit at 0x8B IE1 ;
sbit at 0x8A IT1 ;
sbit at 0x89 IE0 ;
sbit at 0x88 IT0 ;

/* IE */
sbit at 0xAF EA ;
sbit at 0xAC ES ;
sbit at 0xAB ET1 ;
sbit at 0xAA EX1 ;
sbit at 0xA9 ET0 ;
sbit at 0xA8 EX0 ;

/* IP */
sbit at 0xBC PS ;
sbit at 0xBB PT1 ;
sbit at 0xBA PX1 ;
sbit at 0xB9 PT0 ;
sbit at 0xB8 PX0 ;

/* P3 */
sbit at 0xB7 RD ;
sbit at 0xB6 WR ;
sbit at 0xB5 T1 ;
sbit at 0xB4 T0 ;
sbit at 0xB3 INT1 ;
sbit at 0xB2 INT0 ;
sbit at 0xB1 TXD ;
sbit at 0xB0 RXD ;

/* P1 */
sbit at 0x90 P1_0 ;
sbit at 0x91 P1_1 ;
sbit at 0x92 P1_2 ;
sbit at 0x93 P1_3 ;
sbit at 0x94 P1_4 ;
sbit at 0x95 P1_5 ;
sbit at 0x96 P1_6 ;
sbit at 0x97 P1_7 ;

/* SCON */
sbit at 0x9F SM0 ;
sbit at 0x9E SM1 ;
sbit at 0x9D SM2 ;
sbit at 0x9C REN ;
sbit at 0x9B TB8 ;
sbit at 0x9A RB8 ;
sbit at 0x99 TI ;
sbit at 0x98 RI ;

/* TMOD bits */
#define GATE1 (1<<7)
#define C_T1 (1<<6)
#define M1_1 (1<<5)
#define M0_1 (1<<4)
#define GATE0 (1<<3)
#define C_T0 (1<<2)
#define M1_0 (1<<1)
#define M0_0 (1<<0)

/* T2CON */
sfr at 0xC8 T2CON ;

/* T2CON bits */
sbit at 0xC8 T2CON_0 ;
sbit at 0xC9 T2CON_1 ;
sbit at 0xCA T2CON_2 ;
sbit at 0xCB T2CON_3 ;
sbit at 0xCC T2CON_4 ;
sbit at 0xCD T2CON_5 ;
sbit at 0xCE T2CON_6 ;
sbit at 0xCF T2CON_7 ;

/* RCAP2 L & H */
sfr at 0xCB RCAP2H;
sfr at 0xCA RCAP2L;

#endif


Fri Jan 07 2011, 08:36 pm
#33
hi liverpool_fan
it is sufficient don't worry
it has overall 8051 family SFR's declaration
Fri Jan 07 2011, 08:41 pm
#34
thankz majoka!il try out thr photo transistor u used and keep u updated!thankz again!
Fri Jan 07 2011, 08:44 pm
#35
WELCOME liverpool_fan
Thu Jan 13 2011, 09:17 pm
#36
hey majoka...i changed the resistance value to 1MHz as u said n i used an IR transmitter and IR receiver, I couldn't find a 3 pin photo transistor...n the circuit worked!!!!.......thankz again!

i tried compiling my codes as well...i included the register declaration together with my main code..could u jz check n see if everything is ok?

#ifndef REG51_H
#define REG51_H


/* BYTE Register */
sfr at 0x80 P0 ;
sfr at 0x90 P1 ;
sfr at 0xA0 P2 ;
sfr at 0xB0 P3 ;
sfr at 0xD0 PSW ;
sfr at 0xE0 ACC ;
sfr at 0xF0 B ;
sfr at 0x81 SP ;
sfr at 0x82 DPL ;
sfr at 0x83 DPH ;
sfr at 0x87 PCON ;
sfr at 0x88 TCON ;
sfr at 0x89 TMOD ;
sfr at 0x8A TL0 ;
sfr at 0x8B TL1 ;
sfr at 0x8C TH0 ;
sfr at 0x8D TH1 ;
sfr at 0x8E AUXR ;
sfr at 0xA8 IE ;
sfr at 0xB8 IP ;
sfr at 0x98 SCON ;
sfr at 0x99 SBUF ;


/* BIT Register */
/* PSW */
sbit at 0xD7 CY ;
sbit at 0xD6 AC ;
sbit at 0xD5 F0 ;
sbit at 0xD4 RS1 ;
sbit at 0xD3 RS0 ;
sbit at 0xD2 OV ;
sbit at 0xD0 P ;

/* TCON */
sbit at 0x8F TF1 ;
sbit at 0x8E TR1 ;
sbit at 0x8D TF0 ;
sbit at 0x8C TR0 ;
sbit at 0x8B IE1 ;
sbit at 0x8A IT1 ;
sbit at 0x89 IE0 ;
sbit at 0x88 IT0 ;

/* IE */
sbit at 0xAF EA ;
sbit at 0xAC ES ;
sbit at 0xAB ET1 ;
sbit at 0xAA EX1 ;
sbit at 0xA9 ET0 ;
sbit at 0xA8 EX0 ;

/* IP */
sbit at 0xBC PS ;
sbit at 0xBB PT1 ;
sbit at 0xBA PX1 ;
sbit at 0xB9 PT0 ;
sbit at 0xB8 PX0 ;

/* P3 */
sbit at 0xB7 RD ;
sbit at 0xB6 WR ;
sbit at 0xB5 T1 ;
sbit at 0xB4 T0 ;
sbit at 0xB3 INT1 ;
sbit at 0xB2 INT0 ;
sbit at 0xB1 TXD ;
sbit at 0xB0 RXD ;

/* P1 */
sbit at 0x90 P1_0 ;
sbit at 0x91 P1_1 ;
sbit at 0x92 P1_2 ;
sbit at 0x93 P1_3 ;
sbit at 0x94 P1_4 ;
sbit at 0x95 P1_5 ;
sbit at 0x96 P1_6 ;
sbit at 0x97 P1_7 ;

/* SCON */
sbit at 0x9F SM0 ;
sbit at 0x9E SM1 ;
sbit at 0x9D SM2 ;
sbit at 0x9C REN ;
sbit at 0x9B TB8 ;
sbit at 0x9A RB8 ;
sbit at 0x99 TI ;
sbit at 0x98 RI ;

/* TMOD bits */
#define GATE1 (1<<7)
#define C_T1 (1<<6)
#define M1_1 (1<<5)
#define M0_1 (1<<4)
#define GATE0 (1<<3)
#define C_T0 (1<<2)
#define M1_0 (1<<1)
#define M0_0 (1<<0)

/* T2CON */
sfr at 0xC8 T2CON ;

/* T2CON bits */
sbit at 0xC8 T2CON_0 ;
sbit at 0xC9 T2CON_1 ;
sbit at 0xCA T2CON_2 ;
sbit at 0xCB T2CON_3 ;
sbit at 0xCC T2CON_4 ;
sbit at 0xCD T2CON_5 ;
sbit at 0xCE T2CON_6 ;
sbit at 0xCF T2CON_7 ;

/* RCAP2 L & H */
sfr at 0xCB RCAP2H;
sfr at 0xCA RCAP2L;

#endif





unsigned char speedleft,speedright;
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);
}



n with regards to the motor speed..
for an example..the codes goes like dis..

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

which means that the right motor is slightly faster than the left motor rite?
so what if i would want to set my left motor speed to totally zero and only the right motor speeds...making the robot to make a sharper turn?cn u help me?
Fri Jan 14 2011, 08:54 pm
#37
hi liverpool_fan

i changed the resistance value to 1MHz


it is 1 mega ohm dear
yes code is ok u not need to write a reg51.h in the code
just include it keil will find out in c drive where it is

which means that the right motor is slightly faster than the left motor rite?
so what if i would want to set my left motor speed to totally zero and only the right motor speeds...making the robot to make a sharper turn?cn u help me?


when i make this i use 2 motors each controlling 1 well and i want sharp turn also
so u also use 2 motors
when both r on robot move forward
when one off and other on it will do a sharp turn


[ Edited Fri Jan 14 2011, 08:57 pm ]
Sat Jan 15 2011, 02:27 am
#38
oops sorry abt dat..typo!
so i dun need the register declaration when i wana burn it into the microcontroller rite?
n majoka,i tried constructing the main circuit but the motors are not moving..izit possible that d motor driver sum how gt spoiled?cz the current ratings for my DCmotors are 410mA bt the L293D cn deliver up to 600mA per output..im nt sure why it is not workin..u have any ideas?
Sat Jan 15 2011, 10:51 am
#39

so i dun need the register declaration when i wana burn it into the microcontroller rite?


yes ur write keil will manage it
register declaration is only needed for compiler to generate a proper hex file
that hex file is the need of 8051

n majoka,i tried constructing the main circuit but the motors are not moving..izit possible that d motor driver sum how gt spoiled?cz the current ratings for my DCmotors are 410mA bt the L293D cn deliver up to 600mA per output..im nt sure why it is not workin..u have any ideas?


u can also use L298 it has 3 AMP rating
is ic is heat up or not when u try to on the motors
check motor separately is it ok or not
ic has 2 enable inputs give 5 volt to that pins to enable the ic
Sat Jan 15 2011, 04:16 pm
#40
hie majoka..i checked both of the motors as u said, both are working...but when connected to the l293d driver, it is not working...i tried changin the IC as well, but still same result.neway..according to the program, the robot is supposed to run when the main circuit is on rite?,regardless of whether the sensor circuit is connected or not rite?

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

DJGlido
Wed May 08 2024, 09:28 pm
migCar
Wed May 08 2024, 04:48 pm
TimmyJup
Wed May 08 2024, 12:22 am
Shawnarows
Tue May 07 2024, 10:16 pm
GlennVet
Tue May 07 2024, 04:46 pm
RonaldJoump
Tue May 07 2024, 10:15 am
Jasonkam
Mon May 06 2024, 10:00 pm
JamesroW
Mon May 06 2024, 09:37 am