STC51单片机-智能小车

STC51单片机-智能小车

105.小车散件组装

106.L9110s电机控制器接线

(1)L911S电机模块控制左右轮,2针脚通过电平组合控制左轮,2阵脚通过电平组合控制右轮;
注:L9110S电机模块跟单片机要共地;

107.L9110前后左右控制小车

(1)封装前后左右函数;(small_car_motor_drive.c)

#include "reg52.h"
#include "intrins.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;


void goForward(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 1;
}
void goBack(){
	LeftCon1A = 1;
	LeftCon1B = 0;
	RightCon1A = 1;
	RightCon1B = 0;
}

void goLeft(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 1;
}

void goRight(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 0;
} 
void Delay1000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 8;
	j = 1; 
	k = 243;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void main(){
	while(1){
		goForward();
		Delay1000ms();
		Delay1000ms();                                    
		goBack();
		Delay1000ms();
		Delay1000ms();
		goLeft();
		Delay1000ms();
		Delay1000ms();
		goRight();
		Delay1000ms();
		Delay1000ms();
	}
}

108.电机相关代码封装_分文件编程

(1)将代码分文件拆分;(主文件-small_car_motor_drive_split_file.c;电机文件-motor.c,motor.h;延时文件delay.c,delay.h)
small_car_motor_drive_split_file.c:

#include "reg52.h"
#include "motor.h"
#include "delay.h"
void main(){
	while(1){
		goForward();
		Delay1000ms();
		Delay1000ms();
		goBack();
		Delay1000ms();
		Delay1000ms();
		goLeft();
		Delay1000ms();
		Delay1000ms();
		goRight();
		Delay1000ms();
		Delay1000ms();
	}
}

motor.c:

#include "reg52.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;


void goForward(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 1;
}
void goBack(){
	LeftCon1A = 1;
	LeftCon1B = 0;
	RightCon1A = 1;
	RightCon1B = 0;
}

void goLeft(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 1;
}

void goRight(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 0;
} 

delay.c:

#include "intrins.h"

void Delay1000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 8;
	j = 1;
	k = 243;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

motor.h:

void goForward();
void goBack();
void goLeft();
void goRight();

delay.h:

Delay1000ms();

109.串口控制小车

(1)添加了串口文件(含串口初始化函数,串口中断函数),主函数中仅需调用串口初始化文件就行,小车移动再串口中断函数中已实现;
(small_car_serial_control.c,uart.c,motor.c,uart.h,motor.h)
small_car_serial_control.c:

#include "reg52.h"
#include "uart.h"
void main(){
	UartInit();
	while(1){
	}
}

uart.c:

#include "reg52.h"
#include "motor.h"
#include "string.h"
#define SIZE 12
sfr AUXR = 0x8E;
char buffer[SIZE];
void UartInit(void)		//9600bps@11.0592MHz
{
	AUXR = 0x01;
	SCON = 0x50; //配置串口工作方式1,REN使能接收        
	TMOD &= 0x0F;
	TMOD |= 0x20;//定时器1工作方式位8位自动重装
	
	TH1 = 0xFD;
	TL1 = 0xFD;//9600波特率的初值
	TR1 = 1;//启动定时器
	EA = 1;//开启总中断
	ES = 1;//开启串口中断
}
void Uart_Handler() interrupt 4 {
	static int i = 0;//静态变量,背初始化一次
	char tmp;
	//判断是否收到数据,收到数据硬件会将RI置1
	if(RI){
		RI = 0;//清除接收中断标志位
		tmp = SBUF;
		if(tmp == 'M'){
			i = 0;
		}
		buffer[i++] = tmp;
		if(buffer[0] == 'M' ){
			switch(buffer[1]){
				case '1':
					goForward();
					break;
				case '2':
					goBack();
					break;
				case '3':
					goLeft();
					break;
				case '4':
					goRight();
					break;
				default:
					stop();
					break;
			}
		}
		if(i == 12){
			memset(buffer,'\0',SIZE);
			i = 0;
		} 
	}
}

motor.c:

#include "reg52.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;
void goForward(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 1;
}
void goBack(){
	LeftCon1A = 1;
	LeftCon1B = 0;
	RightCon1A = 1;
	RightCon1B = 0;
}

void goLeft(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 1;
}

void goRight(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 0;
} 

void stop(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 0;
} 

uart.h:

void UartInit(void);

motor.h:

void goForward();
void goBack();
void goLeft();
void goRight();
void stop();

110.手机通过蓝牙控制小车_自定义按键

(1)连接好蓝牙模块,手机通过蓝牙控制小车移动(蓝牙助手上设定上,下,左,右,停);

111.蓝牙小车的点动控制

(1)主函数中while(1)循环体中一直调用stop()函数,uart文件中的中断函数中前后左右分别加10ms延时,即可实现点动小车;
(small_car_bluetooth_inching.c,uart.c,motor.c,delay.c,uart.h,motor.h,delay.h)
small_car_bluetooth_inching.c:

#include "reg52.h"
#include "uart.h"
#include "motor.h"
void main(){
	UartInit();
	while(1){
		stop();
	}
}

uart.c:

#include "reg52.h"
#include "motor.h"
#include "string.h"
#include "delay.h"
#define SIZE 12
sfr AUXR = 0x8E;
char buffer[SIZE];
void UartInit(void)		//9600bps@11.0592MHz
{
	AUXR = 0x01;
	SCON = 0x50; //配置串口工作方式1,REN使能接收        
	TMOD &= 0x0F;
	TMOD |= 0x20;//定时器1工作方式位8位自动重装
	
	TH1 = 0xFD;
	TL1 = 0xFD;//9600波特率的初值
	TR1 = 1;//启动定时器
	EA = 1;//开启总中断
	ES = 1;//开启串口中断
}
void Uart_Handler() interrupt 4 {
	static int i = 0;//静态变量,背初始化一次
	char tmp;
	//判断是否收到数据,收到数据硬件会将RI置1
	if(RI){
		RI = 0;//清除接收中断标志位
		tmp = SBUF;
		if(tmp == 'M'){
			i = 0;
		}
		buffer[i++] = tmp;
		if(buffer[0] == 'M' ){
			switch(buffer[1]){
				case '1':
					goForward();
					Delay10ms();
					break;
				case '2':
					goBack();
					Delay10ms();
					break;
				case '3':
					goLeft();
					Delay10ms();
					break;
				case '4':
					goRight();
					Delay10ms();
					break;
				default:
					stop();
					break;
			}
		}
		if(i == 12){
			memset(buffer,'\0',SIZE);
			i = 0;
		} 
	}
}

motor.c:

#include "reg52.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;


void goForward(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 1;
}
void goBack(){
	LeftCon1A = 1;
	LeftCon1B = 0;
	RightCon1A = 1;
	RightCon1B = 0;
}

void goLeft(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 1;
}

void goRight(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 0;
} 

void stop(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 0;
} 

delay.c:

#include "intrins.h"

void Delay10ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 18;
	j = 235;
	do
	{
		while (--j);
	} while (--i);
}

uart.h:

void UartInit(void);

motor.h:

void goForward();
void goBack();
void goLeft();
void goRight();
void stop();

delay.h:

void Delay10ms();

112.串口自动发送数据测试

(1)ISp烧录工具中可设定1ms自动发送数据;

113.软件调速

(1)调用舵机函数,将20ms分为40份;40份中大于speed就小车前进,小于speed小车停止;通过设定不同speed可进行调速;
(small_car_adjust_speed.c,time.c,motor.c,delay.c,time.h,motor.h,delay.h)
small_car_adjust_speed.c:

#include "reg52.h"
#include "uart.h"
#include "motor.h"
#include "delay.h"
#include "time.h"
extern char speed;
void main(){
	//UartInit();
	Time0Init();
	while(1){
		speed = 10;
		Delay1000ms();
		Delay1000ms();
		speed = 20;
		Delay1000ms();
		Delay1000ms();
		speed = 30;
		Delay1000ms();
		Delay1000ms();
		speed = 40;
		Delay1000ms();
		Delay1000ms();
	}
}

time.c:

#include "reg52.h"
#include "intrins.h"
#include "motor.h"
int cnt = 0;
char speed;

void Time0Init(){

	//选择定时器0工作模式16位计数
	TMOD &= 0xF0;
	TMOD |= 0x01; 
	TL0 = 0x33;		//设置定时初值
	TH0 = 0xFE;		//设置定时初值	
	//开始计数
	TR0 = 1;
	TF0 = 0;
	//打开定时器0中断
	EA = 1;
	ET0 = 1;
}



void Time0Handler() interrupt 1{
	//统计爆表次数
	cnt ++;
	//重新定时器赋初值
	TL0 = 0x33;
	TH0 = 0xFE;	
	//控制PWM波
	if(cnt < speed){
		goForward();
	}else{
		stop();
	}
	//爆表40次,经过20ms
	if(cnt == 40){
		//经过20ms后重新累计,并且输出高电平`
		cnt = 0;
	}

}

motor.c:

#include "reg52.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;


void goForward(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 1;
}
void goBack(){
	LeftCon1A = 1;
	LeftCon1B = 0;
	RightCon1A = 1;
	RightCon1B = 0;
}

void goLeft(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 1;
}

void goRight(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 0;
} 

void stop(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 0;
} 

delay.c:

#include "intrins.h"

void Delay1000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 8;
	j = 1;
	k = 243;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void Delay10ms()		//@11.0592MHz
{
	unsigned char i, j;

	i = 18;
	j = 235;
	do
	{
		while (--j);
	} while (--i);
}

time.h:

void Time0Init();

motor.h:

void goForward();
void goBack();
void goLeft();
void goRight();
void stop();

delay.h:

Delay1000ms();
Delay10ms();

114.左右电机的各自调速管理

(1)motor文件中左右轮分别添加向前,停止函数;time文件中用定时器0控制左轮,定时器1控制右轮;
主函数中设定左右轮速度差异进行对比; (small_car_wheel_diff_speed.c,time.c,motor.c,delay.c,time.h,motor.h,delay.h)
small_car_wheel_diff_speed.c:

//#include "reg52.h"
#include "motor.h"
#include "delay.h"
#include "time.h"
extern char speedLeft;
extern char speedRight;
void main(){
	Time0Init();
	Time1Init();
	while(1){

		speedLeft = 20;
		speedRight = 40;
		Delay1000ms();
		Delay1000ms();
		speedLeft = 40;
		speedRight = 20;
		Delay1000ms();
		Delay1000ms();
	}
}

time.c:

#include "reg52.h"
#include "intrins.h"
#include "motor.h"
char cntLeft = 0;
char speedLeft;
char cntRight = 0;
char speedRight;

void Time1Init(){

	//选择定时器1工作模式16位计数
	TMOD &= 0x0F;
	TMOD |= 0x1<< 4; 
	TL1 = 0x33;		//设置定时初值
	TH1 = 0xFE;		//设置定时初值	
	//开始计数
	TR1 = 1;
	TF1 = 0;
	//打开定时器0中断
	EA = 1;
	ET1 = 1;
}


void Time0Init(){

	//选择定时器0工作模式16位计数
	//TMOD &= 0xF0;
	//TMOD |= 0x01; 
	TMOD = 0x01; 
	TL0 = 0x33;		//设置定时初值
	TH0 = 0xFE;		//设置定时初值	
	//开始计数
	TR0 = 1;
	TF0 = 0;
	//打开定时器0中断
	EA = 1;
	ET0 = 1;
}

void Time1Handler() interrupt 3{
	//统计爆表次数
	cntRight ++;
	//重新定时器赋初值
	TL1 = 0x33;
	TH1 = 0xFE;	
	//控制PWM波
	if(cntRight < speedRight){
		goForwardRight();
	}else{
		stopRight();
	}
	//爆表40次,经过20ms
	if(cntRight == 40){
		//经过20ms后重新累计,并且输出高电平`
		cntRight = 0;
	}

}



void Time0Handler() interrupt 1{
	//统计爆表次数
	cntLeft ++;
	//重新定时器赋初值
	TL0 = 0x33;
	TH0 = 0xFE;	
	//控制PWM波
	if(cntLeft < speedLeft){
		goForwardLeft();
	}else{
		stopLeft();
	}
	//爆表40次,经过20ms
	if(cntLeft == 40){
		//经过20ms后重新累计,并且输出高电平`
		cntLeft = 0;
	}

}

motor.c:

#include "reg52.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;

/*
void goForward(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 1;
}
void goBack(){
	LeftCon1A = 1;
	LeftCon1B = 0;
	RightCon1A = 1;
	RightCon1B = 0;
}

void goLeft(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 1;
}

void goRight(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 0;
} 

void stop(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 0;
} 
*/
void goForwardLeft(){
	LeftCon1A = 0;
	LeftCon1B = 1;
}

void goForwardRight(){
	RightCon1A = 0;
	RightCon1B = 1;
}
void stopLeft(){
	LeftCon1A = 0;
	LeftCon1B = 0;
} 
void stopRight(){
	RightCon1A = 0;
	RightCon1B = 0;
} 

delay.c:

#include "intrins.h"

void Delay1000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 8;
	j = 1;
	k = 243;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

time.h:

void Time0Init();
void Time1Init();

motor.h:

void goForwardLeft();
void goForwardRight();
void stopLeft();
void stopRight();

delay.h:

Delay1000ms();

115.循迹小车基本原理和方案

(1)TCRT5000传感器模块特征:发射红外线,反射回来,D0输出低电平,二极管指示灯亮;没反射回来,D0输出高电平,二极管指示灯灭;
(2)TCRT5000传感器模块作为循迹模块安装在小车车头两侧:
遇到黑线,D0输出高电平,二极管指示灯灭,车轮停止;
不是黑线,D0输出低电平,二极管指示灯亮,车轮直走;
例:左轮传感器模块遇到黑线,红外线被吸收,输出高电平,停止转动,右轮输出低电平,向前走,从而达到了左转的目的;

116.根据循迹原理实现循迹功能代码编写

(1)注:传感器模块供电不能超过5V,所以不能跟电机共用电池6V的电,需从单片机中引出5V的电用;
(2)定义2传感器D0使用的IO口,2传感器高低电平组合确定向前,向左,向右移动;
(tracking_car_01.c,motor.c,motor.h)
tracking_car_01.c:

#include "reg52.h"
#include "motor.h"
//#include "delay.h"
sbit leftSensor = P2^7;
sbit rightSensor = P2^6;
void main(){
	//遇到黑线,D0输出高电平,二极管指示灯灭,车轮停止;不是黑线,D0输出低电平,二极管指示灯亮,车轮直走;
	//左轮传感器模块遇到黑线,红外线被吸收,输出高电平,停止转动,右轮输出低电平,向前走,从而达到了左转的目的;		
	while(1){
		if(leftSensor == 0 && rightSensor == 0){
			goForward();
		}
		if(leftSensor == 0 && rightSensor == 1){
			goRight();
		}
		if(leftSensor == 1 && rightSensor == 0){
			goLeft();
		}
		if(leftSensor == 1 && rightSensor == 1){
			stop();
		}		
	}
}

motor.c:

#include "reg52.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;
void goForward(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 1;
}
/*
void goBack(){
	LeftCon1A = 1;
	LeftCon1B = 0;
	RightCon1A = 1;
	RightCon1B = 0;
}
*/
void goLeft(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 1;
}

void goRight(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 0;
} 
void stop(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 0;
} 

motor.h:

void goForward();
//void goBack();
void goLeft();
void goRight();
void stop();

117.循迹实际测试和电位器调节

(1)实际路线测试,通过调节电位器来设定传感器模块灵敏度(顺时钟拧更加灵敏);-待测试

118.解决转弯平滑问题,加入电机调速

(1)引用左右电机的各自调速管理代码,其中通过定时器0,定时器1单独控制左右轮速度,即可解决转弯平滑问题;
(tracking_car_02.c,time.c,motor.c,time.h,motor.h)
tracking_car_02.c:

#include "reg52.h"
#include "motor.h"
//#include "delay.h"
#include "time.h"
extern char speedLeft;
extern char speedRight;
sbit leftSensor = P2^7;
sbit rightSensor = P2^6;
void main(){
	//UartInit();
	Time0Init();
	Time1Init();
	while(1){
		if(leftSensor == 0 && rightSensor == 0){
			speedLeft = 40;
			speedRight = 40;
		}
		if(leftSensor == 0 && rightSensor == 1){
			speedLeft = 40;
			speedRight = 15;
		}
		if(leftSensor == 1 && rightSensor == 0){
			speedLeft = 15;
			speedRight = 40;
		}
		if(leftSensor == 1 && rightSensor == 1){
			speedLeft = 0;
			speedRight = 0;
		}
	}
}

time.c:

#include "reg52.h"
#include "intrins.h"
#include "motor.h"
char cntLeft = 0;
char speedLeft;
char cntRight = 0;
char speedRight;

void Time0Init(){

	//选择定时器0工作模式16位计数
	TMOD &= 0xF0;
	TMOD |= 0x01; 
	TL0 = 0x33;		//设置定时初值
	TH0 = 0xFE;		//设置定时初值	
	//开始计数
	TR0 = 1;
	TF0 = 0;
	//打开定时器0中断
	EA = 1;
	ET0 = 1;
}



void Time0Handler() interrupt 1{
	//统计爆表次数
	cntLeft ++;
	//重新定时器赋初值
	TL0 = 0x33;
	TH0 = 0xFE;	
	//控制PWM波
	if(cntLeft < speedLeft){
		goForwardLeft();
	}else{
		stopLeft();
	}
	//爆表40次,经过20ms
	if(cntLeft == 40){
		//经过20ms后重新累计,并且输出高电平`
		cntLeft = 0;
	}

}

void Time1Init(){

	//选择定时器1工作模式16位计数
	TMOD &= 0x0F;
	TMOD |= 0x1<< 4; 
	TL1 = 0x33;		//设置定时初值
	TH1 = 0xFE;		//设置定时初值	
	//开始计数
	TR1 = 1;
	TF1 = 0;
	//打开定时器0中断
	EA = 1;
	ET1 = 1;
}



void Time1Handler() interrupt 3{
	//统计爆表次数
	cntRight ++;
	//重新定时器赋初值
	TL1 = 0x33;
	TH1 = 0xFE;	
	//控制PWM波
	if(cntRight < speedRight){
		goForwardRight();
	}else{
		stopRight();
	}
	//爆表40次,经过20ms
	if(cntRight == 40){
		//经过20ms后重新累计,并且输出高电平`
		cntRight = 0;
	}

}

motor.c:

#include "reg52.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;

/*
void goForward(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 1;
}
void goBack(){
	LeftCon1A = 1;
	LeftCon1B = 0;
	RightCon1A = 1;
	RightCon1B = 0;
}

void goLeft(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 1;
}

void goRight(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 0;
} 

void stop(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 0;
} 
*/
void goForwardLeft(){
	LeftCon1A = 0;
	LeftCon1B = 1;
}

void goForwardRight(){
	RightCon1A = 0;
	RightCon1B = 1;
}
void stopLeft(){
	LeftCon1A = 0;
	LeftCon1B = 0;
} 
void stopRight(){
	RightCon1A = 0;
	RightCon1B = 0;
} 

time.h:

void Time0Init();
void Time1Init();

motor.h:

/*
void goForward();
void goBack();
void goLeft();
void goRight();
void stop();
*/
void goForwardLeft();
void goForwardRight();
void stopLeft();
void stopRight();

119.循迹小车根据赛道实际运行情况的调试方法

(1)实际路线测试,调整左右轮差速,让小车直行,转弯顺畅;

120.跟随小车

(1)同样使用TCRT5000传感器模块,循迹小车红外模块朝下,跟随小车红外朝前;
(2)原理:左边模块返回红外,输出低电平,右边不返回,输出高电平,物体在左边,左转;
右边模块返回红外,输出低电平,左边不返回,输出高电平,物体在右边,右转;
(following car.c,motor.c,motor.h)
following car.c:

#include "reg52.h"
#include "motor.h"
//#include "delay.h"
sbit leftSensor = P2^5;
sbit rightSensor = P2^4;
void main(){
	//左边模块返回红外,输出低电平,右边不返回,输出高电平,物体在左边,左转;
	//右边模块返回红外,输出低电平,左边不返回,输出高电平,物体在右边,右转;	
	while(1){
		if(leftSensor == 0 && rightSensor == 0){
			goForward();
		}
		if(leftSensor == 0 && rightSensor == 1){
			goLeft();
		}
		if(leftSensor == 1 && rightSensor == 0){
			goRight();
		}
		if(leftSensor == 1 && rightSensor == 1){
			stop();
		}		
	}
}

motor.c:

#include "reg52.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;


void goForward(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 1;
}
/*
void goBack(){
	LeftCon1A = 1;
	LeftCon1B = 0;
	RightCon1A = 1;
	RightCon1B = 0;
}
*/
void goLeft(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 1;
}

void goRight(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 0;
} 
void stop(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 0;
} 

motor.h:

void goForward();
//void goBack();
void goLeft();
void goRight();
void stop();

121.跟随小车效果

(1)实际路线测试;

122.摇头测距小测01_舵机和超声波封装

(1)将垃圾桶测距开关盖代码分文件封装(含超声波测距,舵机转动)
(obstacle_avoidance_car_01.c,hc04.c,sg90.c,delay.c,hc04.h,sg90.h,delay.h)
obstacle_avoidance_car_01.c:

#include "reg52.h"
#include "intrins.h"
#include "delay.h"
#include "hc04.h"
#include "sg90.h"

void main(){
	
	double dis;
	//定时器初始化
	Timer0Init();
	Timer1Init();
	initSG90();
	while(1){
		dis = get_distance();
		if(dis < 10){
			openStatusLight();
			openDusbin();
		}else{
			closeStatusLight();
			closeDusbin();
		}

	}
}

hc04.c:

#include "reg52.h"
#include "delay.h"
sbit Trig = P2^3;
sbit Echo = P2^2;

void Timer1Init(){
	//选择定时器1,设定16位计数
	TMOD &= 0x0F;
	TMOD |= 0x10;
	//设定初始值为0
	TH1 = 0;
	TL1 = 0;
}
void TrigInit(){
	//让硬件稳定一下
	Delay200ms();
	Trig = 0;
	//高电平维持10us
	Trig = 1;
	Delay10us();
	Trig = 0;	
}
double get_distance(){
	double time;
	//定时器数据清0,再次测距
	TH1 = 0;
	TL1 = 0;
	//超声波模块启动
	TrigInit();
	//等待发送超声波
	while(Echo == 0);
	//开启定时器
	TR1 = 1;
	while(Echo == 1);
	TR1 = 0;
	//计算时间,TH0的8位要左移2的8次方才可以与TL0相加求和
	time = (TH1*256+TL1)*1.085;
	//计算距离,距离=速度(340m/s)*时间/2=340*100cm/1000000us*时间/2=0.017cm/us*时间
	return (time*0.017);
}

sg90.c:

#include "reg52.h"
#include "delay.h"
sbit sg90_con = P1^1;
int jd;
int cnt = 0;

sbit led1 = P3^6;
sbit led2 = P3^7;

void Timer0Init(){

	//选择定时器0工作模式16位计数
	TMOD &= 0xF0;
	TMOD |= 0x01; 
	TL0 = 0x33;		//设置定时初值
	TH0 = 0xFE;		//设置定时初值	
	//开始计数
	TR0 = 1;
	TF0 = 0;
	//打开定时器0中断
	EA = 1;
	ET0 = 1;
}
void openStatusLight(){
	led1 = 0;
	led2 = 1;
}
void closeStatusLight(){
	led1 = 1;
	led2 = 0;
}
void initSG90(){
	jd = 1;
	cnt = 0;
	//初始电平为高电平
	sg90_con = 1;
}
void openDusbin(){
	//90度,1.5ms的高电平
	jd = 3;
	cnt = 0;
	Delay2000ms();
}
void closeDusbin(){
	//0度
	jd = 1;
	cnt = 0;
	Delay150ms();
}
void Time0Handler() interrupt 1{
	//统计爆表次数
	cnt ++;
	//重新定时器赋初值
	TL0 = 0x33;
	TH0 = 0xFE;	
	//控制PWM波
	if(cnt < jd){
		sg90_con = 1;
	}else{
		sg90_con = 0;
	}
	//爆表40次,经过20ms
	if(cnt == 40){
		//经过20ms后重新累计,并且输出高电平`
		cnt = 0;
		sg90_con = 1;
	}
}

delay.c:

#include "intrins.h"
void Delay10us()		//@11.0592MHz
{
	unsigned char i;

	i = 2;
	while (--i);
}
void Delay200ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 2;
	j = 103;
	k = 147;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}
void Delay2000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 15;
	j = 2;
	k = 235;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void Delay150ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 2;
	j = 13;
	k = 237;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

hc04.h:

void Timer1Init();
double get_distance();

sg90.h:

void Timer0Init();
void openStatusLight();
void closeStatusLight();
void openDusbin();
void closeDusbin();
void initSG90();

delay.h:

void Delay10us();		//@11.0592MHz
void Delay200ms();		//@11.0592MHz
void Delay2000ms();		//@11.0592MHz
void Delay150ms();		//@11.0592MHz

123.摇头测距小车02_实现疯狂摇头

(1)垃圾桶开关盖中的舵机0-90度切换,再加一个180度即可实现左,中,右疯狂摇头;
(obstacle_avoidance_car_02.c,hc04.c,sg90.c,delay.c,hc04.h,sg90.h,delay.h)
obstacle_avoidance_car_02.c:

#include "reg52.h"
#include "intrins.h"
#include "delay.h"
#include "hc04.h"
#include "sg90.h"

void main(){
	//定时器初始化
	Timer0Init();
	Timer1Init();
	sgMiddle();
	Delay300ms();
	Delay300ms();
	while(1){
		sgLeft();
		Delay300ms();
		sgMiddle();
		Delay300ms();
		sgRight();
		Delay300ms();
		sgMiddle();
		Delay300ms();
	}
}

hc04.c:

#include "reg52.h"
#include "delay.h"
sbit Trig = P2^3;
sbit Echo = P2^2;

void Timer1Init(){
	//选择定时器1,设定16位计数
	TMOD &= 0x0F;
	TMOD |= 0x10;
	//设定初始值为0
	TH1 = 0;
	TL1 = 0;
}
void TrigInit(){
	//让硬件稳定一下
	Delay200ms();
	Trig = 0;
	//高电平维持10us
	Trig = 1;
	Delay10us();
	Trig = 0;	
}
double get_distance(){
	double time;
	//定时器数据清0,再次测距
	TH1 = 0;
	TL1 = 0;
	//超声波模块启动
	TrigInit();
	//等待发送超声波
	while(Echo == 0);
	//开启定时器
	TR1 = 1;
	while(Echo == 1);
	TR1 = 0;
	//计算时间,TH0的8位要左移2的8次方才可以与TL0相加求和
	time = (TH1*256+TL1)*1.085;
	//计算距离,距离=速度(340m/s)*时间/2=340*100cm/1000000us*时间/2=0.017cm/us*时间
	return (time*0.017);
}

sg90.c:

#include "reg52.h"
#include "delay.h"
sbit sg90_con = P1^1;
int jd;
int cnt = 0;


void Timer0Init(){

	//选择定时器0工作模式16位计数
	TMOD &= 0xF0;
	TMOD |= 0x01; 
	TL0 = 0x33;		//设置定时初值
	TH0 = 0xFE;		//设置定时初值	
	//开始计数
	TR0 = 1;
	TF0 = 0;
	//打开定时器0中断
	EA = 1;
	ET0 = 1;
}

void sgMiddle(){
	//90度,1.5ms的高电平
	jd = 3;
	cnt = 0;
}
void sgLeft(){
	//0度
	jd = 5;
	cnt = 0;
}
void sgRight(){
	//0度
	jd = 1;
	cnt = 0;
}
void Time0Handler() interrupt 1{
	//统计爆表次数
	cnt ++;
	//重新定时器赋初值
	TL0 = 0x33;
	TH0 = 0xFE;	
	//控制PWM波
	if(cnt < jd){
		sg90_con = 1;
	}else{
		sg90_con = 0;
	}
	//爆表40次,经过20ms
	if(cnt == 40){
		//经过20ms后重新累计,并且输出高电平`
		cnt = 0;
		sg90_con = 1;
	}
}

delay.c:

#include "intrins.h"
void Delay10us()		//@11.0592MHz
{
	unsigned char i;

	i = 2;
	while (--i);
}
void Delay200ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 2;
	j = 103;
	k = 147;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}
void Delay2000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 15;
	j = 2;
	k = 235;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void Delay150ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 2;
	j = 13;
	k = 237;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}
void Delay300ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 3;
	j = 26;
	k = 223;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

hc04.h:

void Timer1Init();
double get_distance();

sg90.h:

void Timer0Init();
void openStatusLight();
void closeStatusLight();
void openDusbin();
void closeDusbin();
void initSG90();
void sgLeft();
void sgMiddle();
void sgRight();

delay.h:

void Delay10us();		//@11.0592MHz
void Delay200ms();		//@11.0592MHz
void Delay2000ms();		//@11.0592MHz
void Delay150ms();		//@11.0592MHz
void Delay300ms();		//@11.0592MHz

124.摇头测距小车03_测距摇头

(1)测量距离,障碍物距离>35cm前进,<35cm摇头;并进行其实头部方向标记及判断调整;
(obstacle_avoidance_car_03.c,hc04.c,sg90.c,delay.c,hc04.h,sg90.h,delay.h)
obstacle_avoidance_car_03.c:

#include "reg52.h"
#include "intrins.h"
#include "delay.h"
#include "hc04.h"
#include "sg90.h"

#define MIDDLE 0
#define LEFT 1
#define RIGHT 2

void main(){
	char dir;
	double disMiddle;
	double disLeft;
	double disRight;
	//定时器初始化
	Timer0Init();
	Timer1Init();
	sgMiddle();
	Delay300ms();
	Delay300ms();
	dir = MIDDLE;
	while(1){
		if(dir != MIDDLE){
			sgMiddle();
			dir = MIDDLE;
			Delay300ms();
		}
		disMiddle = get_distance();
		if(disMiddle > 35){
			//前进
		}else{
			//摇头
			sgLeft();
			Delay300ms();
			disLeft = get_distance();
			sgMiddle();
			Delay300ms();
			sgRight();
			dir = RIGHT;
			Delay300ms();
			disRight = get_distance();
		}
	}
}

hc04.c:

#include "reg52.h"
#include "delay.h"
sbit Trig = P2^3;
sbit Echo = P2^2;

void Timer1Init(){
	//选择定时器1,设定16位计数
	TMOD &= 0x0F;
	TMOD |= 0x10;
	//设定初始值为0
	TH1 = 0;
	TL1 = 0;
}
void TrigInit(){
	//让硬件稳定一下
	Delay200ms();
	Trig = 0;
	//高电平维持10us
	Trig = 1;
	Delay10us();
	Trig = 0;	
}
double get_distance(){
	double time;
	//定时器数据清0,再次测距
	TH1 = 0;
	TL1 = 0;
	//超声波模块启动
	TrigInit();
	//等待发送超声波
	while(Echo == 0);
	//开启定时器
	TR1 = 1;
	while(Echo == 1);
	TR1 = 0;
	//计算时间,TH0的8位要左移2的8次方才可以与TL0相加求和
	time = (TH1*256+TL1)*1.085;
	//计算距离,距离=速度(340m/s)*时间/2=340*100cm/1000000us*时间/2=0.017cm/us*时间
	return (time*0.017);
}

sg90.c:

#include "reg52.h"
#include "delay.h"
sbit sg90_con = P1^1;
int jd;
int cnt = 0;


void Timer0Init(){

	//选择定时器0工作模式16位计数
	TMOD &= 0xF0;
	TMOD |= 0x01; 
	TL0 = 0x33;		//设置定时初值
	TH0 = 0xFE;		//设置定时初值	
	//开始计数
	TR0 = 1;
	TF0 = 0;
	//打开定时器0中断
	EA = 1;
	ET0 = 1;
}

void sgMiddle(){
	//90度,1.5ms的高电平
	jd = 3;
	cnt = 0;
}
void sgLeft(){
	//180度
	jd = 5;
	cnt = 0;
}
void sgRight(){
	//0度
	jd = 1;
	cnt = 0;
}
void Time0Handler() interrupt 1{
	//统计爆表次数
	cnt ++;
	//重新定时器赋初值
	TL0 = 0x33;
	TH0 = 0xFE;	
	//控制PWM波
	if(cnt < jd){
		sg90_con = 1;
	}else{
		sg90_con = 0;
	}
	//爆表40次,经过20ms
	if(cnt == 40){
		//经过20ms后重新累计,并且输出高电平`
		cnt = 0;
		sg90_con = 1;
	}
}

delay.c:

#include "intrins.h"
void Delay10us()		//@11.0592MHz
{
	unsigned char i;

	i = 2;
	while (--i);
}
void Delay200ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 2;
	j = 103;
	k = 147;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}
void Delay2000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 15;
	j = 2;
	k = 235;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void Delay150ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 2;
	j = 13;
	k = 237;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}
void Delay300ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 3;
	j = 26;
	k = 223;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

hc04.h:

void Timer1Init();
double get_distance();

sg90.h:

void Timer0Init();
void openStatusLight();
void closeStatusLight();
void openDusbin();
void closeDusbin();
void initSG90();
void sgLeft();
void sgMiddle();
void sgRight();

delay.h:

void Delay10us();		//@11.0592MHz
void Delay200ms();		//@11.0592MHz
void Delay2000ms();		//@11.0592MHz
void Delay150ms();		//@11.0592MHz
void Delay300ms();		//@11.0592MHz

125.摇头测距小车04_摇头测距和行驶

(1)摇头测距代码中添加电机代码,大于35cm向前行驶;
小于35cm的话,就需要左右两边离障碍物的距离,向距离远的方向行驶;已添加距离小于10cm时,小车后退
(obstacle_avoidance_car_04.c,hc04.c,sg90.c,delay.c,motor.c,hc04.h,sg90.h,delay.h,motor.h)
obstacle_avoidance_car_04.c:

#include "reg52.h"
#include "intrins.h"
#include "delay.h"
#include "hc04.h"
#include "sg90.h"
#include "motor.h"

#define MIDDLE 0
#define LEFT 1
#define RIGHT 2

void main(){
	char dir;
	double disMiddle;
	double disLeft;
	double disRight;
	//定时器初始化
	Timer0Init();
	Timer1Init();
	sgMiddle();
	Delay300ms();
	Delay300ms();
	dir = MIDDLE;
	while(1){
		if(dir != MIDDLE){
			sgMiddle();
			dir = MIDDLE;
			Delay300ms();
		}
		disMiddle = get_distance();
		if(disMiddle > 35){
			//前进
			goForward();
		}else if(disMiddle < 10){
			goBack();
		}else{
			//摇头
			sgLeft();
			Delay300ms();
			disLeft = get_distance();
			sgMiddle();
			Delay300ms();
			sgRight();
			dir = RIGHT;
			Delay300ms();
			disRight = get_distance();
			if(disLeft < disRight){
				goRight();
				Delay150ms();
				stop();
			}
			if(disRight <disLeft){
				goLeft();
				Delay150ms();
				stop();		
			}				
		}
	}
}

hc04.c:

#include "reg52.h"
#include "delay.h"
sbit Trig = P2^3;
sbit Echo = P2^2;

void Timer1Init(){
	//选择定时器1,设定16位计数
	TMOD &= 0x0F;
	TMOD |= 0x10;
	//设定初始值为0
	TH1 = 0;
	TL1 = 0;
}
void TrigInit(){
	//让硬件稳定一下
	Delay200ms();
	Trig = 0;
	//高电平维持10us
	Trig = 1;
	Delay10us();
	Trig = 0;	
}
double get_distance(){
	double time;
	//定时器数据清0,再次测距
	TH1 = 0;
	TL1 = 0;
	//超声波模块启动
	TrigInit();
	//等待发送超声波
	while(Echo == 0);
	//开启定时器
	TR1 = 1;
	while(Echo == 1);
	TR1 = 0;
	//计算时间,TH0的8位要左移2的8次方才可以与TL0相加求和
	time = (TH1*256+TL1)*1.085;
	//计算距离,距离=速度(340m/s)*时间/2=340*100cm/1000000us*时间/2=0.017cm/us*时间
	return (time*0.017);
}

sg90.c:

#include "reg52.h"
#include "delay.h"
sbit sg90_con = P1^1;
int jd;
int cnt = 0;


void Timer0Init(){

	//选择定时器0工作模式16位计数
	TMOD &= 0xF0;
	TMOD |= 0x01; 
	TL0 = 0x33;		//设置定时初值
	TH0 = 0xFE;		//设置定时初值	
	//开始计数
	TR0 = 1;
	TF0 = 0;
	//打开定时器0中断
	EA = 1;
	ET0 = 1;
}

void sgMiddle(){
	//90度,1.5ms的高电平
	jd = 3;
	cnt = 0;

}
void sgLeft(){
	//0度
	jd = 5;
	cnt = 0;
}
void sgRight(){
	//0度
	jd = 1;
	cnt = 0;
}
void Time0Handler() interrupt 1{
	//统计爆表次数
	cnt ++;
	//重新定时器赋初值
	TL0 = 0x33;
	TH0 = 0xFE;	
	//控制PWM波
	if(cnt < jd){
		sg90_con = 1;
	}else{
		sg90_con = 0;
	}
	//爆表40次,经过20ms
	if(cnt == 40){
		//经过20ms后重新累计,并且输出高电平`
		cnt = 0;
		sg90_con = 1;
	}
}

delay.c:

#include "intrins.h"
void Delay10us()		//@11.0592MHz
{
	unsigned char i;

	i = 2;
	while (--i);
}
void Delay200ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 2;
	j = 103;
	k = 147;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void Delay150ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 2;
	j = 13;
	k = 237;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}
void Delay300ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 3;
	j = 26;
	k = 223;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}


motor.c:

#include "reg52.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;


void goForward(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 1;
}

void goBack(){
	LeftCon1A = 1;
	LeftCon1B = 0;
	RightCon1A = 1;
	RightCon1B = 0;
}


void goLeft(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 1;
}

void goRight(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 0;
} 

void stop(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 0;
} 

hc04.h:

void Timer1Init();
double get_distance();

sg90.h:

void Timer0Init();
void openStatusLight();
void closeStatusLight();
void openDusbin();
void closeDusbin();
void initSG90();
void sgLeft();
void sgMiddle();
void sgRight();

delay.h:

void Delay10us();		//@11.0592MHz
void Delay200ms();		//@11.0592MHz
void Delay150ms();		//@11.0592MHz
void Delay300ms();		//@11.0592MHz

motor.h:

void goForward();
void goBack();
void goLeft();
void goRight();
void stop();

126.实地测试及BUG微调

(1)实际路况测试,主要添加距离小于10cm时,小车后退,其他调整根据实际情况而定;

127.小车测速原理

(1)利用测速模块检测电机转速;根据有遮挡输出高电平,无遮挡输出低电平;
(2)测速原理:走一圈周长C=23.14半径=3.14直径。
码盘有20个格子,每经过一个格子会有遮挡(高电平)和不遮挡(低电平),一个脉冲大概走3.14
6.5cm/20=1.0205cm;
(3)定时器设定成1s,统计脉冲数,1个脉冲就是1cm;若一秒钟有80个脉冲,那么速度就是80cm/s;

128.小车测速代码实现

(1)利用串口控制小车代码+PWM小车调速中的定时器代码修改,测速需要用到串口发送速度;
设定1s需要用到定时器计时;计算脉冲数需要用到外部中断;
(car_speed_measurement.c,uart.c,time.c,delay.c,uart.h,time.h,delay.h) car_speed_measurement.c:

#include "reg52.h"
#include "uart.h"
#include "time.h"
#include "stdio.h"
#include "uart.h"
sbit speedIO = P3^2;
unsigned int speedCnt = 0;//外部中断0
extern unsigned int speed;//速度
extern char signal;//主程序发送速度数据的通知
char speedMes[24];//主程序发送速度数据的字符串缓冲区
void Ex0Init(){
	EX0 = 1;//允许中断
	//EA = 1; 串口中已打开了总中断
	IT0 = 1;//外部中断下降沿触发
}
void main(){
	Time0Init();//定时器0初始化
	UartInit();//串口初始化
	Ex0Init();//外部中断初始化
	while(1){
		if(signal){//定时器0到1s的时,signal置1,主程序发送速度
			sprintf(speedMes,"speed:%d cm/s",speed);//串口数据的字符串拼接
			SendString(speedMes);//发速度
			SendString("\r\n");
			signal = 0;//清0,定时器0再过1s会重新置1
		}
	}
}
void speedHandler() interrupt 0{//外部中断处理函数
	speedCnt++;//码盘转动一个格子+1
}

uart.c:

#include "reg52.h"
#include "motor.h"
#include "string.h"
#define SIZE 12
sfr AUXR = 0x8E;
char buffer[SIZE];
void UartInit(void)		//9600bps@11.0592MHz
{
	AUXR = 0x01;
	SCON = 0x50; //配置串口工作方式1,REN使能接收        
	TMOD &= 0x0F;
	TMOD |= 0x20;//定时器1工作方式位8位自动重装
	
	TH1 = 0xFD;
	TL1 = 0xFD;//9600波特率的初值
	TR1 = 1;//启动定时器
	EA = 1;//开启总中断
	ES = 1;//开启串口中断
}
void SendByte(char mydata){
	SBUF = mydata;
	while(!TI);
	TI = 0;
}
void SendString(char *str){
	while(*str != '\0'){
		SendByte(*str);
		str++;
	}
}
void Uart_Handler() interrupt 4 {
	static int i = 0;//静态变量,背初始化一次
	char tmp;
	//判断是否收到数据,收到数据硬件会将RI置1
	if(RI){
		RI = 0;//清除接收中断标志位
		tmp = SBUF;
		if(tmp == 'M'){
			i = 0;
		}
		buffer[i++] = tmp;
		if(buffer[0] == 'M' ){
			switch(buffer[1]){
				case '1':
					goForward();
					break;
				case '2':
					goBack();
					break;
				case '3':
					goLeft();
					break;
				case '4':
					goRight();
					break;
				default:
					stop();
					break;
			}
		}
		if(i == 12){
			memset(buffer,'\0',SIZE);
			i = 0;
		} 
	}
}

time.c:

#include "reg52.h"
#include "intrins.h"
#include "motor.h"
unsigned int cnt = 0;
unsigned int speed;
extern unsigned int speedCnt;
char signal = 0;
void Time0Init(){

	//选择定时器0工作模式16位计数
	TMOD &= 0xF0;
	TMOD |= 0x01; 
	TL0 = 0x33;		//设置定时初值
	TH0 = 0xFE;		//设置定时初值	
	//开始计数
	TR0 = 1;
	TF0 = 0;
	//打开定时器0中断
	EA = 1;
	ET0 = 1;
}



void Time0Handler() interrupt 1{
	//统计爆表次数
	cnt ++;
	//重新定时器赋初值
	TL0 = 0x33;
	TH0 = 0xFE;	
	//爆表2000次,经过1s
	if(cnt == 2000){
		signal = 1;
		//经过1s后重新累计,并且输出高电平`
		cnt = 0;
		speed = speedCnt;
		speedCnt = 0;
	}
}

uart.h:

void UartInit(void);
void SendString(char *str);

time.h:

void Time0Init();

129.小车测速代码验证及BUG修改

(1)代码验证及调整;

130.Oled二次开发为了显示速度

(1)将OLED显示字符A代码+厂家提供代码(Oled显示单个字符函数,Oled显示字符串函数)重新分文件封装;
(small_car_oled.c,Oled.c,Oled.h,Oledfont.h)
small_car_oled.c:

#include "reg52.h"
#include "intrins.h"
#include "Oled.h"
void main()
{
		//1. OLED初始化
		Oled_Init();
		Oled_Clear();
		Oled_Show_Str(2,2,"speed:35/s");
		while(1);
}

Oled.c:

#include "reg52.h"
#include "intrins.h"
#include "Oledfont.h"
sbit scl = P1^2;
sbit sda = P1^3;

void IIC_Start()
{
	scl = 0;
	sda = 1;
	scl = 1;
	_nop_();
	sda = 0;
	_nop_();
}

void IIC_Stop()
{
	scl = 0;
	sda = 0;
	scl = 1;
	_nop_();
	sda = 1;
	_nop_();
}

char IIC_ACK()
{
	char flag;
	sda = 1;//就在时钟脉冲9期间释放数据线
	_nop_();
	scl = 1;
	_nop_();
	flag = sda;
	_nop_();
	scl = 0;
	_nop_();
	
	return flag;
}

void IIC_Send_Byte(char dataSend)
{
	int i;
	
	for(i = 0;i<8;i++){
		scl = 0;//scl拉低,让sda做好数据准备
		sda = dataSend & 0x80;//1000 0000获得dataSend的最高位,给sda
		_nop_();//发送数据建立时间
		scl = 1;//scl拉高开始发送
		_nop_();//数据发送时间
		scl = 0;//发送完毕拉低
		_nop_();//
		dataSend = dataSend << 1;
	}
}

void Oled_Write_Cmd(char dataCmd)
{
	//	1. start()
	IIC_Start();
	//		
	//	2. 写入从机地址  b0111 1000 0x78
	IIC_Send_Byte(0x78);
	//	3. ACK
	IIC_ACK();
	//	4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
	IIC_Send_Byte(0x00);
	//	5. ACK
	IIC_ACK();
	//6. 写入指令/数据
	IIC_Send_Byte(dataCmd);
	//7. ACK
	IIC_ACK();
	//8. STOP
	IIC_Stop();
}

void Oled_Write_Data(char dataData)
{
	//	1. start()
	IIC_Start();
	//		
	//	2. 写入从机地址  b0111 1000 0x78
	IIC_Send_Byte(0x78);
	//	3. ACK
	IIC_ACK();
	//	4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
	IIC_Send_Byte(0x40);
	//	5. ACK
	IIC_ACK();
	///6. 写入指令/数据
	IIC_Send_Byte(dataData);
	//7. ACK
	IIC_ACK();
	//8. STOP
	IIC_Stop();
}


void Oled_Init(void){
	Oled_Write_Cmd(0xAE);//--display off
	Oled_Write_Cmd(0x00);//---set low column address
	Oled_Write_Cmd(0x10);//---set high column address
	Oled_Write_Cmd(0x40);//--set start line address  
	Oled_Write_Cmd(0xB0);//--set page address
	Oled_Write_Cmd(0x81); // contract control
	Oled_Write_Cmd(0xFF);//--128   
	Oled_Write_Cmd(0xA1);//set segment remap 
	Oled_Write_Cmd(0xA6);//--normal / reverse
	Oled_Write_Cmd(0xA8);//--set multiplex ratio(1 to 64)
	Oled_Write_Cmd(0x3F);//--1/32 duty
	Oled_Write_Cmd(0xC8);//Com scan direction
	Oled_Write_Cmd(0xD3);//-set display offset
	Oled_Write_Cmd(0x00);//
	
	Oled_Write_Cmd(0xD5);//set osc division
	Oled_Write_Cmd(0x80);//
	
	Oled_Write_Cmd(0xD8);//set area color mode off
	Oled_Write_Cmd(0x05);//
	
	Oled_Write_Cmd(0xD9);//Set Pre-Charge Period
	Oled_Write_Cmd(0xF1);//
	
	Oled_Write_Cmd(0xDA);//set com pin configuartion
	Oled_Write_Cmd(0x12);//
	
	Oled_Write_Cmd(0xDB);//set Vcomh
	Oled_Write_Cmd(0x30);//
	
	Oled_Write_Cmd(0x8D);//set charge pump enable
	Oled_Write_Cmd(0x14);//
	
	Oled_Write_Cmd(0xAF);//--turn on oled panel		
}

void Oled_Clear()
{
	unsigned char i,j; //-128 --- 127
	
	for(i=0;i<8;i++){
		Oled_Write_Cmd(0xB0 + i);//page0--page7
		//每个page从0列
		Oled_Write_Cmd(0x00);
		Oled_Write_Cmd(0x10);
		//0到127列,依次写入0,每写入数据,列地址自动偏移
		for(j = 0;j<128;j++){
			Oled_Write_Data(0);
		}
	}
}


/******************************************************************************/
// 函数名称:Oled_Show_Char 
// 输入参数:oledChar 
// 输出参数:无 
// 函数功能:OLED显示单个字符
/******************************************************************************/
void Oled_Show_Char(char row,char col,char oledChar){ //row*2-2
	unsigned int  i;
	Oled_Write_Cmd(0xb0+(row*2-2));                           //page 0
	Oled_Write_Cmd(0x00+(col&0x0f));                          //low
	Oled_Write_Cmd(0x10+(col>>4));                            //high	
	for(i=((oledChar-32)*16);i<((oledChar-32)*16+8);i++){
		Oled_Write_Data(F8X16[i]);                            //写数据oledTable1
	}

	Oled_Write_Cmd(0xb0+(row*2-1));                           //page 1
	Oled_Write_Cmd(0x00+(col&0x0f));                          //low
	Oled_Write_Cmd(0x10+(col>>4));                            //high
	for(i=((oledChar-32)*16+8);i<((oledChar-32)*16+8+8);i++){
		Oled_Write_Data(F8X16[i]);                            //写数据oledTable1
	}		
}

void Oled_Show_Str(char row,char col,char *str){
	while(*str!=0){
		Oled_Show_Char(row,col,*str);
		str++;
		col += 8;	
	}		
}


Oled.h:

void Oled_Init(void);
void Oled_Clear();
void Oled_Show_Str(char row,char col,char *str);

Oledfont.h


const unsigned char code F8X16[]=	  
{
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
  0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
  0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
  0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
  0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
  0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
  0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
  0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
  0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
  0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
  0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
  0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
  0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
  0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
  0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
  0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
  0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
  0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
  0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
  0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
  0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
  0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
  0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
  0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
  0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
  0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
  0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
  0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
  0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
  0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
  0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
  0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
  0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
  0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
  0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
  0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
  0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
  0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
  0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
  0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
  0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
  0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
  0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
  0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
  0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
  0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
  0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
  0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
  0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
  0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
  0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
  0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
  0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
  0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
  0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
  0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
  0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
  0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
  0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
  0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
  0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
  0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
  0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
  0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
  0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
  0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
  0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
  0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
  0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
  0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
  0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
  0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
  0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
  0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
  0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
  0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};


131.蓝牙控制且OLED和蓝牙显示速度

(1)测速数据通过串口发送到上位机代码+OLED代码二次开发代码结合;
(car_speed_measurement_display.c,uart.c,time.c,Oled.c,uart.h,time.h,Oled.h,Oledfont.h)
car_speed_measurement_display.c:

#include "reg52.h"
#include "uart.h"
#include "time.h"
#include "stdio.h"
#include "uart.h"
#include "Oled.h"
sbit speedIO = P3^2;
unsigned int speedCnt = 0;//外部中断0
extern unsigned int speed;//速度
extern char signal;//主程序发送速度数据的通知
char speedMes[24];//主程序发送速度数据的字符串缓冲区
void Ex0Init(){
	EX0 = 1;//允许中断
	//EA = 1; 串口中已打开了总中断
	IT0 = 1;//外部中断下降沿触发
}
void main(){
	Time0Init();//定时器0初始化
	UartInit();//串口初始化
	Ex0Init();//外部中断初始化
	Oled_Init();
	Oled_Clear();
	while(1){
		if(signal){//定时器0到1s的时,signal置1,主程序发送速度
			sprintf(speedMes,"speed:%d cm/s",speed);//串口数据的字符串拼接
			SendString(speedMes);//发速度
			SendString("\r\n");
			signal = 0;//清0,定时器0再过1s会重新置1
		}
		Oled_Show_Str(2,2,speedMes);
	}
}



void speedHandler() interrupt 0{//外部中断处理函数
	speedCnt++;//码盘转动一个格子+1
}

uart.c:

#include "reg52.h"
#include "motor.h"
#include "string.h"
#define SIZE 12
sfr AUXR = 0x8E;
char buffer[SIZE];
void UartInit(void)		//9600bps@11.0592MHz
{
	AUXR = 0x01;
	SCON = 0x50; //配置串口工作方式1,REN使能接收        
	TMOD &= 0x0F;
	TMOD |= 0x20;//定时器1工作方式位8位自动重装
	
	TH1 = 0xFD;
	TL1 = 0xFD;//9600波特率的初值
	TR1 = 1;//启动定时器
	EA = 1;//开启总中断
	ES = 1;//开启串口中断
}
void SendByte(char mydata){
	SBUF = mydata;
	while(!TI);
	TI = 0;
}
void SendString(char *str){
	while(*str != '\0'){
		SendByte(*str);
		str++;
	}
}
void Uart_Handler() interrupt 4 {
	static int i = 0;//静态变量,背初始化一次
	char tmp;
	//判断是否收到数据,收到数据硬件会将RI置1
	if(RI){
		RI = 0;//清除接收中断标志位
		tmp = SBUF;
		if(tmp == 'M'){
			i = 0;
		}
		buffer[i++] = tmp;
		if(buffer[0] == 'M' ){
			switch(buffer[1]){
				case '1':
					goForward();
					break;
				case '2':
					goBack();
					break;
				case '3':
					goLeft();
					break;
				case '4':
					goRight();
					break;
				default:
					stop();
					break;
			}
		}
		if(i == 12){
			memset(buffer,'\0',SIZE);
			i = 0;
		} 
	}
}

time.c:

#include "reg52.h"
#include "intrins.h"
#include "motor.h"
unsigned int cnt = 0;
unsigned int speed;
extern unsigned int speedCnt;
char signal = 0;
void Time0Init(){

	//选择定时器0工作模式16位计数
	TMOD &= 0xF0;
	TMOD |= 0x01; 
	TL0 = 0x33;		//设置定时初值
	TH0 = 0xFE;		//设置定时初值	
	//开始计数
	TR0 = 1;
	TF0 = 0;
	//打开定时器0中断
	EA = 1;
	ET0 = 1;
}



void Time0Handler() interrupt 1{
	//统计爆表次数
	cnt ++;
	//重新定时器赋初值
	TL0 = 0x33;
	TH0 = 0xFE;	
	//爆表2000次,经过1s
	if(cnt == 2000){
		signal = 1;
		//经过1s后重新累计,并且输出高电平`
		cnt = 0;
		speed = speedCnt;
		speedCnt = 0;
	}
}

Oled.c:

#include "reg52.h"
#include "intrins.h"
#include "Oledfont.h"
sbit scl = P1^2;
sbit sda = P1^3;

void IIC_Start()
{
	scl = 0;
	sda = 1;
	scl = 1;
	_nop_();
	sda = 0;
	_nop_();
}

void IIC_Stop()
{
	scl = 0;
	sda = 0;
	scl = 1;
	_nop_();
	sda = 1;
	_nop_();
}

char IIC_ACK()
{
	char flag;
	sda = 1;//就在时钟脉冲9期间释放数据线
	_nop_();
	scl = 1;
	_nop_();
	flag = sda;
	_nop_();
	scl = 0;
	_nop_();
	
	return flag;
}

void IIC_Send_Byte(char dataSend)
{
	int i;
	
	for(i = 0;i<8;i++){
		scl = 0;//scl拉低,让sda做好数据准备
		sda = dataSend & 0x80;//1000 0000获得dataSend的最高位,给sda
		_nop_();//发送数据建立时间
		scl = 1;//scl拉高开始发送
		_nop_();//数据发送时间
		scl = 0;//发送完毕拉低
		_nop_();//
		dataSend = dataSend << 1;
	}
}

void Oled_Write_Cmd(char dataCmd)
{
	//	1. start()
	IIC_Start();
	//		
	//	2. 写入从机地址  b0111 1000 0x78
	IIC_Send_Byte(0x78);
	//	3. ACK
	IIC_ACK();
	//	4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
	IIC_Send_Byte(0x00);
	//	5. ACK
	IIC_ACK();
	//6. 写入指令/数据
	IIC_Send_Byte(dataCmd);
	//7. ACK
	IIC_ACK();
	//8. STOP
	IIC_Stop();
}

void Oled_Write_Data(char dataData)
{
	//	1. start()
	IIC_Start();
	//		
	//	2. 写入从机地址  b0111 1000 0x78
	IIC_Send_Byte(0x78);
	//	3. ACK
	IIC_ACK();
	//	4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
	IIC_Send_Byte(0x40);
	//	5. ACK
	IIC_ACK();
	///6. 写入指令/数据
	IIC_Send_Byte(dataData);
	//7. ACK
	IIC_ACK();
	//8. STOP
	IIC_Stop();
}


void Oled_Init(void){
	Oled_Write_Cmd(0xAE);//--display off
	Oled_Write_Cmd(0x00);//---set low column address
	Oled_Write_Cmd(0x10);//---set high column address
	Oled_Write_Cmd(0x40);//--set start line address  
	Oled_Write_Cmd(0xB0);//--set page address
	Oled_Write_Cmd(0x81); // contract control
	Oled_Write_Cmd(0xFF);//--128   
	Oled_Write_Cmd(0xA1);//set segment remap 
	Oled_Write_Cmd(0xA6);//--normal / reverse
	Oled_Write_Cmd(0xA8);//--set multiplex ratio(1 to 64)
	Oled_Write_Cmd(0x3F);//--1/32 duty
	Oled_Write_Cmd(0xC8);//Com scan direction
	Oled_Write_Cmd(0xD3);//-set display offset
	Oled_Write_Cmd(0x00);//
	
	Oled_Write_Cmd(0xD5);//set osc division
	Oled_Write_Cmd(0x80);//
	
	Oled_Write_Cmd(0xD8);//set area color mode off
	Oled_Write_Cmd(0x05);//
	
	Oled_Write_Cmd(0xD9);//Set Pre-Charge Period
	Oled_Write_Cmd(0xF1);//
	
	Oled_Write_Cmd(0xDA);//set com pin configuartion
	Oled_Write_Cmd(0x12);//
	
	Oled_Write_Cmd(0xDB);//set Vcomh
	Oled_Write_Cmd(0x30);//
	
	Oled_Write_Cmd(0x8D);//set charge pump enable
	Oled_Write_Cmd(0x14);//
	
	Oled_Write_Cmd(0xAF);//--turn on oled panel		
}

void Oled_Clear()
{
	unsigned char i,j; //-128 --- 127
	
	for(i=0;i<8;i++){
		Oled_Write_Cmd(0xB0 + i);//page0--page7
		//每个page从0列
		Oled_Write_Cmd(0x00);
		Oled_Write_Cmd(0x10);
		//0到127列,依次写入0,每写入数据,列地址自动偏移
		for(j = 0;j<128;j++){
			Oled_Write_Data(0);
		}
	}
}


/******************************************************************************/
// 函数名称:Oled_Show_Char 
// 输入参数:oledChar 
// 输出参数:无 
// 函数功能:OLED显示单个字符
/******************************************************************************/
void Oled_Show_Char(char row,char col,char oledChar){ //row*2-2
	unsigned int  i;
	Oled_Write_Cmd(0xb0+(row*2-2));                           //page 0
	Oled_Write_Cmd(0x00+(col&0x0f));                          //low
	Oled_Write_Cmd(0x10+(col>>4));                            //high	
	for(i=((oledChar-32)*16);i<((oledChar-32)*16+8);i++){
		Oled_Write_Data(F8X16[i]);                            //写数据oledTable1
	}

	Oled_Write_Cmd(0xb0+(row*2-1));                           //page 1
	Oled_Write_Cmd(0x00+(col&0x0f));                          //low
	Oled_Write_Cmd(0x10+(col>>4));                            //high
	for(i=((oledChar-32)*16+8);i<((oledChar-32)*16+8+8);i++){
		Oled_Write_Data(F8X16[i]);                            //写数据oledTable1
	}		
}

void Oled_Show_Str(char row,char col,char *str){
	while(*str!=0){
		Oled_Show_Char(row,col,*str);
		str++;
		col += 8;	
	}		
}


uart.h:

void UartInit(void);
void SendString(char *str);

time.h:

void Time0Init();

Oled.h:

void Oled_Init(void);
void Oled_Clear();
void Oled_Show_Str(char row,char col,char *str);

Oledfont.h:


const unsigned char code F8X16[]=	  
{
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
  0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
  0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
  0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
  0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
  0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
  0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
  0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
  0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
  0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
  0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
  0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
  0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
  0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
  0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
  0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
  0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
  0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
  0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
  0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
  0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
  0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
  0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
  0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
  0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
  0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
  0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
  0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
  0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
  0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
  0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
  0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
  0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
  0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
  0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
  0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
  0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
  0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
  0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
  0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
  0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
  0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
  0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
  0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
  0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
  0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
  0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
  0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
  0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
  0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
  0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
  0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
  0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
  0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
  0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
  0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
  0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
  0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
  0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
  0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
  0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
  0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
  0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
  0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
  0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
  0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
  0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
  0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
  0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
  0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
  0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
  0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
  0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
  0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
  0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
  0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};


132.wifi控制小车并发送速度

(1)蓝牙测速并本地显示的小车代码+wifi模块04_esp工作在路由服务器模式代码(wifi初始化,等待wifi连接)结合;
(car_speed_measurement_display_by_wifi.c,uart.c,time.c,Oled.c,esp8266.c,delay.c,uart.h,time.h,Oled.h,Oledfont.h,esp8266.h,delay.h)
car_speed_measurement_display_by_wifi.c:

#include "reg52.h"
#include "uart.h"
#include "time.h"
#include "stdio.h"
#include "uart.h"
#include "Oled.h"
#include "delay.h"
#include "esp8266.h"

sbit speedIO = P3^2;
unsigned int speedCnt = 0;//外部中断0
extern unsigned int speed;//速度
extern char signal;//主程序发送速度数据的通知
char speedMes[24];//主程序发送速度数据的字符串缓冲区
//4 发送数据
char FSSJ[] = "AT+CIPSEND=0,5\r\n";
void Ex0Init(){
	EX0 = 1;//允许中断
	//EA = 1; 串口中已打开了总中断
	IT0 = 1;//外部中断下降沿触发
}
void main(){
	Time0Init();//定时器0初始化
	UartInit();//串口初始化
	Delay1000ms();//给espwifi模块上电时间
	initWifi_AP(); //初始化wifi工作在ap模式
	waitConnect(); //等待客户端的连接
	Ex0Init();//外部中断初始化
	Oled_Init();
	Oled_Clear();
	while(1){
		if(signal){//定时器0到1s的时,signal置1,主程序发送速度
			SendString(FSSJ);
			Delay1000ms();			
			sprintf(speedMes,"%dcms",speed);//串口数据的字符串拼接
			SendString(speedMes);//发速度
			SendString("\r\n");
			signal = 0;//清0,定时器0再过1s会重新置1
		}
		Oled_Show_Str(2,2,speedMes);
	}
}

void speedHandler() interrupt 0{//外部中断处理函数
	speedCnt++;//码盘转动一个格子+1
}

uart.c:

#include "reg52.h"
#include "motor.h"
#include "string.h"
#define SIZE 12
sfr AUXR = 0x8E;
char buffer[SIZE];

extern char AT_OK_Flag;				//OK返回值的标志位
extern char Client_Connect_Flag;

void UartInit(void)		//9600bps@11.0592MHz
{
	AUXR = 0x01;
	SCON = 0x50; //配置串口工作方式1,REN使能接收        
	TMOD &= 0x0F;
	TMOD |= 0x20;//定时器1工作方式位8位自动重装
	
	TH1 = 0xFD;
	TL1 = 0xFD;//9600波特率的初值
	TR1 = 1;//启动定时器
	EA = 1;//开启总中断
	ES = 1;//开启串口中断
}
void SendByte(char mydata){
	SBUF = mydata;
	while(!TI);
	TI = 0;
}
void SendString(char *str){
	while(*str != '\0'){
		SendByte(*str);
		str++;
	}
}
void Uart_Handler() interrupt 4 {
	static int i = 0;//静态变量,背初始化一次
	char tmp;
	//判断是否收到数据,收到数据硬件会将RI置1
	if(RI){
		RI = 0;//清除接收中断标志位
		tmp = SBUF;
		if(tmp == 'M' || tmp == 'O' || tmp == '0'){
			i = 0;
		}
		buffer[i++] = tmp;		
		//连接服务器等OK返回值指令的判断
		if(buffer[0] == 'O' && buffer[1] == 'K'){
			AT_OK_Flag	= 1;
			memset(buffer, '\0', SIZE);
		}
			
		if(buffer[0] == '0' && buffer[2] == 'C'){
			Client_Connect_Flag	= 1;
			memset(buffer, '\0', SIZE);
		}
		if(buffer[0] == 'M' ){
			switch(buffer[1]){
				case '1':
					goForward();
					break;
				case '2':
					goBack();
					break;
				case '3':
					goLeft();
					break;
				case '4':
					goRight();
					break;
				default:
					stop();
					break;
			}
		}
		if(i == 12){
			memset(buffer,'\0',SIZE);
			i = 0;
		} 
	}
}

time.c:

#include "reg52.h"
#include "intrins.h"
#include "motor.h"
unsigned int cnt = 0;
unsigned int speed;
extern unsigned int speedCnt;
char signal = 0;
void Time0Init(){

	//选择定时器0工作模式16位计数
	TMOD &= 0xF0;
	TMOD |= 0x01; 
	TL0 = 0x33;		//设置定时初值
	TH0 = 0xFE;		//设置定时初值	
	//开始计数
	TR0 = 1;
	TF0 = 0;
	//打开定时器0中断
	EA = 1;
	ET0 = 1;
}



void Time0Handler() interrupt 1{
	//统计爆表次数
	cnt ++;
	//重新定时器赋初值
	TL0 = 0x33;
	TH0 = 0xFE;	
	//爆表2000次,经过1s
	if(cnt == 2000){
		signal = 1;
		//经过1s后重新累计,并且输出高电平`
		cnt = 0;
		speed = speedCnt;
		speedCnt = 0;
	}
}

Oled.c:

#include "reg52.h"
#include "intrins.h"
#include "Oledfont.h"
sbit scl = P1^2;
sbit sda = P1^3;

void IIC_Start()
{
	scl = 0;
	sda = 1;
	scl = 1;
	_nop_();
	sda = 0;
	_nop_();
}

void IIC_Stop()
{
	scl = 0;
	sda = 0;
	scl = 1;
	_nop_();
	sda = 1;
	_nop_();
}

char IIC_ACK()
{
	char flag;
	sda = 1;//就在时钟脉冲9期间释放数据线
	_nop_();
	scl = 1;
	_nop_();
	flag = sda;
	_nop_();
	scl = 0;
	_nop_();
	
	return flag;
}

void IIC_Send_Byte(char dataSend)
{
	int i;
	
	for(i = 0;i<8;i++){
		scl = 0;//scl拉低,让sda做好数据准备
		sda = dataSend & 0x80;//1000 0000获得dataSend的最高位,给sda
		_nop_();//发送数据建立时间
		scl = 1;//scl拉高开始发送
		_nop_();//数据发送时间
		scl = 0;//发送完毕拉低
		_nop_();//
		dataSend = dataSend << 1;
	}
}

void Oled_Write_Cmd(char dataCmd)
{
	//	1. start()
	IIC_Start();
	//		
	//	2. 写入从机地址  b0111 1000 0x78
	IIC_Send_Byte(0x78);
	//	3. ACK
	IIC_ACK();
	//	4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
	IIC_Send_Byte(0x00);
	//	5. ACK
	IIC_ACK();
	//6. 写入指令/数据
	IIC_Send_Byte(dataCmd);
	//7. ACK
	IIC_ACK();
	//8. STOP
	IIC_Stop();
}

void Oled_Write_Data(char dataData)
{
	//	1. start()
	IIC_Start();
	//		
	//	2. 写入从机地址  b0111 1000 0x78
	IIC_Send_Byte(0x78);
	//	3. ACK
	IIC_ACK();
	//	4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
	IIC_Send_Byte(0x40);
	//	5. ACK
	IIC_ACK();
	///6. 写入指令/数据
	IIC_Send_Byte(dataData);
	//7. ACK
	IIC_ACK();
	//8. STOP
	IIC_Stop();
}


void Oled_Init(void){
	Oled_Write_Cmd(0xAE);//--display off
	Oled_Write_Cmd(0x00);//---set low column address
	Oled_Write_Cmd(0x10);//---set high column address
	Oled_Write_Cmd(0x40);//--set start line address  
	Oled_Write_Cmd(0xB0);//--set page address
	Oled_Write_Cmd(0x81); // contract control
	Oled_Write_Cmd(0xFF);//--128   
	Oled_Write_Cmd(0xA1);//set segment remap 
	Oled_Write_Cmd(0xA6);//--normal / reverse
	Oled_Write_Cmd(0xA8);//--set multiplex ratio(1 to 64)
	Oled_Write_Cmd(0x3F);//--1/32 duty
	Oled_Write_Cmd(0xC8);//Com scan direction
	Oled_Write_Cmd(0xD3);//-set display offset
	Oled_Write_Cmd(0x00);//
	
	Oled_Write_Cmd(0xD5);//set osc division
	Oled_Write_Cmd(0x80);//
	
	Oled_Write_Cmd(0xD8);//set area color mode off
	Oled_Write_Cmd(0x05);//
	
	Oled_Write_Cmd(0xD9);//Set Pre-Charge Period
	Oled_Write_Cmd(0xF1);//
	
	Oled_Write_Cmd(0xDA);//set com pin configuartion
	Oled_Write_Cmd(0x12);//
	
	Oled_Write_Cmd(0xDB);//set Vcomh
	Oled_Write_Cmd(0x30);//
	
	Oled_Write_Cmd(0x8D);//set charge pump enable
	Oled_Write_Cmd(0x14);//
	
	Oled_Write_Cmd(0xAF);//--turn on oled panel		
}

void Oled_Clear()
{
	unsigned char i,j; //-128 --- 127
	
	for(i=0;i<8;i++){
		Oled_Write_Cmd(0xB0 + i);//page0--page7
		//每个page从0列
		Oled_Write_Cmd(0x00);
		Oled_Write_Cmd(0x10);
		//0到127列,依次写入0,每写入数据,列地址自动偏移
		for(j = 0;j<128;j++){
			Oled_Write_Data(0);
		}
	}
}


/******************************************************************************/
// 函数名称:Oled_Show_Char 
// 输入参数:oledChar 
// 输出参数:无 
// 函数功能:OLED显示单个字符
/******************************************************************************/
void Oled_Show_Char(char row,char col,char oledChar){ //row*2-2
	unsigned int  i;
	Oled_Write_Cmd(0xb0+(row*2-2));                           //page 0
	Oled_Write_Cmd(0x00+(col&0x0f));                          //low
	Oled_Write_Cmd(0x10+(col>>4));                            //high	
	for(i=((oledChar-32)*16);i<((oledChar-32)*16+8);i++){
		Oled_Write_Data(F8X16[i]);                            //写数据oledTable1
	}

	Oled_Write_Cmd(0xb0+(row*2-1));                           //page 1
	Oled_Write_Cmd(0x00+(col&0x0f));                          //low
	Oled_Write_Cmd(0x10+(col>>4));                            //high
	for(i=((oledChar-32)*16+8);i<((oledChar-32)*16+8+8);i++){
		Oled_Write_Data(F8X16[i]);                            //写数据oledTable1
	}		
}

void Oled_Show_Str(char row,char col,char *str){
	while(*str!=0){
		Oled_Show_Char(row,col,*str);
		str++;
		col += 8;	
	}		
}


esp8266.c:

#include "uart.h"
//1 配置成路由
code char LYMO[] = "AT+CWMODE=2\r\n";
//2 使能多链接
code char DLJ[] = "AT+CIPMUX=1\r\n";
//3 建立TCPServer
code char JLFW[] = "AT+CIPSERVER=1\r\n";
char AT_OK_Flag = 0;						//OK返回值的标志位
char Client_Connect_Flag = 0;

void initWifi_AP(){
	SendString(LYMO);		//发送选择路由模式指令
	while(!AT_OK_Flag);	//等待返回OK
	AT_OK_Flag = 0;
	SendString(DLJ);		//发送建立多连接指令
	while(!AT_OK_Flag);	//等待返回OK
	AT_OK_Flag = 0;
}
void waitConnect(){
	SendString(JLFW);		//发送建立TCPServer指令
	while(!Client_Connect_Flag);	//等待返回OK
	AT_OK_Flag = 0;
}

delay.c:

#include "intrins.h"

void Delay1000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 8;
	j = 1;
	k = 243;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

uart.h:

void UartInit(void);
void SendString(char *str);
void SendByte(char mydata);

time.h:

void Time0Init();

Oled.h:

void Oled_Init(void);
void Oled_Clear();
void Oled_Show_Str(char row,char col,char *str);

Oledfont.h:


const unsigned char code F8X16[]=	  
{
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
  0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
  0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
  0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
  0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
  0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
  0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
  0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
  0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
  0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
  0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
  0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
  0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
  0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
  0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
  0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
  0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
  0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
  0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
  0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
  0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
  0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
  0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
  0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
  0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
  0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
  0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
  0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
  0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
  0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
  0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
  0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
  0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
  0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
  0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
  0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
  0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
  0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
  0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
  0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
  0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
  0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
  0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
  0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
  0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
  0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
  0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
  0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
  0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
  0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
  0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
  0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
  0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
  0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
  0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
  0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
  0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
  0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
  0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
  0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
  0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
  0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
  0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
  0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
  0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
  0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
  0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
  0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
  0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
  0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
  0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
  0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
  0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
  0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
  0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
  0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};


esp8266.h:

void initWifi_AP();
void waitConnect();

delay.h:

Delay1000ms();

133.4g模块控制小车

(1)蓝牙测速并本地显示的小车代码+4G模块代码结合

134-1.非特定语音识别方案介绍

(1)SU-03T语音识别模块,平台网址:http://www.smartpi.cn/#/

134-2.SU-03T语音模块的配置使用

(1)平台网页上配置语音模块,生成SDK压缩包;

135.SU-03T固件烧录并语音识别测试

(1)语音模块连接串口工具,其中B7接串口工具RXD,B6接串口工具TXD;
(2)解压压缩包,用里面的UniOneUpdateTool.exe烧录工具进行烧录,烧录uni_app_release_update.bin文件

136.语音识别切换小车循迹避障跟随且Oled显示状态

(1)摇头避障小车代码+循迹实现01代码+跟随小车代码+蓝牙测速并本地显示的小车代码中的Oled.c,Oled.h,Oledfont.h
(small_car_voice_recognition.c,hc04.c,sg90.c,delay.c,motor.c,Oled.c,hc04.h,sg90.h,delay.h,motor.h,Oled.h,Oledfont.h)
small_car_voice_recognition.c:

#include "reg52.h"
#include "intrins.h"
#include "delay.h"
#include "hc04.h"
#include "sg90.h"
#include "motor.h"
#include "Oled.h"

#define MIDDLE 0
#define LEFT 1
#define RIGHT 2

#define BZ 1
#define XJ 2
#define GS 3

char dir;
double disMiddle;
double disLeft;
double disRight;

sbit leftSensorX = P2^7;
sbit rightSensorX = P2^6;

sbit leftSensorG = P2^5;
sbit rightSensorG = P2^4;

sbit A25 = P1^5;
sbit A26 = P1^6;
sbit A27 = P1^7;

void xunJiMode(){
		if(leftSensorX == 0 && rightSensorX == 0){
			goForward();
		}
		if(leftSensorX == 0 && rightSensorX == 1){
			goRight();
		}
		if(leftSensorX == 1 && rightSensorX == 0){
			goLeft();
		}
		if(leftSensorX == 1 && rightSensorX == 1){
			stop();
		}		
}

void genSuiMode(){
		if(leftSensorG == 0 && rightSensorG == 0){
			goForward();
		}
		if(leftSensorG == 0 && rightSensorG == 1){
			goLeft();
		}
		if(leftSensorG == 1 && rightSensorG == 0){
			goRight();
		}
		if(leftSensorG == 1 && rightSensorG == 1){
			stop();
		}	
}

void biZhangMode(){
		if(dir != MIDDLE){
			sgMiddle();
			dir = MIDDLE;
			Delay300ms();
		}
		disMiddle = get_distance();
		if(disMiddle > 35){
			//前进
			goForward();
		}else if(disMiddle < 10){
			goBack();
		}else{
			//摇头
			sgLeft();
			Delay300ms();
			disLeft = get_distance();
			sgMiddle();
			Delay300ms();
			sgRight();
			dir = RIGHT;
			Delay300ms();
			disRight = get_distance();
			if(disLeft < disRight){
				goRight();
				Delay150ms();
				stop();
			}
			if(disRight <disLeft){
				goLeft();
				Delay150ms();
				stop();		
			}				
		}
}
void main(){
	int mark = 0;
	//定时器初始化
	Timer0Init();
	Timer1Init();
	sgMiddle();
	Delay300ms();
	Delay300ms();
	dir = MIDDLE;
	Oled_Init();
	Oled_Clear();
	Oled_Show_Str(2,2,"-----Ready----");
	while(1){
		//循迹模式
		if(A25 == 0 && A26 == 1 && A27 == 1){
			if(mark != XJ){
				Oled_Clear();
				Oled_Show_Str(2,2,"------XunJi-----");
			}
			mark = XJ;
			xunJiMode();
		}
		//避障模式
		if(A25 == 1 && A26 == 0 && A27 == 1){
			if(mark != BZ){
				Oled_Clear();
				Oled_Show_Str(2,2,"------Bizhang-----");
			}
			mark = BZ;
			biZhangMode();
		}
		//跟随模式
		if(A25 == 1 && A26 == 1 && A27 == 0){
			if(mark != GS){
				Oled_Clear();
				Oled_Show_Str(2,2,"------GenSui-----");
			}
			mark = GS;
			genSuiMode();
		}
	}
}

hc04.c:

#include "reg52.h"
#include "delay.h"
sbit Trig = P2^3;
sbit Echo = P2^2;

void Timer1Init(){
	//选择定时器1,设定16位计数
	TMOD &= 0x0F;
	TMOD |= 0x10;
	//设定初始值为0
	TH1 = 0;
	TL1 = 0;
}
void TrigInit(){
	//让硬件稳定一下
	Delay200ms();
	Trig = 0;
	//高电平维持10us
	Trig = 1;
	Delay10us();
	Trig = 0;	
}
double get_distance(){
	double time;
	//定时器数据清0,再次测距
	TH1 = 0;
	TL1 = 0;
	//超声波模块启动
	TrigInit();
	//等待发送超声波
	while(Echo == 0);
	//开启定时器
	TR1 = 1;
	while(Echo == 1);
	TR1 = 0;
	//计算时间,TH0的8位要左移2的8次方才可以与TL0相加求和
	time = (TH1*256+TL1)*1.085;
	//计算距离,距离=速度(340m/s)*时间/2=340*100cm/1000000us*时间/2=0.017cm/us*时间
	return (time*0.017);
}

sg90.c:

#include "reg52.h"
#include "delay.h"
sbit sg90_con = P1^1;
int jd;
int cnt = 0;


void Timer0Init(){

	//选择定时器0工作模式16位计数
	TMOD &= 0xF0;
	TMOD |= 0x01; 
	TL0 = 0x33;		//设置定时初值
	TH0 = 0xFE;		//设置定时初值	
	//开始计数
	TR0 = 1;
	TF0 = 0;
	//打开定时器0中断
	EA = 1;
	ET0 = 1;
}

void sgMiddle(){
	//90度,1.5ms的高电平
	jd = 3;
	cnt = 0;

}
void sgLeft(){
	//0度
	jd = 5;
	cnt = 0;
}
void sgRight(){
	//0度
	jd = 1;
	cnt = 0;
}
void Time0Handler() interrupt 1{
	//统计爆表次数
	cnt ++;
	//重新定时器赋初值
	TL0 = 0x33;
	TH0 = 0xFE;	
	//控制PWM波
	if(cnt < jd){
		sg90_con = 1;
	}else{
		sg90_con = 0;
	}
	//爆表40次,经过20ms
	if(cnt == 40){
		//经过20ms后重新累计,并且输出高电平`
		cnt = 0;
		sg90_con = 1;
	}
}

delay.c:

#include "intrins.h"
void Delay10us()		//@11.0592MHz
{
	unsigned char i;

	i = 2;
	while (--i);
}
void Delay200ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 2;
	j = 103;
	k = 147;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void Delay150ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 2;
	j = 13;
	k = 237;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}
void Delay300ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 3;
	j = 26;
	k = 223;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}


motor.c:

#include "reg52.h"
sbit RightCon1A = P3^7;
sbit RightCon1B = P3^3;
sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;


void goForward(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 1;
}

void goBack(){
	LeftCon1A = 1;
	LeftCon1B = 0;
	RightCon1A = 1;
	RightCon1B = 0;
}


void goLeft(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 1;
}

void goRight(){
	LeftCon1A = 0;
	LeftCon1B = 1;
	RightCon1A = 0;
	RightCon1B = 0;
} 

void stop(){
	LeftCon1A = 0;
	LeftCon1B = 0;
	RightCon1A = 0;
	RightCon1B = 0;
} 

Oled.c:

#include "reg52.h"
#include "intrins.h"
#include "Oledfont.h"
sbit scl = P1^2;
sbit sda = P1^3;

void IIC_Start()
{
	scl = 0;
	sda = 1;
	scl = 1;
	_nop_();
	sda = 0;
	_nop_();
}

void IIC_Stop()
{
	scl = 0;
	sda = 0;
	scl = 1;
	_nop_();
	sda = 1;
	_nop_();
}

char IIC_ACK()
{
	char flag;
	sda = 1;//就在时钟脉冲9期间释放数据线
	_nop_();
	scl = 1;
	_nop_();
	flag = sda;
	_nop_();
	scl = 0;
	_nop_();
	
	return flag;
}

void IIC_Send_Byte(char dataSend)
{
	int i;
	
	for(i = 0;i<8;i++){
		scl = 0;//scl拉低,让sda做好数据准备
		sda = dataSend & 0x80;//1000 0000获得dataSend的最高位,给sda
		_nop_();//发送数据建立时间
		scl = 1;//scl拉高开始发送
		_nop_();//数据发送时间
		scl = 0;//发送完毕拉低
		_nop_();//
		dataSend = dataSend << 1;
	}
}

void Oled_Write_Cmd(char dataCmd)
{
	//	1. start()
	IIC_Start();
	//		
	//	2. 写入从机地址  b0111 1000 0x78
	IIC_Send_Byte(0x78);
	//	3. ACK
	IIC_ACK();
	//	4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
	IIC_Send_Byte(0x00);
	//	5. ACK
	IIC_ACK();
	//6. 写入指令/数据
	IIC_Send_Byte(dataCmd);
	//7. ACK
	IIC_ACK();
	//8. STOP
	IIC_Stop();
}

void Oled_Write_Data(char dataData)
{
	//	1. start()
	IIC_Start();
	//		
	//	2. 写入从机地址  b0111 1000 0x78
	IIC_Send_Byte(0x78);
	//	3. ACK
	IIC_ACK();
	//	4. cotrol byte: (0)(0)000000 写入命令   (0)(1)000000写入数据
	IIC_Send_Byte(0x40);
	//	5. ACK
	IIC_ACK();
	///6. 写入指令/数据
	IIC_Send_Byte(dataData);
	//7. ACK
	IIC_ACK();
	//8. STOP
	IIC_Stop();
}


void Oled_Init(void){
	Oled_Write_Cmd(0xAE);//--display off
	Oled_Write_Cmd(0x00);//---set low column address
	Oled_Write_Cmd(0x10);//---set high column address
	Oled_Write_Cmd(0x40);//--set start line address  
	Oled_Write_Cmd(0xB0);//--set page address
	Oled_Write_Cmd(0x81); // contract control
	Oled_Write_Cmd(0xFF);//--128   
	Oled_Write_Cmd(0xA1);//set segment remap 
	Oled_Write_Cmd(0xA6);//--normal / reverse
	Oled_Write_Cmd(0xA8);//--set multiplex ratio(1 to 64)
	Oled_Write_Cmd(0x3F);//--1/32 duty
	Oled_Write_Cmd(0xC8);//Com scan direction
	Oled_Write_Cmd(0xD3);//-set display offset
	Oled_Write_Cmd(0x00);//
	
	Oled_Write_Cmd(0xD5);//set osc division
	Oled_Write_Cmd(0x80);//
	
	Oled_Write_Cmd(0xD8);//set area color mode off
	Oled_Write_Cmd(0x05);//
	
	Oled_Write_Cmd(0xD9);//Set Pre-Charge Period
	Oled_Write_Cmd(0xF1);//
	
	Oled_Write_Cmd(0xDA);//set com pin configuartion
	Oled_Write_Cmd(0x12);//
	
	Oled_Write_Cmd(0xDB);//set Vcomh
	Oled_Write_Cmd(0x30);//
	
	Oled_Write_Cmd(0x8D);//set charge pump enable
	Oled_Write_Cmd(0x14);//
	
	Oled_Write_Cmd(0xAF);//--turn on oled panel		
}

void Oled_Clear()
{
	unsigned char i,j; //-128 --- 127
	
	for(i=0;i<8;i++){
		Oled_Write_Cmd(0xB0 + i);//page0--page7
		//每个page从0列
		Oled_Write_Cmd(0x00);
		Oled_Write_Cmd(0x10);
		//0到127列,依次写入0,每写入数据,列地址自动偏移
		for(j = 0;j<128;j++){
			Oled_Write_Data(0);
		}
	}
}


/******************************************************************************/
// 函数名称:Oled_Show_Char 
// 输入参数:oledChar 
// 输出参数:无 
// 函数功能:OLED显示单个字符
/******************************************************************************/
void Oled_Show_Char(char row,char col,char oledChar){ //row*2-2
	unsigned int  i;
	Oled_Write_Cmd(0xb0+(row*2-2));                           //page 0
	Oled_Write_Cmd(0x00+(col&0x0f));                          //low
	Oled_Write_Cmd(0x10+(col>>4));                            //high	
	for(i=((oledChar-32)*16);i<((oledChar-32)*16+8);i++){
		Oled_Write_Data(F8X16[i]);                            //写数据oledTable1
	}

	Oled_Write_Cmd(0xb0+(row*2-1));                           //page 1
	Oled_Write_Cmd(0x00+(col&0x0f));                          //low
	Oled_Write_Cmd(0x10+(col>>4));                            //high
	for(i=((oledChar-32)*16+8);i<((oledChar-32)*16+8+8);i++){
		Oled_Write_Data(F8X16[i]);                            //写数据oledTable1
	}		
}

void Oled_Show_Str(char row,char col,char *str){
	while(*str!=0){
		Oled_Show_Char(row,col,*str);
		str++;
		col += 8;	
	}		
}


hc04.h:

void Timer1Init();
double get_distance();

sg90.h:

void Timer0Init();
void openStatusLight();
void closeStatusLight();
void openDusbin();
void closeDusbin();
void initSG90();
void sgLeft();
void sgMiddle();
void sgRight();

delay.h:

void Delay10us();		//@11.0592MHz
void Delay200ms();		//@11.0592MHz
void Delay150ms();		//@11.0592MHz
void Delay300ms();		//@11.0592MHz

motor.h:

void goForward();
void goBack();
void goLeft();
void goRight();
void stop();

Oled.h:

void Oled_Init(void);
void Oled_Clear();
void Oled_Show_Str(char row,char col,char *str);

Oledfont.h:


const unsigned char code F8X16[]=	  
{
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
  0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
  0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
  0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
  0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
  0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
  0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
  0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
  0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
  0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
  0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
  0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
  0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
  0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
  0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
  0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
  0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
  0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
  0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
  0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
  0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
  0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
  0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
  0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
  0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
  0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
  0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
  0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
  0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
  0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
  0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
  0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
  0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
  0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
  0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
  0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
  0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
  0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
  0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
  0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
  0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
  0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
  0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
  0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
  0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
  0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
  0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
  0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
  0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
  0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
  0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
  0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
  0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
  0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
  0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
  0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
  0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
  0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
  0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
  0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
  0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
  0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
  0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
  0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
  0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
  0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
  0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
  0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
  0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
  0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
  0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
  0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
  0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
  0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
  0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
  0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};


137.效果演示

(1)实际路况测试;

138.语音模块以及硬件模块化开发行情

(1)YS-LDV7语音识别模块–使用手册解析

139.语音模块文档查看及语音识别干扰

140.最强代码阅读器sourceInsight工具介绍

(1)sourceInsight方便阅读大的代码量代码,文件可联系并跳转阅读;
(2)新建工程-》展板中的工程文件清单-》工程中的同步文件-》ctrl+左键可查看底层代码,ctrl+/(查看哪几处使用)

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值