|
#include<reg52.h>
#include <intrins.h>
#include <math.h>
/****************1602**I/O口******************/
sbit rs = P1^1;
sbit lcden = P3^3; //外部中断入口
sbit state = P0^7; //1说明液晶繁忙
/*********模式选择端口************/
sbit key = P2^4;
/***************超声波**I/O口******************/
sbit trig = P1^0;
sbit echo = P3^2;
/******************寻迹IO口声明********************/
/*白线为0,黑线为1*/
sbit trace1 = P3^5; /*1路*/
sbit trace2 = P2^5; /*2路*/
sbit trace3 = P2^6; /*3路*/
/***************测试灯**I/O口******************/
sbit led = P2^0;
/*****************电机驱动**IO口*****************/
/*使能端*/
sbit em1 = P1^4; //左后
sbit em2 = P1^7; //右后
sbit em3 = P2^7; //右前
sbit em4 = P2^3; //左前
/*电机口*/
sbit in1 = P1^2; //左后
sbit in2 = P1^3;
sbit in3 = P1^5; //右后
sbit in4 = P1^6;
sbit in5 = P3^6; //右前
sbit in6 = P3^7;
sbit in7 = P2^1; //左前
sbit in8 = P2^2;
/***************定义全局变量******************/
uchar table1[] = "Distance:"; //1602显示
uchar table2[] = "cm";
uchar table3[] = "Tracing";
uchar flag_ula; //超声波接收标志
float distance; //计算距离
uchar bluetoothdata; //接受蓝牙串口数据
/****************函数声明******************/
void Reverse();
void Stop();
/*****************宏定义******************/
#define uchar unsigned char
#define uint unsigned int
#define cycle 15
#define cycle1 100
/***********************延时类函数***********************/
/*毫秒延时*/
void Delayms(uint x)
{
uint a, b;
for(a = x; a > 0; a--)
for(b = 110; b > 0; b--);
}
/*微妙延时*/
void Delay10us(unsigned char i)
{
unsigned char j;
do{
j = 10;
do
{
_nop_();
}
while(--j);
}
while(--i);
}
/***************初始化中断************/
void init_T0()
{
TMOD = 0x20;
TH0 = 0;
TL0 = 0;
EA = 1;
IT0 = 1; //外部0中断的中断方式为:下降沿中断
ES = 1; //开串口中断
SCON = 0x50;
|
|