Infrared remote control to send data, binary data is modulated into a series of pulses emitted infrared emission control, IR carrier frequency 38KHz square wave, infrared receiver receives the carrier signal at the end of 38KHz, it will output low, Otherwise, high output, thereby "intermittent" infrared light signals can be demodulated into a continuous square wave signal certain cycle, and then after 1838 demodulation integrated infrared receiver can recover the original data signal. As shown in Figure 1
Figure 1
Infrared receiver demodulation process is shown in Figure 2
Figure 2
The demodulated, "0" and "1" and the waveform encoding the microcontroller 3, as shown in Figure 4
Figure 3
Figure 4
Figure 5
Understanding of the remote control infrared receiver demodulation and coding can be controlled below 5 write coding procedures, and Figure 5 is a section of the actual encoding a remote control button, and by the high level of 9ms low 4.5ms start code, 26 systems yards, and eight data code, 8 data inverted, 23ms high and end code components.
Circuit
Physical map
he following is a complete program remote ******** ********
/ ********
* Project: homemade infrared TV remote control (EE01 learning board demo)
* Author: frontline workers
* Website: Electronics Engineers House www.eehome.cn
** Please maintain the integrity of the code posted
******** /
#include "reg52.h"
#define uint unsigned int
#define uchar unsigned char
bit irout; // infrared tube status
sbit ir = P1 ^ 7; // infrared emission control pin
uint count, set_count; // interrupt count, set the interrupt number
bit flag, keyflag; // infrared transmitter flag button flag
uchar irsys [4] = {0x1a, 0xa1,0xdc, 0x03}; // 26-bit system code, the last byte of only two
uchar ircode, irdata;
/ **********************************************
Delay 1ms
*********************************************** /
void delay (uint z) // delay 1ms, crystal 22.1184M
{
uint x, y;
for (x = z; x "0; x--)
for (y = 225; y "0; y--);
}
/ **********************************************
Key scan
********************************************** /
void keyscan (void)
{
uchar keytemp;
P3 = 0xff;
keytemp = P3 & 0x0f;
if (keytemp! = 0x0f)
{
delay (20);
keytemp = P3 & 0x0f;
if (keytemp! = 0x0f)
keyflag = 1; // with keys logo
switch (keytemp)
{
case 0x0e: irdata = 27; // button one pair should P + remote control keys; break
case 0x0d: irdata = 26; break; // remote control button two pairs should P- keys
case 0x0b: irdata = 31; break; // button three pairs should VOL + keys on the remote control
case 0x07: irdata = 30; // remote control button should VOL- keys four pairs; break
}
}
}
/ *******************************************
Send eight infrared data
******************************************* /
void sendcode_8 (void)
{
uchar i;
for (i = 0; i "8; i ++)
{
set_count = 28; // send 0.56ms 38k infrared waves (encoding 0.56ms low)
flag = 1;
count = 0;
TR0 = 1;
while (count "set_count);
TR0 = 0;
if (ircode & 0x01) // judge infrared encoder lowest position, a wide high, narrow high 0
{
set_count = 120;
}
else
{
set_count = 38;
}
flag = 0;
count = 0;
TR0 = 1;
while (count "set_count);
TR0 = 0;
ircode = ircode "" 1;
}
}
/ *******************************************
Send two infrared data
******************************************* /
void sendcode_2 (void) // system before 26 yards last two
{
uchar i;
for (i = 0; i "2; i ++)
{
set_count = 28;
flag = 1;
count = 0;
TR0 = 1;
while (count "set_count);
TR0 = 0;
if (ircode & 0x01)
{
set_count = 120;
}
else
{
set_count = 38;
}
flag = 0;
count = 0;
TR0 = 1;
while (count "set_count);
TR0 = 0;
ircode = ircode "" 1;
}
}
/ *******************************************
Send infrared data
******************************************* /
void sendcode (void)
{
set_count = 575; // infrared light to send 9ms 38K
flag = 1;
count = 0;
TR0 = 1;
while (count "set_count);
TR0 = 0;
set_count = 320; // interval 4.5ms
flag = 0;
count = 0;
TR0 = 1;
while (count "set_count);
TR0 = 0;
ircode = irsys [0]; // before the 26-bit transmission system code 1-8
sendcode_8 ();
ircode = irsys [1]; // before the 26-bit transmission system code 9-16
sendcode_8 ();
ircode = irsys [2]; // before the 26-bit transmission system code 17-24
sendcode_8 ();
ircode = irsys [3]; // before the 26-bit transmission system code 24-26
sendcode_2 ();
ircode = irdata; // send eight data code
sendcode_8 ();
ircode = ~ irdata; // send eight data inverted
sendcode_8 ();
set_count = 28; // send 0.56ms 38k infrared waves (encoding 0.56ms low)
flag = 1;
count = 0;
TR0 = 1;
while (count "set_count);
TR0 = 0;
ir = 1;
delay (23); // delay of 23ms (23ms high coding)
set_count = 575; // send 9ms 38k infrared waves
flag = 1;
count = 0;
TR0 = 1;
while (count "set_count);
TR0 = 0;
set_count = 330; // interval 4.5ms
flag = 0;
count = 0;
TR0 = 1;
while (count "set_count);
TR0 = 0;
set_count = 30; // send 0.56ms 38k infrared waves (encoding 0.56ms low)
flag = 1;
count = 0;
TR0 = 1;
while (count "set_count);
TR0 = 0;
ir = 1;
}
/ *******************************************
Timer initialization
******************************************* /
void init_timer ()
{
EA = 1;
TMOD = 0X02; // 8-bit auto-reload mode
ET0 = 1;
TH0 = 0XE8; // timing 13us, 38K infrared waves, crystal 22.1184
TL0 = 0XE8;
}
/ *******************************************
The main function
******************************************* /
void main (void)
{
init_timer ();
count = 0;
flag = 0;
irout = 1;
while (1)
{
keyscan ();
if (keyflag) // if new keys
{
delay (10);
sendcode (); // send IR codes
delay (500);
keyflag = 0; // button flag is cleared
}
}
}
/ *******************************************
Timer interrupt
******************************************* /
void timer0 (void) interrupt 1
{
count ++;
if (flag == 1)
{
irout = ~ irout;
}
else
{
irout = 1;
}
ir = irout;
}
************************************************** *************************************************
No comments:
Post a Comment
Please comment