位置:首页>>  单片机应用

 项目:循迹机机器人

 来源:共享

.

循迹机器人

循迹机器人-实物

这个机器人由89c2051、L293D、4个红外传感器组成。 

机器人的主控制部分电路图如下:

 

机器人的传感器部分和比较器部分电路图如下

 

传感器位置图如下,左边是侧视图,右边是顶视图。
这个机器人电路简单、循迹速度快、程序容易理解。

在这个电路中采用了两个电机来控制后轮,而前轮则是可自由转动的。机器人的底部
有四个红外传感器用来检测黑色的轨迹,当检测到黑色,比较器的输出,LM324是低电平,
其他输出是高电平。 单片机AT89C2051和H-Briage驱动电路L293D用来控制方向和电机的
速度。

 

 

以下是asm文件-----

 

*#cpu 8051 Tiny
*
* DDS MICRO-C 8031/51 Startup Code & Runtime library for TINY model
*
* Copyright 1991-1999 Dave Dunfield
* All rights reserved.
*
ORG $0000 $0800 CODE Starts here (Normally in ROM)
LJMP START

ORG $0003
LJMP SERVICE_EX0

ORG $000B
LJMP SERVICE_TIMER0_INTERRUPT


* Fixed memory locations for alternate access to the R0-R7 register bank.
* If you are NOT useing BANK 0, these equates must be adjusted.
?R0 EQU 0 Used for "POP" from stack
?R1 EQU ?R0+1 Used to load index indirectly
?R2 EQU ?R0+2 "" "" "" ""
?R3 EQU ?R0+3 Used by some runtime lib functions
?R4 EQU ?R0+4
?R5 EQU ?R0+5
?R6 EQU ?R0+6
?R7 EQU ?R0+7
*
* Startup code entry point
*
* If you are NOT using interrupts, you can reclaim 50 bytes
* of code space by removing the following TWO lines.
* AJMP *+$0032 Skip interrupt vectors
* DS $0032-2 Reserve space for interrupt vectors
*
START EQU *
MOV SP,#?stk-1 Set up initial stack
ORL TMOD,#%00000001 set timer 0 to be counter 16 bit
SETB IE.7 $AF EA
SETB IE.1 $A9 ET0 Enable timer 0 interrupt
SETB TCON.4 start timer 0


LCALL main Execute program
SJMP * JUMP HERE

* EXIT to MON51 by calling the 'timer1' interrupt vector ($001B).
* This causes MON51 to think that a single-step operation has just
* completed, and therefore it saves the user registers, and performs
* a context switch back to the monitor.
*
* When using 2K addressing (CC51: -Z option, ASM51: -A option) this LCALL
* may fail "Out of range" because it gets translated to ACALL, and $001B
* may not be in the same 2K block as your program. Since 2K devices cannot
* support a debugger, change the ORG to $0000, and ...<continue below>...
*
* If you are NOT using MON51 (or MONICA which works the same), you will
* need to change this to whatever action you desire when main() returns.
* Suggestions: 1:freeze (SJMP *) 2:Restart (SJMP *&$FF00)
exit LCALL $001B Call Timer-1 interrupt
SJMP exit Incase he go's again

**************************** My code *********************************

SERVICE_TIMER0_INTERRUPT EQU *
PUSH ACC
PUSH PSW
MOV TH0,#$FF reload timer 0 for ms
MOV TL0,#$00
INC tick

MOV A,tick
CJNE A,#100,RIGHT
MOV tick,#0

RIGHT
CLR C
SUBB A,speedright
JC ON_RIGHT
CLR P1.0
SJMP LEFT

ON_RIGHT
SETB P1.0

LEFT
MOV A,tick
CLR C
SUBB A,speedleft
JC ON_LEFT
CLR P1.1
SJMP EXIT_I

ON_LEFT
SETB P1.1

EXIT_I
POP PSW
POP ACC
RETI

SERVICE_EX0 EQU *
INC cputick
RETI


$SE:1
*#map1 Segment 1, initialized variables
$SE:2
*#map2 Segment 2, internal "register" variables
ORG $0008 Internal ram ALWAYS starts here

tick DS 1
speedright DS 1 
speedleft DS 1 
cputick DS 1

 

以下是“C”语言文件

 


#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);
}

 

以下是烧录文件 hex

 

:0300000002000EED

:03000300020055A3

:20000B0002002475810F438901D2AFD2A9D28C12005880FE12001B80FBC0E0C0D0758CFFC3

:20002B00758A000508E508B46403750800C395094004C2908002D290E508C3950A4004C2F4

:20004B00918002D291D0D0D0E032050B327440F59074FFF5B07450F50C741EF50D7400F548

:20006B000E7432F50F120080E5B0440FF5B01200BC0200732205810581740178FD12022609

:20008B00F678FD120226E670030200B7E59008F6E654401202517B0012024812025A45F0D2

:2000AB0070030200B4740018F602008C15811581220581E5B0540FF5B078FE120226F6E6FF

:2000CB0054011202517B0012024812025A45F070030200E91201A97401F50E02018478FE52

:2000EB00120226E654081202517B0012024812025A45F0700302010D1201C87402F50E02C1

:20010B00018478FE120226E61202517B0912024812025A45F0700302013CE50C75F000C009

:20012B00E0C0F0120187158115817400F50E02018478FE120226E61202517B0B1202481271

:20014B00025A45F0700CE61202517B0D12024812025A45F0600CE50E75F0007B007C0012E8

:20016B00025A45F07003020184E50D75F000C0E0C0F0120187158115811581227464F59067

:20018B0078FB120226E6240AF509E6F50AE50F75F000C0E0C0F012020915811581227468C0

:2001AB00F590E50D2405F509E50DF50AE50F75F000C0E0C0F012020915811581227454F5D4

:2001CB0090E50D2405F509E50DF50AE50F75F000C0E0C0F012020915811581227458F59015

:2001EB0078FB120226E6F509E62405F50AE50F75F000C0E0C0F0120209158115812278FBCE

:20020B001202268603088604BB0004BC00012279E5A3D9FD1BBBFFF01C80F4C82581C8225C

:20022B00C92581C97A0022D083D082CF2581F581CFC082C08322CF2581F581CF227C00CBB6

:20024B0030E7011CCB2275F00030E70215F02212026D6009E4F5F02212026D60F7E4F5F057

:20026B000422C5F0C39C7003E5F09B22FBE493CB22FCE493FB740193CC22FAE493F9740192

:03028B0093CA22F1

:00000001FF

 

 


 

 

网络实名:电子实验室7i8i.com制作维护