A kind of method of remote control decoding
Technical field
The present invention relates to telecontrol engineering field, particularly relate to a kind of method of remote control decoding.
Background technology
At present, the method comparatively commonly used remote control decoding uses oscillograph to receive its waveform, carries out Decoding Analysis by its waveform.Need like this to have equipment oscillographic while, also need artificially to carry out rigorous analysis to the waveform on oscillograph, not only spend larger energy and manpower when decoded data is more especially, but also need to use high precision oscillograph, cost is high, and error is greatly, time-consuming.
Summary of the invention
The object of this invention is to provide a kind of method of remote control decoding, reduce costs, improve decoding accuracy rate, raise the efficiency.
Technical scheme of the present invention is a kind of method of remote control decoding, the hardware unit that the method adopts comprises infrared receiving tube, the MCU of described infrared receiving tube of being connected by resistance R2 and simultaneously connect the pull-up resistor R1 of described infrared receiving tube and resistance R2, and described method comprises the steps:
S1, add 5V voltage to pull-up resistor R1;
S2, press remote controller key, send infrared data in real time, described infrared receiving tube receives and detects infrared data in real time, obtains remote controller code;
After S3, MCU receive described remote controller code, by pin P
10generation negative edge interrupts, and meanwhile, the timer in described MCU starts timing, and described timer, when each negative edge interrupts, records the time of the point of interruption; After timing terminates, get the mistiming of often adjacent two negative edge points of interruption, then draw 0 and 1 in first code and numeric data code and numeric data code; And
S4, described MCU continue high level to be detected, and determine that remote control mode sends and terminate, decoding terminates.
Telepilot often presses primary key, pin P
10by detecting, can obtain a remote controller code, this remote controller code is divided into first code and numeric data code, and first code is front, and numeric data code, rear, has a lot of data bit in described numeric data code, and each data bit can only be 0 or 1; Telepilot often presses primary key, the pin P in receiving end MCU
10can produce at least 3 negative edges to interrupt, timer falls in each of the lower puts the time of record along break period.By getting the mistiming of often adjacent two negative edge points of interruption, the time span of first code can be calculated, the type of each data bit in numeric data code and the duration of each data bit, finally realizing complete decoding.Without the need to external demoder, MCU decodes voluntarily, reduces cost, improves decoding accuracy rate, increases work efficiency.
Further, described step S3 comprises the steps:
S301, pin P
10be set to negative edge interrupt mode, when not having button to press, pin P
10high level detected, when there being button to press, pin P
10start to produce negative edge to interrupt, and the level of saltus step detected, start timer timing simultaneously; Then, if do not have new negative edge to interrupt producing, pin P
10high level detected, if there is new negative edge to interrupt producing, the time of the second time point of interruption is deducted the time of the first time point of interruption by MCU, obtains the numerical value T of first code
s, then remove described count value T
s;
If S302 does not have new negative edge to interrupt producing, pin P
10high level detected; If there is new negative edge to interrupt producing, interrupts starting from third time negative edge, deduct the time of a front point of interruption with the time of a rear point of interruption, just draw the mistiming of the twice negative edge interruption in adjacent front and back, be i.e. the count value T of a data bit in numeric data code
n, n>=1, gets positive integer;
S303, by doing the mistiming that twice negative edge in adjacent front and back interrupts, drawing the count value of all data bit in described numeric data code, and determining that each data bit is 0 or 1; And
S304, as pin P
10after setting-up time, when not receiving new negative edge again, fall count value T clearly
n, timeing closing device, this end of decoding.
Further, the count value of all meter digitals in the numeric data code that MCU obtains is divided into data bit 0 and data bit 1, and what count value was larger is data bit 1, and what count value was less is data bit 0; The count value of data bit 1 meets formula:
A*0.9<= T
A<= A*1.1
In formula, A represents the setting value of data bit 1, T
arepresent the detected value of data bit 1;
The count value of data bit 0 meets formula:
B*0.9<= T
B<= B*1.1
In formula, B represents the setting value of data bit 0, T
brepresent the detected value of data bit 0.
Further, A is 2.24ms, B is 1.1ms.
Further, R
1for 4k Ω, R
2for 1k Ω.
Further, the setting-up time in step S304 is 100ms.
Beneficial effect: the technical program is without the need to external demoder, and MCU decodes voluntarily, reduces cost, improves decoding accuracy rate, increases work efficiency.
Accompanying drawing explanation
Fig. 1 is the workflow diagram of an embodiment of the present invention;
Fig. 2 is the annexation schematic diagram of the another kind of embodiment of the present invention;
Fig. 3 is the level signal figure of the another kind of embodiment of the present invention.
Embodiment
Below in conjunction with accompanying drawing, preferably embodiment of the present invention is described in further detail:
See Fig. 1 to 3, a kind of method of remote control decoding, the hardware unit that the method adopts comprises infrared receiving tube, the MCU of described infrared receiving tube of being connected by resistance R2 and simultaneously connect the pull-up resistor R1 of described infrared receiving tube and resistance R2, this pull-up resistor R
1resistance be 4k Ω, resistance R
2resistance be 1k Ω, described method comprises the steps:
S1, add 5V voltage to pull-up resistor R1;
S2, press remote controller key, send infrared data in real time, described infrared receiving tube receives and detects infrared data in real time, obtains remote controller code;
After S3, MCU receive described remote controller code, by pin P
10generation negative edge interrupts, and meanwhile, the timer in described MCU starts timing, and described timer, when each negative edge interrupts, records the time of the point of interruption; After timing terminates, get the mistiming of often adjacent two negative edge points of interruption, then draw 0 and 1 in first code and numeric data code and numeric data code; And
S4, described MCU continue high level to be detected, and determine that remote control mode sends and terminate, decoding terminates.
Telepilot often presses primary key, pin P
10by detecting, can obtain a remote controller code, this remote controller code is divided into first code and numeric data code, and first code is front, and numeric data code, rear, has a lot of data bit in described numeric data code, and each data bit can only be 0 or 1; Telepilot often presses primary key, the pin P in receiving end MCU
10can produce at least 3 negative edges to interrupt, timer falls in each of the lower puts the time of record along break period.By getting the mistiming of often adjacent two negative edge points of interruption, the time span of first code can be calculated, the type of each data bit in numeric data code and the duration of each data bit, finally realizing complete decoding.Without the need to external demoder, MCU decodes voluntarily, reduces cost, improves decoding accuracy rate, increases work efficiency.
See Fig. 1, described step S3 comprises the steps:
S301, pin P
10be set to negative edge interrupt mode, when not having button to press, pin P
10high level detected, when there being button to press, pin P
10start to produce negative edge to interrupt, and the level of saltus step detected, start timer timing simultaneously; Then, if do not have new negative edge to interrupt producing, pin P
10high level detected, if there is new negative edge to interrupt producing, the time of the second time point of interruption is deducted the time of the first time point of interruption by MCU, obtains the count value T of first code
s, then remove described count value T
s;
If S302 does not have new negative edge to interrupt producing, pin P
10high level detected; If there is new negative edge to interrupt producing, interrupts starting from third time negative edge, deduct the time of a front point of interruption with the time of a rear point of interruption, just draw the mistiming of the twice negative edge interruption in adjacent front and back, be i.e. the count value T of a data bit in numeric data code
n, n>=1, gets positive integer;
S303, by doing the mistiming that twice negative edge in adjacent front and back interrupts, drawing the count value of all data bit in described numeric data code, and determining that each data bit is 0 or 1; And
S304, as pin P
10after setting-up time, when not receiving new negative edge again, fall count value T clearly
n, timeing closing device, this end of decoding.
The count value of all meter digitals in the numeric data code that MCU obtains is divided into data bit 0 and data bit 1, and what count value was larger is data bit 1, and what count value was less is data bit 0; The count value of data bit 1 meets formula:
A*0.9<= T
A<= A*1.1
In formula, A represents the setting value of data bit 1, T
arepresent the detected value of data bit 1;
The count value of data bit 0 meets formula:
B*0.9<= T
B<= B*1.1
In formula, B represents the setting value of data bit 0, T
brepresent the detected value of data bit 0.
Preferably, A is 2.24ms, B is 1.1ms.
In specific implementation process, setting value and detected value see the following form:
|
A(ms) |
T
A(ms)
|
B(ms) |
T
B(ms)
|
First group of numerical value |
2.24 |
2.016 |
1.1 |
0.99 |
Second group of numerical value |
2.24 |
2.214 |
1.1 |
1.13 |
3rd group of numerical value |
2.24 |
2.333 |
1.1 |
1.24 |
4th group of numerical value |
2.24 |
2.464 |
1.1 |
1.21 |
Preferably, the setting-up time in step S304 is 100ms.
The present embodiment is without the need to external demoder, and MCU decodes voluntarily, reduces cost, improves decoding accuracy rate, increases work efficiency.
Above content is in conjunction with concrete preferred implementation further description made for the present invention, can not assert that specific embodiment of the invention is confined to these explanations.For general technical staff of the technical field of the invention, without departing from the inventive concept of the premise, some simple deduction or replace can also be made, all should be considered as belonging to protection scope of the present invention.