How to use PIC as infrared remote control receiver? (Part 2)

Publisher:平安守护Latest update time:2015-01-20 Source: laoguKeywords:PIC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
There are three methods that are commonly used for infrared reception.

1. Query method, that is, the software keeps querying whether it is low (remote control signal) and then reads the header code and
data 0 or 1 code through precise delay.
2. When a signal input is read, turn on the timer counter, and then judge the header code and 0, 1 by reading the number of timer interrupts.
3 RB0 or ​​RB4-RB7 plus timer (or software delay) The advantage of using input interrupts is that real-time control can be performed.

As follows:
;***The transmission is 6221, and the received code value is sent to the PORTC port of ICD for display******
;**************** ***************
         org 0000h
         nop
         goto start
         org 0004h
         goto serv
;******************************************************
start
         bsf status,rp0 ;body 1
         movlw 0000h
         movwf trisc ;C port output
         movlw 0ffh ;B port RB0 input
         movwf trisb
         movlw B''00000100'' ;1:64
         movwf option_reg ;TMR0 timer
         bcf status,rp0 ;body 0
         clrf intcon ;10010000
         bsf intcon,7 ;Open INT falling edge interrupt
         bsf intcon,4
         bcf intcon,1
         clrf portc
loop    
         sleep
         nop
         goto loop
;****************Scene protection********************************
serv     
         movwf w_temp
         swapf status,0      
         clrf status        
         movwf status_temp   
         movf pclath,0
         movwf pclath_temp
         clrf pclath
   
;***************Remote control processing.******************************

         bcf intcon,1
         btfsc portb,0 ;Check if RB0 is 0.
         goto zdhh ;RB0 is not 0, wrong interrupt. Return to
         call delay8 ;Call 8MS delay. Header code detection.
         btfsc portb,0 ;Detect header code
         goto zdhh ;Not interrupt and return to
         call delay5 ;Delay 5MS before data detection.
         btfss portb,0 ;Detect if RB0 is high level.
         goto zdhh ;Not continue detection.
;********************************************
       
         clrf data1 ;20H
         clrf data2 ;21H
         clrf data3 ;22H
         clrf data4 ;24H
         clrf jsp2 ;32-bit counter
         clrf sj ;Received data register
         clrf jsp1 ;8-bit counter
         movlw 0x20 ;20H register to W
         movwf fsr ;Send 20H from W to FSR
jc btfsc portb,0 ;Detect if RB0 is low level.
         goto jc ;Not continue detection.
;**************0 and 1 data detection********************************      
js call delay1 ;delay 1.3MS
         btfsc portb,0 ;check whether it is 0 or 1 after the header code,
         goto s1 ;check data is not "1"
;*************0 data processing****************************
         bcf sj,c ;data is "0"
         rrf sj,1 ;0 data right shift to SJ register
         goto j1
;**************1 data processing.****************************
s1 bsf sj,c
         rrf sj,1
ddp btfsc portb,0
         goto ddp
;**************RAM shift***************************
j1 incf jsp1 ;8-bit counting register
         incf jsp2 ;32-bit number, counter register.
         btfss jsp1,3 ;whether there is 8-bit
         goto js
         clrf jsp1
         movf sj,0 ;shift 8-bit number to W
         movwf indf ;W to DATA
         incf fsr ;RAM address plus 1
         clrf sj
;********************************
         btfss jsp2,5 ;Check whether 32 bits are received.
         goto js ;If not, check again.
         movlw B''10001111'' ;Send IC high 8-bit code
         xorwf data1,0 ;Subtraction (Z:1=result is 0;0=result is not 0)
         btfss status,2 ;If the result is 0, go to the next step.
         goto zdhh ;If the subtraction result is not 0, interrupt and return
          movlw B''101010101'' ;Low 8-bit IC code detection
          xorwf data2,0
         btfss status,2
          goto zdhh
         ;comf data4,0 ;Data inverse code detection. Not used for the time being.
         ;subwf data3,0
         ;btfss status,2
         ;goto zdhh
         movf data3,0 ;Send digital data to port C
         movwf portc
          goto zdhh ;Return from interrupt after receiving 32 bits
;****************zdhh interrupt return procedure*********************
zdhh   
         movf pclath_temp,0
         movwf pclath
         swapf status_temp,0 ;Swap the contents of STATUS and W, and restore the body selection.
         movwf status ;Send the contents of W to the STATUS register
         swapf w_temp,1 ;Swap w_temp
         swapf w_temp,0 ;Swap the contents of w_temp and w, and restore the contents of w_temp?       
         bcf intcon,1
         retfie ;Return from interrupt,

;****************8ms************************************
delay8 bcf intcon,5
         bcf intcon,2
         movlw D''15''
         movwf tmr0
loop1 btfss intcon,2
         goto loop1
           return
;****************5ms********************************
delay5 bcf intcon,5
         bcf intcon,2
         movlw D''120''
         movwf tmr0
loop2 btfss intcon,2
         goto loop2
           return
;****************1.3ms*******************************
delay1 bcf intcon,5
         bcf intcon,2
         movlw D''240''
         movwf tmr0
loop3 btfss intcon,2
         goto loop3
         return
;****************
          end



  There are two possible error codes.
One is that the header is not aligned properly.
The other is that there is an error in data transmission, especially a timing error. The
latter can
be verified by software. If the header is not aligned properly, it is best to send several consecutive sub-headers according to the software regulations and then use the shift method to determine whether there are multiple consecutive identical sub-headers. Align the headers. For example, 20 consecutive 1 0s are converted to indicate that data is ready to be sent and then wait for 1 0. After the transmission is completed, there is a header such as 11110000. In this way, data can be received later.
 
A I bought a universal remote control outside. It is made of pic16c57c, which means it has no interrupt. I really don't understand how it is made. It has no decoding chip. Does anyone know? I am also working on this. Can anyone give me some tips? Thank you.

B This is very easy. 
Last time I used two PIC16C57C chips to make a small module for transmission and reception. It is effective control and no garbled code appears. However, there is a disadvantage that it will be interfered by other infrared products! ! 

C Infrared reception 
uses external interrupts and timing to detect the code, which is very accurate. I use PIC16F72 chip. 


D I use an infrared receiving tube with two-stage amplification to see the infrared output waveform. I use a Changhong remote control as the signal source. On the oscilloscope, I have to hit 10ms to see the complete signal waveform, like a waveform after voltage stabilization. I read a book about it and it says that the infrared signal is modulated on a 38khz signal. Why can't I see the waveform when I hit the oscilloscope on 50ns? In this case, there is no way to program. I hope some experts can help me. Thank you. 


E You can use the input capture function in CCP. It is very useful. Read the relevant content of input capture carefully. It is very easy.
If an event occurs on the CCP pin (can be set to rising edge, falling edge or other methods), the content of TMR1 is recorded. This is very accurate. Even if the interrupt response is slow, there is no problem. This function is the most appropriate for infrared remote control! !

F Reply to the principle of infrared timing reception. 
Use RB0 as interrupt (FIRST: RISING TRIG, SECOND: FALLING TRIG), and start TIMER2 timing (100US) counting at the same time. When the next interrupt comes, TIMER2 has 88 numbers, and 9MS is detected. The rest of the time,
and so on. Note that the interrupt edge of RBO should be changed according to the timing. Based on this principle, it is easy to compile the code.
There is another point worth noting; the attenuation of infrared signals is very strong, so you must consider the choice of its acceptance range. 
In fact, any method can be used. Leave enough margin in time when receiving data, which is good for correct data reception. 
Keywords:PIC Reference address:How to use PIC as infrared remote control receiver? (Part 2)

Previous article:How to use PIC as infrared remote control receiver? (I)
Next article:How to use PIC as infrared remote control receiver? (Part 3)

Recommended ReadingLatest update time:2024-11-15 11:36

PIC18F45K80 CAN communication example, can be debugged by simulation
PIC18F 45K80 CAN communication example, can be debugged through simulation, pay attention to the selection of compiler, C18 cannot pass. The microcontroller source program is as follows: #pragma config XINST = OFF // CONFIG1L #pragma config FOSC = INTIO2, FCMEN = OFF, IESO = OFF ,PLLCFG = OFF // CONFIG1H #pragma conf
[Microcontroller]
PIC timer1 timer
Function: Use Timer1 to delay the LED light to flash in a cycle Requirements: MPLAB 8.2 or above, a MEO engineering board, PIC16-MCD2 simulation download, Chip configuration word, watchdog off, power-on delay on, power-off detection off, low voltage programming off, 4MXT mode oscillation  */ #include pic18.h int mai
[Microcontroller]
Conversion between floating point and decimal numbers in PIC microcontroller
We used PIC series microcontrollers in the instrument we designed, and encountered the problem of floating point calculation. After consulting the relevant information, we found that the format of its floating point number and the conversion between it and decimal number are completely different from the three-byte and
[Microcontroller]
Conversion between floating point and decimal numbers in PIC microcontroller
PIC32 interrupt and oscillator configuration
A month has passed since the summer vacation. I am enjoying the sweat and passion in the busy cornfield. However, I still haven't fallen behind in my studies. Taking advantage of the rare network access, I have summarized my notes for this month. 1. Interrupt settings step: 1.    Set the peripheral interrupt prio
[Microcontroller]
PIC32 interrupt and oscillator configuration
Design of PIC microcontroller controlling the programmer circuit
Someone asked: Can IC burning also be used as a tutorial? Kimura Dou Momoya is thinking... Using the LEAPER-48 multi-purpose programmer 1. Pull your hand down 2. Put the IC on 3. Close the handle 4. Select IC brand/number 5. Load HEX file 6. Press Burn 7. Just wait for the PASS to appear Why teach??? So, what shou
[Microcontroller]
Design of PIC microcontroller controlling the programmer circuit
PIC 18f45k80 microcontroller watchdog program
#pragma config WDTPS = 512 // Watchdog reset time 2.048s void main(void) {     while(1)     {         ClrWdt(); // Feed the dog     } }
[Microcontroller]
Design of embedded smart home system based on PIC32
    Preface     Imagine: in the scorching summer or the freezing winter, when you are on your way home tired after a long day of work, the air conditioner has been turned on and adjusted to a comfortable temperature, soft music has been played for you, the ventilation device has been turned on, the indoor light has be
[Microcontroller]
Design of embedded smart home system based on PIC32
PIC16F877A drives 12864 LCD
This program is equipped with Jinpeng's 12864 LCD using serial mode head File #ifndef LCD12864_H #define LCD12864_H #include  "main.h" //define control port pin //serial mode //#define SCLK RD4  //#define STD RD5 //#define LCD_EN RD6  //parallel mode #define PSB RA0 #define CS RA1  #define STD RA2 #defi
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号