遥控小汽车的设计

更新时间:2023-07-20 15:00:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

红外遥控小车系统设计

默认分类 2010-06-23 09:31:05 阅读122 评论0 字号:大中小 订阅

红外接收与控件电路原理图:

红外遥控器原理图:

红外遥控器实物图:

红外接收与控制实物图:

程序:

接收控制主程序:

#include<reg52.h>

#include "hongwai.c"

#include "5110.c"

sbit hy=P0^0;//LED指示灯

sbit hz=P2^0;

sbit qy=P1^4;

sbit qz=P3^7;

sbit djf1=P1^0;//电机1的方向控制

sbit djd1=P1^1;//电机1的动力控制

sbit djf2=P1^2;//电机2的方向控制

sbit djd2=P1^3;//电机2的动力控制

unsigned char flag,flag1,PW;

bit fan,fan1,tf=0;

unsigned char fafg=0;

unsigned char time_flag;

unsigned char data time[2];

//=====================================

//ms延时

//=====================================

void delayms(unsigned int ms)

{

unsigned char i;

while(ms--)

for(i=0;i<120;i++);

}

//=====================================

//LED灯闪烁

//=====================================

void LED(unsigned char ms)

{

unsigned char i;

for(i=0;i<ms;i++)

{

delayms(200);

qz=~qz;

qy=~qy;

hz=~hz;

hy=~hy;

}

}

//======================================

//控制

//=====================================

void kongzi(void)

{

switch(shu[2])

{

case 0x20: {//前进

fafg=1;

qz=qy=0;

hz=hy=1;

TR1=ET1=1;

djd1=djd2=1;

djf1=djf2=0;

fan=0;

break;

}

case 0x30: {//后退

fafg=2;

qz=qy=1;

hz=hy=0;

TR1=ET1=1;

djd1=djd2=1;

djf1=djf2=1;

fan=1;

break;

}

case 0x40: {//前左转弯

fafg=3;

djf1=djf2=0;

qz=0;

qy=hz=hy=1;

djd1=1;

djd2=0;

fan1=0;

TR1=ET1=1;

break;

}

case 0x60: { //后左转弯

fafg=4;

djf1=djf2=1;

hz=0;

hy=qz=qy=1;

djd1=1;

djd2=0;

fan1=0;

TR1=ET1=1;

break;

}

case 0x50: {//前右转弯

fafg=5;

djf1=djf2=0;

qy=0;

qz=hy=hz=1;

djd1=0;

djd2=1;

fan1=1;

TR1=ET1=1;

break;

}

case 0x70: { //后退

fafg=6;

djf1=djf2=1;

hy=0;

hz=qz=qy=1;

djd1=0;

djd2=1;

fan1=1;

TR1=ET1=1;

break;

}

case 0x80: {

if(tf==1)

{

qy=qz=hy=hz=1;

TR1=ET1=0;

djd1=djd2=0;

NOKIA5110_clear(); // 清屏

W_LCD_chinese(20,0,21);//停

W_LCD_chinese(40,0,22);//止

W_LCD_zifu(15,3,time[1]/10);//

W_LCD_zifu(23,3,time[1]%10);//

W_LCD_zifu(33,3,11);//:

W_LCD_zifu(42,3,time[0]/10);//

W_LCD_zifu(50,3,time[0]%10);//

time[0]=time[1]=0;

tf=0;

}

break;

}

}

}

//***********************************************

//显示

//************************************************

void LCD_display(void)

{

NOKIA5110_clear(); // 清屏

W_LCD_zifu(15,3,time[1]/10);//

W_LCD_zifu(23,3,time[1]%10);//

W_LCD_zifu(33,3,11);//:

W_LCD_zifu(42,3,time[0]/10);//

W_LCD_zifu(50,3,time[0]%10);//

if(fafg==1)

{

W_LCD_chinese(20,0,0);//前

W_LCD_chinese(40,0,1);//进

}

if(fafg==2)

{

W_LCD_chinese(20,0,2);//后

W_LCD_chinese(40,0,3);//退

}

if(fafg==3)

{

W_LCD_chinese(5,0,0);//前

W_LCD_chinese(25,0,4);//左

W_LCD_chinese(45,0,5);//转

W_LCD_chinese(65,0,6);//弯

}

if(fafg==4)

{

W_LCD_chinese(5,0,2);//后

W_LCD_chinese(25,0,4);//左

W_LCD_chinese(45,0,5);//转

W_LCD_chinese(65,0,6);//弯

}

if(fafg==5)

{

W_LCD_chinese(5,0,0);//前

W_LCD_chinese(25,0,7);//右

W_LCD_chinese(45,0,5);//转

W_LCD_chinese(65,0,6);//弯

}

if(fafg==6)

{

W_LCD_chinese(5,0,2);//后

W_LCD_chinese(25,0,7);//右

W_LCD_chinese(45,0,5);//转

W_LCD_chinese(65,0,6);//弯

}

}

//=====================================

//定时器T1

//=====================================

void wan_T1(void) interrupt 3

{

time_flag++;

tf=1;

TH1=(65536-50000)/256;

TL1=(65536-50000)%256;

if(time_flag>15)

{

time[0]++;

time_flag=0;

if(time[0]>59)

{

time[0]=0;

time[1]++;

if(time[1]>59) time[1]=0;

}

}

}

//=====================================

//主函数

//=====================================

void main(void)

{

djd1=djd2=0;

NOKIA5110_init();

NOKIA5110_clear(); // 清屏

W_LCD_chinese(0,0,8);//正

delayms(100);

W_LCD_chinese(15,0,9);//在

delayms(100);

W_LCD_chinese(30,0,10);//初

delayms(100);

W_LCD_chinese(45,0,11);//始

delayms(100);

W_LCD_chinese(60,0,12);//化

delayms(100);

W_LCD_chinese(10,3,13);//请

delayms(100);

W_LCD_chinese(25,3,14);//稍

delayms(100);

W_LCD_chinese(40,3,2);//后

delayms(100);

W_LCD_zifu(60,3,10);//...

PW=20;

TH1=(65536-50000)/256;

TL1=(65536-50000)%256;

IP=0x09;//设置中断优先级

IPH=0x08;

open_interrupt();

TR1=ET1=0;

LED(10);

qy=qz=hy=hz=1;

NOKIA5110_clear(); // 清屏

W_LCD_chinese(1,0,10);//初

delayms(100);

W_LCD_chinese(16,0,11);//始

delayms(100);

W_LCD_chinese(31,0,12);//化

delayms(100);

W_LCD_chinese(46,0,15);//完

delayms(100);

W_LCD_chinese(61,0,16);//成

delayms(100);

W_LCD_chinese(0,3,17);//等

delayms(100);

W_LCD_chinese(15,3,18);//待

delayms(100);

W_LCD_chinese(30,3,19);//信

delayms(100);

W_LCD_chinese(45,3,20);//号

delayms(100);

W_LCD_zifu(65,3,10);//...

while(1)

{

kongzi();

if(tf==1&&time_flag==7) LCD_display();

}

}

红外解码:

/*************************************************************************/

/**** 红外解码

/*** 晶振:11.0592MHZ

/*** 数据口:外中断0

/*** 计数器:定时器T0

/************************************************************************/

#include<reg52.h>

sbit Dat=P3^2; //数据口

bit tru;

unsigned char shu[4];

/****************开中断************************/

void open_interrupt(void)

{

TMOD=0x11; //定时器T0工作在方式1

IT0=1; //中断0在下降沿触发

TR0=1;

EX0=1; //开外部中断0

EA=1; //开中断

}

/**************接收数据**********************/

void R_Dat(void) interrupt 0

{

unsigned char i,j;

unsigned int dtime=0;

unsigned char temp;

// P1=0xff;

TH0=TL0=0;

while(!Dat)

{

if(TH0*256+TL0>20000) return;

}

while(Dat)

if(TH0*256+TL0>20000) return;

dtime=TH0*256+TL0;

TH0=TL0=0;

if(8000<dtime&&dtime<14000) //9MS的引导码+4.5MS的结束码

{

for(i=0;i<4;i++)

{

temp=0;

for(j=0;j<8;j++)

{

while(!Dat)

{

if(TH0*256+TL0>20000) return;

}

while(Dat)

{

if(TH0*256+TL0>20000) return;

}

dtime=TH0*256+TL0;

TH0=TL0=0;

if(1450<dtime&&dtime<3000) {temp=(temp>>1)|0x80;}//是否为1

else if(700<dtime&&dtime<1450) {temp=(temp>>1)|0x00;}//是否为0

}

shu[i]=temp;

}

if(shu[0]==~shu[1]&&shu[2]==~shu[3]) tru=1;//查错

}

}

LCD5110驱动程序:

#include<reg52.h>

#include "ziku.C"

//-----------------管脚定义-------------------------

sbit LCD_sce = P2^7; //片选,低最平有效

sbit LCD_rst = P2^6; //复位,0复位

sbit LCD_dc = P2^5; //1写数据,0写指令

sbit LCD_sdin = P2^4; //数据

sbit LCD_sclk = P2^3; //时钟

//**********************************************************************

// NOKIA5110_w_byte : 使用SPI接口写数据到LCD

// 输入参数:data :写入的数据;

// command :写数据/命令选择;

//**********************************************************************

void NOKIA5110_w_byte(unsigned char dat,unsigned char command)

{

unsigned char i;

LCD_sce=0; //LCD使能

LCD_dc=command;//

for(i=0;i<8;i++) //传输8位数据(1个字节)

{

if(dat&0x80) LCD_sdin=1;

else LCD_sdin=0;

dat=dat<<1;

LCD_sclk=0;

LCD_sclk=1;

}

LCD_sce=1; //LCD不使能

}

//**********************************************************************

//NOKIA5110_init : LCD初始化

//**********************************************************************

void NOKIA5110_init(void)

{

unsigned char k;

LCD_rst=0;

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

LCD_rst=1;

//-------------------------------------------------------------

NOKIA5110_w_byte(0x21, 0); // 使用扩展命令设置LCD模式

NOKIA5110_w_byte(0xd0, 0); // 设置偏置电压

NOKIA5110_w_byte(0x06, 0); // 温度校正

NOKIA5110_w_byte(0x13, 0); // 1:48

NOKIA5110_w_byte(0x20, 0); // 使用基本命令

NOKIA5110_w_byte(0x0c, 0); // 设定显示模式,正常显示

}

//**********************************************************************

// NOKIA5110_set_XY : 设置LCD坐标函数

// 输入参数:X:0-83

// Y:0-5

//**********************************************************************

void NOKIA5110_set_XY(unsigned char x, unsigned char y)

{

NOKIA5110_w_byte(0x40 | y, 0); // 列(竖)

NOKIA5110_w_byte(0x80 | x, 0); // 行(横)

}

//*********************************************************************

//写汉字到LCD

//*********************************************************************

void W_LCD_chinese(unsigned char X,unsigned char Y,unsigned char dat)

unsigned char i;

NOKIA5110_set_XY(X,Y);

for(i=0;i<16;i++) NOKIA5110_w_byte(hanzi[dat][i],1);

NOKIA5110_set_XY(X,Y+1);

for(i=16;i<32;i++)NOKIA5110_w_byte(hanzi[dat][i],1);

}

//*********************************************************************

//写字符到LCD5110

//*********************************************************************

void W_LCD_zifu(unsigned char X,unsigned char Y,unsigned char dat)

{

unsigned char i;

NOKIA5110_set_XY(X,Y);

for(i=0;i<8;i++) NOKIA5110_w_byte(zifu[dat][i],1);

NOKIA5110_set_XY(X,Y+1);

for(i=16;i<24;i++)NOKIA5110_w_byte(zifu[dat][i],1);

}

//**********************************************************************

//NOKIA5110_clear : LCD清屏

//**********************************************************************

void NOKIA5110_clear(void)

{

unsigned char t;

unsigned char k;

NOKIA5110_set_XY(0,0);

for(t=0;t<6;t++)

{

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

NOKIA5110_w_byte(0x00,1);

}

}

字库:

unsigned char code zifu[][32]=

{

{0xF0,0xF8,0x0C,0x04,0x0C,0xF8,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x07,0x0C,0x08,0x0C,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*以上为"0"的点阵*/

{0x00,0x10,0x18,0xFC,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x0F,0x0F,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*以上为"1"的点阵*/

{0x08,0x0C,0x84,0xC4,0x64,0x3C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x0F,0x09,0x08,0x08,0x0C,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*以上为"2"的点阵*/

{0x08,0x0C,0x44,0x44,0x44,0xFC,0xB8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*以上为"3"的点阵*/

{0xC0,0xE0,0xB0,0x98,0xFC,0xFC,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*以上为"4"的点阵*/

{0x00,0xF8,0x98,0x48,0x48,0x88,0x88,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x10,0x20,0x20,0x18,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*以上为"5"的点阵*/

{0x00,0xE0,0x30,0x88,0xC8,0x98,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x19,0x20,0x20,0x30,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*以上为"6"的点阵*/

{0x00,0x08,0x08,0x08,0x08,0xE8,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

{0x00,0x70,0xD8,0x08,0x08,0xD8,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x31,0x21,0x21,0x31,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*以上为"8"的点阵*/

{0x00,0xF0,0x18,0x08,0x08,0x18,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x33,0x22,0x22,0x19,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*以上为"9"的点阵*/

{0x80,0x80,0x00,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*10以上为"..."的点阵*/

{0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

/*11以上为":"的点阵*/

};

unsigned char code hanzi[][32]=

{

{0x00,0x08,0x08,0xC8,0x48,0x4A,0x4C,0xC8,0x08,0x08,0xCE,0x0A,0x08,0xE8,0x08,0x00,0x00,0x00,0x80,0xFF,0x09,0x09,0x49,0x7F,0x00,0x00,0x0F,0x40,0x40,0x7F,0x00,0x00},

/*0以上为"前"的点阵*/

{0x00,0x40,0x44,0xC8,0x00,0x10,0x10,0x10,0xFE,0x10,0x10,0xFE,0x10,0x10,0x10,0x00,0x00,0x60,0x20,0x3F,0x20,0x21,0x51,0x4F,0x41,0x41,0x41,0x5F,0x41,0x41,0x41,0x00},

/*1以上为"进"的点阵*/

{0x00,0x00,0x00,0xFC,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x26,0x26,0x24,0x20,0x00,0x00,0x20,0x3C,0x07,0x00,0x7E,0x22,0x22,0x22,0x22,0x22,0x22,0x7E,0x00,0x00,0x00},

/*2以上为"后"的点阵*/

{0x00,0x80,0x84,0x9C,0x00,0x00,0xFC,0x54,0x54,0x54,0x54,0x54,0x7C,0x7C,0x00,0x00,0x00,0x40,0x60,0x3F,0x20,0x20,0x5F,0x50,0x48,0x4B,0x42,0x44,0x4E,0x59,0x40,0x00},

/*3以上为"退"的点阵*/

{0x00,0x00,0x10,0x10,0x10,0x90,0x7C,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x10,0x10,0x0C,0x46,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00},

/*4以上为"左"的点阵*/

{0x00,0x88,0xE8,0x1E,0xCA,0x08,0x08,0x40,0x48,0xC8,0x7E,0x48,0x48,0x48,0x48,0x00,0x00,0x09,0x09,0x09,0x7F,0x09,0x05,0x00,0x10,0x13,0x22,0x72,0xCE,0x06,0x02,0x00},

{0x00,0x44,0x64,0xB4,0x94,0x84,0xFC,0x86,0x86,0xFC,0x84,0x84,0x94,0x24,0x44,0x00,0x00,0x00,0x00,0x0E,0x0A,0x0A,0x0A,0x0A,0x0A,0xCA,0x4A,0x4A,0x7B,0x18,0x00,0x00},

/*6以上为"弯"的点阵*/

{0x00,0x10,0x10,0x10,0x10,0x90,0x70,0x1E,0x12,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x08,0x08,0x04,0x43,0x7F,0x21,0x21,0x21,0x21,0x21,0x21,0x7F,0x00,0x00,0x00},

/*7以上为"右"的点阵*/

{0x00,0x00,0x08,0xC8,0xC8,0x08,0x08,0x08,0xF8,0x88,0x88,0x88,0x88,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x3F,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x00},

/*8以上为"正"的点阵*/

{0x00,0x00,0x08,0x08,0x88,0xE8,0x38,0x0E,0x08,0x08,0xE8,0x08,0x08,0x08,0x08,0x00,0x00,0x04,0x06,0x03,0x7F,0x20,0x21,0x21,0x21,0x21,0x3F,0x21,0x21,0x21,0x20,0x00},

/*9以上为"在"的点阵*/

{0x00,0x00,0x10,0x90,0xD6,0x30,0x80,0x80,0x08,0x08,0xF8,0x08,0x08,0x08,0xF8,0x00,0x00,0x06,0x03,0x01,0x7F,0x03,0x47,0x64,0x30,0x0E,0x03,0x40,0x60,0x7C,0x1F,0x00},

/*10以上为"初"的点阵*/

{0x00,0x10,0xD0,0x3E,0x12,0xF0,0x10,0x40,0x70,0x58,0x46,0x40,0x50,0x70,0x60,0x00,0x00,0x40,0x63,0x34,0x0E,0x1B,0x10,0x00,0x7E,0x22,0x22,0x22,0x22,0x7E,0x00,0x00},

/*11以上为"始"的点阵*/

{0x00,0x80,0xC0,0x30,0xFC,0x06,0x00,0x00,0x00,0xFE,0x80,0xC0,0x60,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x04,0x04,0x02,0x7F,0x41,0x40,0x40,0x60,0x30,0x00},

/*12以上为"化"的点阵*/

{0x00,0x20,0x10,0xF6,0x00,0x00,0x44,0x54,0x54,0x54,0x7E,0x54,0x54,0x54,0x44,0x00,0x00,0x00,0x00,0x7F,0x10,0x08,0x00,0xFF,0x15,0x15,0x15,0x15,0xD5,0x7F,0x00,0x00},

/*13以上为"请"的点阵*/

{0x00,0x40,0x44,0xFC,0xFC,0x46,0x40,0x04,0xD8,0x40,0x7E,0x42,0x50,0xC8,0x04,0x00,0x00,0x08,0x06,0x7F,0x7F,0x03,0x06,0x00,0xFF,0x09,0x09,0x09,0x49,0xFF,0x00,0x00},

/*14以上为"稍"的点阵*/

{0x00,0x00,0x38,0x08,0x68,0x48,0x48,0x4A,0x4E,0x48,0x48,0x68,0x08,0x38,0x00,0x00,0x00,0x40,0xC1,0x41,0x21,0x1D,0x07,0x01,0x01,0x7F,0x41,0x41,0x41,0x71,0x21,0x00},

/*15以上为"完"的点阵*/

{0x00,0x00,0x00,0xF0,0x90,0x90,0x90,0x10,0x10,0xFE,0x10,0x12,0xD6,0x10,0x10,0x00,0x00,0x40,0x78,0x0F,0x00,0x10,0x5F,0x40,0x60,0x37,0x1C,0x1F,0x61,0x40,0x60,0x00},

/*16以上为"成"的点阵*/

本文来源:https://www.bwwdw.com/article/p231.html

Top