GardenRobot.c:

#include"reg52.h"

#include"intrins.h"

#define uchar unsigned char 

#define uint unsigned int

sbit magInduction1=P2^7;

sbit magInduction2=P2^6;

sbit magInduction3=P2^5;

sbit magInduction4=P2^4;

uchar Duty_left,Duty_right,i=0,j=0;

uint  time=0,s; 

sbit in1=P1^0;

sbit in2=P1^1;

sbit in3=P1^2;

sbit in4=P1^3;

sbit e1=P2^3;

sbit e2=P2^2;

sbit RX=P0^4;

sbit TX=P0^5; 

sbit jd=P3^7;

void init()

{

  TMOD=0X01;

  TH0=(65536-50)/256;

  TL0=(65536-50)%256;

  EA=1;

  ET0=1;

  TR0=1;

  e1=1;

  e2=1;

}

void init2()

{

  TMOD=0x10;

     TH1=0;

  TL1=0;

  TR1=1;

  ET1=1;

  EA=1;

}

void startmodule()

{

  uint n; 

  TX=1;

  for(n=0;n<21;n++)

    _nop_();

  TX=0; 

}

void count()

{

  time=TH1*256+TL1;

  TH1=0;

  TL1=0;

  s=(time*1.7)/100;

}

void stop()

{

  in1=0;

  in2=0;

  in3=0;

  in4=0;

}

void delay(unsigned int k)

  unsigned int x,y;

  for(x=0;x<k;x++) 

    for(y=0;y<2000;y++);

}

void turnRight()

{

  Duty_left=29;

  Duty_right=20;

  in1=1;

  in2=0;

  in3=0;

  in4=1;

}

void turnRight2()

{

  Duty_left=29;

  Duty_right=20;

  in1=1;

  in2=0;

  in3=0;

  in4=1;

}

void turnLeft()

{

  Duty_left=18;

  Duty_right=26;

  in1=0;

  in2=1;

  in3=1;

  in4=0;

}

void turnLeft2()

{

  Duty_left=20;

  Duty_right=30;

  in1=0;

  in2=1;

  in3=1;

  in4=0;

}

void forward()

{

  Duty_left=25;

  Duty_right=25;

  in1=1;

  in2=0;

  in3=1;

  in4=0;

}

void forward2()

{

  Duty_left=45;

  Duty_right=35;

  in1=1;

  in2=0;

  in3=1;

  in4=0;

}

 

void timer() interrupt 1

{

  i++;

  j++;

  if(i<=Duty_left)

    e1=1;

  else

    e1=0;

  if(i>100)

  {

    e1=1;

    i=0;

  }

  if(j<=Duty_right)

    e2=1;

  else

    e2=0;

  if(j>100)

  {

    e2=0;

    j=0;

  }

  TH0=(65536-50)/256;

  TL0=(65536-50)%256;

}

void main()

{

  init();

  init2();

  while(1)

  {

    startmodule(); 

    while(!RX);

    TR1=1;

    while(RX);

    TR1=0;

    count();

    if(magInduction1==0&&magInduction2==1&&magInduction3==1&&magInduction4==1&&s>40)

      turnRight();

    if(magInduction1==0&&magInduction2==0&&magInduction3==1&&magInduction4==1&&s>40)

      turnRight();

    if(magInduction1==1&&magInduction2==0&&magInduction3==0&&magInduction4==1&&s>40)

      forward();

    if(magInduction1==1&&magInduction2==1&&magInduction3==1&&magInduction4==1&&s>40)

      forward();

    if(magInduction1==1&&magInduction2==1&&magInduction3==0&&magInduction4==0&&s>40)

      turnLeft();

    if(magInduction1==1&&magInduction2==1&&magInduction3==1&&magInduction4==0&&s>40)

      turnLeft();

    if(magInduction2==0&&magInduction1==1&&magInduction3==1&&magInduction4==1&&s>40)

      turnRight();

    if(magInduction3==0&&magInduction1==1&&magInduction2==1&&magInduction4==1&&s>40)

      turnLeft();

    if(magInduction1==0&&magInduction2==1&&magInduction3==1&&magInduction4==1&&s<40)

    { 

      stop();

      jd=0;

      delay(30);

      jd=1;

      turnRight2();

      delay(8);

    }

    if(magInduction1==0&&magInduction2==0&&magInduction3==1&&magInduction4==1&&s<40)

    { 

      stop();

      jd=0; 

      delay(30);

      jd=1;

      turnRight2();

      delay(8);

    }

    if(magInduction1==1&&magInduction2==0&&magInduction3==0&&magInduction4==1&&s<40)

    {

      stop();

      jd=0; 

      delay(30);

      jd=1;

      forward2();

      delay(8);  

    }

    if(magInduction1==1&&magInduction2==1&&magInduction3==1&&magInduction4==1&&s<40)

    {

      stop();

      jd=0;

      delay(30);

      jd=1;

      forward2();

      delay(8);

    }

    if(magInduction1==1&&magInduction2==1&&magInduction3==0&&magInduction4==0&&s<40)

    {

      stop();

      jd=0;

      delay(30);

      jd=1;

      turnLeft2();

      delay(8);

    }

    if(magInduction1==1&&magInduction2==1&&magInduction3==1&&magInduction4==0&&s<40)

    {

      stop(); 

      jd=0;

      delay(30);

      jd=1;

      turnLeft2();

      delay(8);

    }

  }

}

源文件下载:

链接:GardenRobot.c
提取码:iu32 

基于C语言的磁引导园丁机器人源程序 --单片机应用的更多相关文章

  1. 基于python语言的tensorflow的‘端到端’的字符型验证码识别源码整理(github源码分享)

    基于python语言的tensorflow的‘端到端’的字符型验证码识别 1   Abstract 验证码(CAPTCHA)的诞生本身是为了自动区分 自然人 和 机器人 的一套公开方法, 但是近几年的 ...

  2. selenium2自动化测试实战--基于Python语言

    自动化测试基础 一. 软件测试分类 1.1 根据项目流程阶段划分软件测试 1.1.1 单元测试 单元测试(或模块测试)是对程序中的单个子程序或具有独立功能的代码段进行测试的过程. 1.1.2 集成测试 ...

  3. 关于《selenium2自动测试实战--基于Python语言》

    关于本书的类型: 首先在我看来技术书分为两类,一类是“思想”,一类是“操作手册”. 对于思想类的书,一般作者有很多年经验积累,这类书需要细读与品位.高手读了会深有体会,豁然开朗.新手读了不止所云,甚至 ...

  4. 《Selenium2自动化测试实战--基于Python语言》 --即将面市

    发展历程: <selenium_webdriver(python)第一版>   将本博客中的这个系列整理为pdf文档,免费. <selenium_webdriver(python)第 ...

  5. Gogs - 基于 Go 语言的自助 Git 服务

    Gogs(Go Git Service) 是一个基于 Go 语言的自助 Git 服务.Gogs 的目标是打造一个最简单.最快速和最轻松的方式搭建自助 Git 服务.使用 Go 语言开发使得 Gogs ...

  6. Ggoogle Protocol Buffer的使用 (基于C++语言)

    首先说明的是Protocol Buffle是灵活高效的.它的一个很好的优点(很重要的,我认为)就是后向兼容性--当我们扩展了了.proto文件后,我们照样可以用它来读取之前生成的文件. 之前已经写了关 ...

  7. 基于C# 语言的两个html解析器

    基于C# 语言的两个html解析器 1)Html Agility Pack http://nsoup.codeplex.com/ 代码段示例: HtmlDocument doc = new HtmlD ...

  8. springmvc国际化 基于浏览器语言的国际化配置

    当前标签: springmvc   springmvc国际化 基于浏览器语言的国际化配置 苏若年 2013-10-09 13:03 阅读:305 评论:0   SpringMVC中应用Ajax异步通讯 ...

  9. 基于JAVA语言的多线程技术

    1.简介 多线程技术属于操作系统范围内的知识: 进程与线程 可以这么理解,一个应用程序就是一个进程,在一个进程中包含至少一个线程:进程就是线程的容器,真正工作.处理任务的是线程. 进程是操作系统分配资 ...

随机推荐

  1. mysql使用存储过程和event定期删除

    -- 创建存储过程DELIMITER //CREATE PROCEDURE del_data()BEGIN DELETE FROM t_route_status WHERE route_date &l ...

  2. [efficiency] emacs入门

    一. 没记错的话,这可能是第三次读emacs tutorial了.前两次读的非常慢,也不记得有没有读完了.总之最后都忘光了. 这次读的很顺畅,利用工作的空闲时间加上今天晚上(周日).总算是读完了. 没 ...

  3. springboot:spring data jpa介绍

    转载自:https://www.cnblogs.com/ityouknow/p/5891443.html 在上篇文章springboot(二):web综合开发中简单介绍了一下spring data j ...

  4. (备忘)怎么去除WinRAR弹窗广告?

    1.在WinRAR的安装目录下新建一个记事本,命名为“rarreg.key”. 2.打开记事本,将一下内容复制进去. RAR registration data Federal Agency for ...

  5. 唯美MACD-完全版

    前言: 自己很喜欢MACD这个指标,因为很欠缺所以就搜集的多一点,有人问,学习缠为什么还这么搜集些Macd的资料呢?因为在分析走势(或盘整背驰.或趋势背驰)的时候我的习惯使用Macd做辅助判断,所以M ...

  6. 【JVM】-NO.116.JVM.1 -【JDK11 HashMap详解-5-红黑树】

    Style:Mac Series:Java Since:2018-09-10 End:2018-09-10 Total Hours:1 Degree Of Diffculty:5 Degree Of ...

  7. C# AsyncCallback异步回调用法示例

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  8. 20190408Linux权限管理week1_day5

    权限概述 Linux系统一般将文件可存/取访问的身份分为3个类别:owner(拥有者).group(和所有者同组的用户).others(其他人,除了所有者,除了同组的用户以及除了超级管理员),且3种身 ...

  9. 获取JS数组中所有重复元素

    //获取数组内所有重复元素,并以数组返回 //例:入参数组['1','2','4','7','1','2','2'] 返回数组:['1','2'] function GetRepeatFwxmmc(a ...

  10. Java 运行时字符编码与解码

    以下仅为个人学习的记录,如有疏漏不妥之处,还请不吝赐教. Java在运行时字符char采用UTF-16进行编码. public class RuntimeEncoding { public stati ...