遥控智能小车程序
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
sbit left_b=P0^1;
sbit right_a=P0^2;
sbit right_b=P0^3;
//sbit P2_0= P2^3;
uchar rcvdata; //用来存放从串口接收到的数据
uchar flag=0; //表示有没有接收到数据
//uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80};
void Timer0Interrupt(void) interrupt 1
{
TH0 = (65535-10000)/256;
TL0 = (65535-10000)%256;
if(flag_la==1)
{left_a=~left_a;}
if(flag_lb==1)
{left_b=~left_b;}
if(flag_ra==1)
TL0 = (65535-10000)%256;//TH0 = (65536 - x)%256
EA = 1;//打开总中断
ET0 = 1;//打开定时器0中断
TR0 = 1;//定时器0中断标志位,设置为1即马上进入中断函数
//Timer0Interrupt(void)
}
void jin(){//第1种
left_a= 1;
left_b= 0;
right_a=1;
right_b=0;
flag_la=0;
flag_ra=0;
flag_lb=0;
flag_rb=0;
}
void tui()//第2种
{
left_a= 0;
left_b= 1;
right_a=0;
right_b=1;
flag_la=0;
flag_ra=0;
case '7': {zuotui();/*P0=table[7];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
case '8': {youtui();/*P0=table[8];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
}
}
}
}
// right_b=1;
flag_la=0;
flag_ra=0;
flag_lb=0;
flag_rb=1;
}
void zuo(){//第3种
left_a=0;
left_b=1;
right_a=1;
right_b=0;
flag_lb=0;
flag_rb=0;
flag_la=0;
flag_ra=0;
}
vBaidu Nhomakorabeaid you(){//第4种
left_a=1;
left_b=0;
right_a=0;
right_b=1;
flag_la=0;
flag_ra=0;
flag_lb=0;
flag_rb=0;
}
void main()
{
SM0=0;
SM1=1;
REN=1;
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
EA=1;
ES=1;
TR1=1;
遥控智能小车控制程序:
#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar flag_la=0,flag_lb=0;
uchar flag_ra=0,flag_rb=0;
sbit left_a=P0^0;
left_b=0;
//right_a=1;
right_b=0;
flag_la=0;
flag_ra=1;
flag_lb=0;
flag_rb=0;
}
void ting(){//第0种
left_a=0;
left_b=0;
right_a=0;
right_b=0;
flag_la=0;
flag_ra=0;
flag_lb=0;
flag_lb=0;
flag_rb=0;
}
void zuoqian(){//第5种
// left_a=1;
left_b=0;
right_a=1;
right_b=0;
flag_la=1;
flag_ra=0;
flag_lb=0;
flag_rb=0;
}
void youqian(){//第6种
left_a=1;
flag_rb=0;
}
void zuotui(){//第7种
left_a=0;
// left_b=1;
right_a=0;
right_b=1;
flag_la=0;
flag_ra=0;
flag_lb=1;
flag_rb=0;
}
void youtui(){//第8种
left_a=0;
left_b=1;
right_a=0;
{right_a=~right_a;}
if(flag_rb==1)
{right_b=~right_b;}
}
void comint() interrupt 4
{
RI=0;
flag=1;
rcvdata=SBUF;
}
case '4': {you();/*P0=table[4];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
case '5': {zuoqian();/*P0=table[5];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
case '6': {youqian();/*P0=table[6];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
case '1': {jin();/*P0=table[1];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
case '2': {tui();/*P0=table[2];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
case '3': {zuo();/*P0=table[3];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
void delay(uchar x)
{
uint i;
while(x--)
for(i=0;i<120;i++);
}
void Timer0_Init(void)
{
TMOD |= 0x01;//定时器工作在方式1(16自加定时器)
TH0 = (65535-10000)/256;//重新装填定时器数据,10ms后触发中断
Timer0_Init();
left_a=0;
left_b= 0;
right_a=0;
right_b=0;
while(1)
{
if(flag==1){
switch(rcvdata) {
case '0': {ting();/*P0=table[0];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
sbit right_a=P0^2;
sbit right_b=P0^3;
//sbit P2_0= P2^3;
uchar rcvdata; //用来存放从串口接收到的数据
uchar flag=0; //表示有没有接收到数据
//uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80};
void Timer0Interrupt(void) interrupt 1
{
TH0 = (65535-10000)/256;
TL0 = (65535-10000)%256;
if(flag_la==1)
{left_a=~left_a;}
if(flag_lb==1)
{left_b=~left_b;}
if(flag_ra==1)
TL0 = (65535-10000)%256;//TH0 = (65536 - x)%256
EA = 1;//打开总中断
ET0 = 1;//打开定时器0中断
TR0 = 1;//定时器0中断标志位,设置为1即马上进入中断函数
//Timer0Interrupt(void)
}
void jin(){//第1种
left_a= 1;
left_b= 0;
right_a=1;
right_b=0;
flag_la=0;
flag_ra=0;
flag_lb=0;
flag_rb=0;
}
void tui()//第2种
{
left_a= 0;
left_b= 1;
right_a=0;
right_b=1;
flag_la=0;
flag_ra=0;
case '7': {zuotui();/*P0=table[7];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
case '8': {youtui();/*P0=table[8];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
}
}
}
}
// right_b=1;
flag_la=0;
flag_ra=0;
flag_lb=0;
flag_rb=1;
}
void zuo(){//第3种
left_a=0;
left_b=1;
right_a=1;
right_b=0;
flag_lb=0;
flag_rb=0;
flag_la=0;
flag_ra=0;
}
vBaidu Nhomakorabeaid you(){//第4种
left_a=1;
left_b=0;
right_a=0;
right_b=1;
flag_la=0;
flag_ra=0;
flag_lb=0;
flag_rb=0;
}
void main()
{
SM0=0;
SM1=1;
REN=1;
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
EA=1;
ES=1;
TR1=1;
遥控智能小车控制程序:
#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar flag_la=0,flag_lb=0;
uchar flag_ra=0,flag_rb=0;
sbit left_a=P0^0;
left_b=0;
//right_a=1;
right_b=0;
flag_la=0;
flag_ra=1;
flag_lb=0;
flag_rb=0;
}
void ting(){//第0种
left_a=0;
left_b=0;
right_a=0;
right_b=0;
flag_la=0;
flag_ra=0;
flag_lb=0;
flag_lb=0;
flag_rb=0;
}
void zuoqian(){//第5种
// left_a=1;
left_b=0;
right_a=1;
right_b=0;
flag_la=1;
flag_ra=0;
flag_lb=0;
flag_rb=0;
}
void youqian(){//第6种
left_a=1;
flag_rb=0;
}
void zuotui(){//第7种
left_a=0;
// left_b=1;
right_a=0;
right_b=1;
flag_la=0;
flag_ra=0;
flag_lb=1;
flag_rb=0;
}
void youtui(){//第8种
left_a=0;
left_b=1;
right_a=0;
{right_a=~right_a;}
if(flag_rb==1)
{right_b=~right_b;}
}
void comint() interrupt 4
{
RI=0;
flag=1;
rcvdata=SBUF;
}
case '4': {you();/*P0=table[4];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
case '5': {zuoqian();/*P0=table[5];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
case '6': {youqian();/*P0=table[6];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
case '1': {jin();/*P0=table[1];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
case '2': {tui();/*P0=table[2];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
case '3': {zuo();/*P0=table[3];P2_0 = 0;delay(200);P2_0 = 1;*/};break;
void delay(uchar x)
{
uint i;
while(x--)
for(i=0;i<120;i++);
}
void Timer0_Init(void)
{
TMOD |= 0x01;//定时器工作在方式1(16自加定时器)
TH0 = (65535-10000)/256;//重新装填定时器数据,10ms后触发中断
Timer0_Init();
left_a=0;
left_b= 0;
right_a=0;
right_b=0;
while(1)
{
if(flag==1){
switch(rcvdata) {
case '0': {ting();/*P0=table[0];P2_0 = 0;delay(200);P2_0 = 1;*/};break;