Embedded Development Project-remote control vehicle design

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.