Tutorial Microcontroller MCS-51 ATMEL ISP

Microcontroller Kits
Programmer and Target 89s51

Simple Mikrokontroller 89s51 Trainer


Standart
Mikrokontroller 89s51 Trainer


Super Mikrokontroller Trainer 89s51

+

All Item Include

Programmer
Via USB

 

 

BACK

Software Line Follower Robots Microcontroller 8051:
Software for write to AT89C2051 is robot1.hex ,which was written by C-language ,the source code is robot1.c compiled by using MIDE-51, you can download this compiler from here.

#include 8051io.h #include 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);
           }


Comments, questions and discussion about this topic

BACK