基于单片机的红外遥控小车系统设计.doc
《基于单片机的红外遥控小车系统设计.doc》由会员分享,可在线阅读,更多相关《基于单片机的红外遥控小车系统设计.doc(30页珍藏版)》请在冰豆网上搜索。
红外接收与控件电路原理图:
141
红外遥控器原理图:
红外遥控器实物图:
红外接收与控制实物图:
程序:
接收控制主程序:
#include
#include"hongwai.c"
#include"5110.c"
sbithy=P0^0;//LED指示灯
sbithz=P2^0;
sbitqy=P1^4;
sbitqz=P3^7;
sbitdjf1=P1^0;//电机1的方向控制
sbitdjd1=P1^1;//电机1的动力控制
sbitdjf2=P1^2;//电机2的方向控制
sbitdjd2=P1^3;//电机2的动力控制
unsignedcharflag,flag1,PW;
bitfan,fan1,tf=0;
unsignedcharfafg=0;
unsignedchartime_flag;
unsignedchardatatime[2];
//=====================================
//ms延时
voiddelayms(unsignedintms)
{
unsignedchari;
while(ms--)
for(i=0;i<120;i++);
}
//LED灯闪烁
voidLED(unsignedcharms)
for(i=0;i { delayms(200); qz=~qz; qy=~qy; hz=~hz; hy=~hy; }}//======================================//控制//=====================================voidkongzi(void){ switch(shu[2]) { case0x20:{//前进 fafg=1; qz=qy=0; hz=hy=1; TR1=ET1=1; djd1=djd2=1; djf1=djf2=0; fan=0; break; } case0x30:{//后退 fafg=2; qz=qy=1; hz=hy=0; TR1=ET1=1; djd1=djd2=1; djf1=djf2=1; fan=1; break; } case0x40:{//前左转弯 fafg=3; djf1=djf2=0; qz=0; qy=hz=hy=1; djd1=1; djd2=0; fan1=0; TR1=ET1=1; break; } case0x60: {//后左转弯 fafg=4; djf1=djf2=1; hz=0; hy=qz=qy=1; djd1=1; djd2=0; fan1=0; TR1=ET1=1; break; } case0x50:{//前右转弯 fafg=5; djf1=djf2=0; qy=0; qz=hy=hz=1; djd1=0; djd2=1; fan1=1; TR1=ET1=1; break; } case0x70: {//后退 fafg=6; djf1=djf2=1; hy=0; hz=qz=qy=1; djd1=0; djd2=1; fan1=1; TR1=ET1=1; break; } case0x80:{ 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; } }}//***********************************************//显示//************************************************voidLCD_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//=====================================voidwan_T1(void)interrupt3{ 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; } }}//==================================
delayms(200);
qz=~qz;
qy=~qy;
hz=~hz;
hy=~hy;
//======================================
//控制
voidkongzi(void)
switch(shu[2])
case0x20:
{//前进
fafg=1;
qz=qy=0;
hz=hy=1;
TR1=ET1=1;
djd1=djd2=1;
djf1=djf2=0;
fan=0;
break;
case0x30:
{//后退
fafg=2;
qz=qy=1;
hz=hy=0;
djf1=djf2=1;
fan=1;
case0x40:
{//前左转弯
fafg=3;
qz=0;
qy=hz=hy=1;
djd1=1;
djd2=0;
fan1=0;
case0x60:
{//后左转弯
fafg=4;
hz=0;
hy=qz=qy=1;
case0x50:
{//前右转弯
fafg=5;
qy=0;
qz=hy=hz=1;
djd1=0;
djd2=1;
fan1=1;
case0x70:
fafg=6;
hy=0;
hz=qz=qy=1;
case0x80:
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;
//***********************************************
//显示
//************************************************
voidLCD_display(void)
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);//后
if(fafg==5)
W_LCD_chinese(25,0,7);//右
if(fafg==6)
//定时器T1
voidwan_T1(void)interrupt3
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;
//==================================
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1