昨天想了一晚,发现程序里有问题,若是一帧出现问题,可能信号永远连不上
今天新写了一个Bate2,准备用手机为通讯,即手机的话筒和耳机。
现在把程序贴上来,延时 2500 是用开发板的LED与肉眼测试的,延时1000时看不出来,延时2500时能看出来闪烁。因为人眼对闪烁的分辨力比声音低,所以2500这个延时用手机应该能很容易,很有效的传输。对于延时2500是不是太长,到时候硬件齐全会进行测试。
/*
Remote control car
Remote transmitter
Thought Mobilephone (The whole world!)
Main Max Ping: 65
*/
#include<reg52.h>
sbit IN0 = P0^0;
sbit IN1 = P0^1;
sbit IN2 = P0^2;
sbit IN3 = P0^3; //2 motors for moving
sbit IN4 = P0^4;
sbit IN5 = P0^5;
sbit IN6 = P0^6;
sbit IN7 = P0^7; //2 motors for weapons
sbit LIGHT0 = P1^0;
sbit LIGHT1 = P1^1;
sbit LAMB = P1^2;
sbit SPEAKER = P1^3;
sbit LOCK0 = P1^4;
sbit LOCK1 = P1^5; //2 weapon locks
sbit FIRE = P1^6; // --WEAPON--
sbit OTHER = P1^7; //Other use (RELAY) ( decided by user )
sbit LED0 = P2^0; //All ready
sbit LED1 = P2^1; //C373 Locking
sbit LED2 = P2^2; //C373 unlocking
sbit LED3 = P2^3; //OUT
sbit LED4 = P2^4; //
sbit LED5 = P2^5; //LOCK0
sbit LED6 = P2^6; //LOCK1
sbit LED7 = P2^7; //Weapon uncloking //8 LED interface
sbit C373 = P3^6; //IC 74HC373
sbit OUT = P3^7; //OUT( Connect with mobilephone )
void main()
{
unsigned int i;
P0=0x00;
P1=0x00;
P2=0x00;
P3=0x00;
C373=0;
for(i=0;i<10000;i++);
LED0=1;
for(i=0;i<5000;i++);
LED1=1;
for(i=0;i<5000;i++);
LED2=1;
for(i=0;i<5000;i++);
LED3=1;
for(i=0;i<5000;i++);
LED4=1;
for(i=0;i<5000;i++);
LED5=1;
for(i=0;i<5000;i++);
LED6=1;
for(i=0;i<5000;i++);
LED7=1;
for(i=0;i<5000;i++);
P2=0x00;
for(i=0;i<2500;i++);
P2=0xff;
for(i=0;i<5000;i++);
P2=0x00;
for(i=0;i<2500;i++);
LED0=1;
for(i=0;i<10000;i++);
//All ready!
while(1)
{
//Begin!
OUT=LED3=1;
delay();
delay();
delay();
delay();
OUT=LED3=0;
delay();
OUT=LED3=IN0;
delay();
OUT=LED3=IN1;
delay();
OUT=LED3=IN2;
delay();
OUT=LED3=IN3;
delay();
OUT=LED3=IN4;
delay();
OUT=LED3=IN5;
delay();
OUT=LED3=IN6;
delay();
OUT=LED3=IN7;
delay();
OUT=LED3=LIGHT0;
delay();
OUT=LED3=LIGHT1;
delay();
OUT=LED3=LAMB;
delay();
OUT=LED3=SPEAKER;
delay();
OUT=LED3=LOCK0;
delay();
OUT=LED3=LOCK1;
delay();
OUT=LED3=FIRE;
delay();
OUT=LED3=OTHER;
delay();
OUT=LED3=0;
delay();
delay();
delay();
delay();
delay();
//End, return to "begin!".
}
}
//For delay (Decided on how fast the mobilephone can trans.)
//(Now, it is in testing.)
delay()
{
unsigned int s;
for(s=0;s<2500;s++);
}
/*
Remote control car
Remote-controlled receiver
Thought Mobilephone (The whole world!)
Main Max Ping: 65
*/
#include<reg52.h>
sbit MOTOR0 = P0^0;
sbit MOTOR1 = P0^1;
sbit MOTOR2 = P0^2;
sbit MOTOR3 = P0^3; //2 motors for moving
sbit MOTOR4 = P0^4;
sbit MOTOR5 = P0^5;
sbit MOTOR6 = P0^6;
sbit MOTOR7 = P0^7; //2 motors for weapons
sbit LIGHT0 = P1^0;
sbit LIGHT1 = P1^1;
sbit LAMB = P1^2;
sbit SPEAKER = P1^3;
sbit LOCK0 = P1^4;
sbit LOCK1 = P1^5; //2 weapon locks
sbit FIRE = P1^6; // --WEAPON--
sbit OTHER = P1^7; //Other use (RELAY) ( decided by user )
sbit WRONG = P2^0; //Interface ( if "IN" is wrong ).
sbit C373 = P3^6; //IC 74HC373 For balance
sbit IN = P3^7; //OUT( Connect with mobilephone )
void main()
{
unsigned int i;
//Begin
if(IN=1)
{
delay();
for(i=0;i<1250;i++);//Delay ( At 1/2 )
if(IN=1)
{
delay();
if(IN=1)
{
delay();
if(IN=1)
{
delay();
if(IN=0)
{
delay;
//All check!
//Star to get info
MOTOR0=IN;
delay();
MOTOR1=IN;
delay();
MOTOR2=IN;
delay();
MOTOR3=IN;
delay();
MOTOR4=IN;
delay();
MOTOR5=IN;
delay();
MOTOR6=IN;
delay();
MOTOR7=IN;
delay();
LIGHT0=IN;
delay();
LIGHT1=IN;
delay();
LAMB=IN;
delay();
SPEAKER=IN;
delay();
LOCK0=IN;
delay();
LOCK1=IN;
delay();
FIRE=IN;
delay();
OTHER=IN;
delay();
//End, return
}
else
{
WRONG=1;
for(i=0;i<500;i++);
WRONG=0;
}
}
else
{
WRONG=1;
for(i=0;i<500;i++);
WRONG=0;
}
}
else
{
WRONG=1;
for(i=0;i<500;i++);
WRONG=0;
}
}
else
{
WRONG=1;
for(i=0;i<500;i++);
WRONG=0;
}
}
else
{
WRONG=1;
for(i=0;i<500;i++);
WRONG=0;
}
//End, return to "Begin!".
}
//For delay (Decided on how fast the mobilephone can trans.)
//(Now, it is in testing.)
delay()
{
unsigned int s;
for(s=0;s<2500;s++);
}
|