C Language Control Program:
# Include <reg52.h>
# Define uchar unsigned char
# Define uint unsigned int
// This variable is used to record the current operation status of the vehicle
Uint opchoice = 0;
// The secondary variable is used to control the vehicle speed.
Uint speed = 2;
// Forward
Sbit kf = P3 ^ 0;
// Return
Sbit kb = P3 ^ 1;
// Left turn
Sbit KL = P3 ^ 4;
// Turn right
Sbit Kr = P3 ^ 5;
// Latency subfunction
Void delayms (uint MS)
{
Uchar T;
While (MS --)
For (t = 0; t <120; t ++ );
}
// Move the car forward
Void forward ()
{
P2. = 100 * speed;
Delayms (10 );
P1 = 100 * speed;
P0 = 0x02;
}
// The car stops.
Void backward ()
{
P2 = 0;
Delayms (10 );
P1 = 0;
P0 = 0x04;
}
// Turn left
Void turnleft ()
{
P2. = 100 * speed;
Delayms (10 );
P1 = 50 * speed;
P0 = 0x08;
}
// Turn right on the trolley
Void turnright ()
{
P2 = 50 * speed;
Delayms (10 );
P1 = 100 * speed;
P0 = 0x10;
}
// Main program
Void main ()
{
P2 = 0;
Delayms (10 );
P1 = 0;
Ea = 1; // total interruptions allowed
It0 = 1; // edge trigger
Ex0 = 1; // allows int0 interruption
While (1)
{
// Start to check the status of KF, kb, KL, and kr after power-on.
If (kf = 0) opchoice = 1;
If (kb = 0) opchoice = 2;
If (KL = 0) opchoice = 3;
If (KR = 0) opchoice = 4;
Switch (opchoice)
{
Case 0: backward (); break;
Case 1: Forward (); break;
Case 2: backward (); break;
Case 3: turnleft (); break;
Case 4: turnright (); break;
Default :;
}
}
}
// Shift interruption
Void ex_int0 () interrupt 0
{
Speed = speed % 3 + 1;
// Opchoice = 0;
}
Infrared Control:
Problem:
1. When S is closed at position A, the circuit on the left emits infrared rays. After the circuit on the right detects the infrared rays, what is a single peak pulse at the out output end?
A pulse waveform of 38 kHz (ne555 or single-chip microcomputer) should be added at a. Only one pulse can be output by the infrared receiving module.
2. Are there any alternative devices for devices A and B?
You can buy any type of infrared emission tubes at location a and any type of integrated infrared receiver components at location B (38 kHz, capable of responding to continuous infrared carriers with three feet ), there are many electronic markets and the pin definitions may be different. Ask the buyer.
3. Can this circuit better implement the following functions?
Function Description: When the left button S is pressed, a single peak pulse can be obtained at the CPU, indicating that the left button S is pressed.
No, the key s must be connected to ne555.
Hardware circuit:
Http://blog.sina.com.cn/s/blog_70c2b7560100qskk.html
Embedded Development Project-remote control vehicle design