求高手看下程序
时间:10-02
整理:3721RD
点击:
#include <stc12c5a.h>
#include "pwm.h"
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit l4=P0^0;
sbit l3=P0^1;
sbit l2=P0^2;
sbit l1=P0^3;
sbit r1=P0^4;
sbit r2=P0^5;
sbit r3=P0^6;
sbit r4=P0^7;
sbit s1 = P1 ^ 0;//无线键盘1 ++
sbit s2 = P1 ^ 1;//无线键盘2 ++
sbit s3 = P1 ^ 2;//无线键盘3 ++
sbit s4 = P1 ^ 3;//无线键盘4 ++
sbit sn = P1 ^ 4;//无线键盘N(中断) ++ 接VT脚
uchar keys;
void DELAY_MS (unsigned int a)
{
unsigned char i;
while( --a != 0)
{
for(i = 0; i < 600; i++);
}
}
//无线键值处理程序(扫描)
void key_init( )//键盘初始化程序//
{
keys = 0;
}
void key_rxd()//键盘处理程序//
{
key_init();
if(sn == 1)//查看是否有键被按下
{
DELAY_MS(10);//延时去干扰
if(sn == 1)
{
if(s1 == 1 && s2 == s3 == s4 == 0){keys = 1;}//查找键值并放入寄存器
if(s2 == 1 && s1 == s3 == s4 == 0){keys = 2;}
if(s3 == 1 && s1 == s2 == s4 == 0){keys = 3;}
if(s4 == 1 && s1 == s2 == s3 == 0){keys = 4;}
}
while(sn == 1);//按键是否松开
}
}
void main ()
{
PWM_init();
while(1)
{
key_rxd();
if(keys == 1)RUN(-50,-50);
if(keys == 2)RUN(50,50);
if(keys == 3)RUN(-50,50);
if(keys == 4)RUN(50,-50);
if (P0==0X10) //左1黑 0001 0000
{
RUN(105,85);
while(l1==1);
}
else if (P0==0X30) //左12黑 0011 0000
{
RUN(105,85);
while(l1==1);
}
else if (P0==0X20) //左2黑 0010 0000
{
RUN(130,75);
while(l2==1);
}
else if (P0==0X60) //左23黑 0110 0000
{
RUN(130,65);
while(l2==1);
}
else if (P0==0X40) //左3黑 0100 0000
{
RUN(150,75);
while(l3==1);
}
else if (P0==0XC0) //左34黑 1100 0000
{
RUN(150,75);
while(l3==1);
}
else if (P0==0X80) //左4黑 1000 0000
{
RUN(150,15);
while(l4==1);
}
else if (P0==0X08) //右1黑 0000 1000
{
RUN(85,105);
while(r1==1);
}
else if (P0==0X0C) //右12黑 0000 1100
{
RUN(85,105);
while(r1==1);
}
else if (P0==0X04) //右2黑 0000 0100
{
RUN(75,130);
while(r2==1);
}
else if (P0==0X06) //右23黑 0000 0110
{
RUN(65,130);
while(r2==1);
}
else if (P0==0X02) //右3黑 0000 0010
{
RUN(80,150);
while(r3==1);
}
else if (P0==0X03) //右34黑 0000 0011
{
RUN(75,150);
while(r3==1);
}
else if (P0==0X01) //右4黑 0000 0001
{
RUN(15,150);
while(r4==1);
}
else if(P0==0X00) // 0000 0000
{ RUN(80,80);
while(P0==0X00);
}
else if(P0==0XFF) // 1111 1111
{ RUN(-80,-80);
while(P0==0XFF);
}
}
}
这个错在哪了,怎么程序写进去之后车不动,遥控也没用
#include "pwm.h"
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit l4=P0^0;
sbit l3=P0^1;
sbit l2=P0^2;
sbit l1=P0^3;
sbit r1=P0^4;
sbit r2=P0^5;
sbit r3=P0^6;
sbit r4=P0^7;
sbit s1 = P1 ^ 0;//无线键盘1 ++
sbit s2 = P1 ^ 1;//无线键盘2 ++
sbit s3 = P1 ^ 2;//无线键盘3 ++
sbit s4 = P1 ^ 3;//无线键盘4 ++
sbit sn = P1 ^ 4;//无线键盘N(中断) ++ 接VT脚
uchar keys;
void DELAY_MS (unsigned int a)
{
unsigned char i;
while( --a != 0)
{
for(i = 0; i < 600; i++);
}
}
//无线键值处理程序(扫描)
void key_init( )//键盘初始化程序//
{
keys = 0;
}
void key_rxd()//键盘处理程序//
{
key_init();
if(sn == 1)//查看是否有键被按下
{
DELAY_MS(10);//延时去干扰
if(sn == 1)
{
if(s1 == 1 && s2 == s3 == s4 == 0){keys = 1;}//查找键值并放入寄存器
if(s2 == 1 && s1 == s3 == s4 == 0){keys = 2;}
if(s3 == 1 && s1 == s2 == s4 == 0){keys = 3;}
if(s4 == 1 && s1 == s2 == s3 == 0){keys = 4;}
}
while(sn == 1);//按键是否松开
}
}
void main ()
{
PWM_init();
while(1)
{
key_rxd();
if(keys == 1)RUN(-50,-50);
if(keys == 2)RUN(50,50);
if(keys == 3)RUN(-50,50);
if(keys == 4)RUN(50,-50);
if (P0==0X10) //左1黑 0001 0000
{
RUN(105,85);
while(l1==1);
}
else if (P0==0X30) //左12黑 0011 0000
{
RUN(105,85);
while(l1==1);
}
else if (P0==0X20) //左2黑 0010 0000
{
RUN(130,75);
while(l2==1);
}
else if (P0==0X60) //左23黑 0110 0000
{
RUN(130,65);
while(l2==1);
}
else if (P0==0X40) //左3黑 0100 0000
{
RUN(150,75);
while(l3==1);
}
else if (P0==0XC0) //左34黑 1100 0000
{
RUN(150,75);
while(l3==1);
}
else if (P0==0X80) //左4黑 1000 0000
{
RUN(150,15);
while(l4==1);
}
else if (P0==0X08) //右1黑 0000 1000
{
RUN(85,105);
while(r1==1);
}
else if (P0==0X0C) //右12黑 0000 1100
{
RUN(85,105);
while(r1==1);
}
else if (P0==0X04) //右2黑 0000 0100
{
RUN(75,130);
while(r2==1);
}
else if (P0==0X06) //右23黑 0000 0110
{
RUN(65,130);
while(r2==1);
}
else if (P0==0X02) //右3黑 0000 0010
{
RUN(80,150);
while(r3==1);
}
else if (P0==0X03) //右34黑 0000 0011
{
RUN(75,150);
while(r3==1);
}
else if (P0==0X01) //右4黑 0000 0001
{
RUN(15,150);
while(r4==1);
}
else if(P0==0X00) // 0000 0000
{ RUN(80,80);
while(P0==0X00);
}
else if(P0==0XFF) // 1111 1111
{ RUN(-80,-80);
while(P0==0XFF);
}
}
}
这个错在哪了,怎么程序写进去之后车不动,遥控也没用