用703N刷的openwrt,路由器通过TTL连接51单片机,再由单片机连接L298N电机驱动板控制轮子。本人不懂C语言,只好在论坛上找了个代码: #include<reg52.h> #include<math.h> #define uchar unsigned char #define uint unsigned int uchar Buffer[4] = {0}; uint i,j; sbit LeftLight=P2^1; sbit RightLight=P2^2;
void Delay_1ms(uint i) { uchar x,j; for(j=0;j<i;j++) for(x=0;x<=148;x++); }
void Com_Int(void) interrupt 4 {
EA = 0; if(RI == 1) { Buffer[0] = SBUF - 48; RI = 0;
} EA = 1; }
void Com_Init(void) { TMOD = 0x20; PCON = 0x00; SCON = 0x50; TH1 = 0xFd; TL1 = 0xFd; TR1 = 1; ES = 1; EA = 1; }
void Moto_Forward() {
P1= 0x06;
Delay_1ms(100);
}
void Moto_Backward() {
P1= 0x05; Delay_1ms(100); }
void Moto_TurnLeft() { P1= 0x09; Delay_1ms(100); }
void Moto_TurnRight() { P1= 0x0A;
Delay_1ms(100); }
void Moto_Stop() {
P1= 0x00; Delay_1ms(100); }
void LightTurnOn() {
LeftLight=0; RightLight=0;
}
void LightTurnOff() {
LeftLight=1; RightLight=1;
} void main() { Delay_1ms(100); Com_Init();
while(1) { switch(Buffer[0]) { case 0: Moto_Stop(); break; case 1: Moto_Forward(); break; case 2: Moto_Backward(); break; case 3: Moto_TurnLeft(); break; case 4: Moto_TurnRight(); break; case 8: LightTurnOn(); break; case 9: LightTurnOff(); break; default:break; }
} }
但是不知道手机端的代码怎么设置,下面的是软件一装上就有的。
|