Decoding program for infrared coding chips such as AVR microcontroller uPD6121/AS6122

Publisher:神光骑士Latest update time:2017-12-13 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include 

#define uchar unsigned char    
#define ulong unsigned long  
/*------------------------------Display-----------------------------------*/  
#define  LED _DATA PORTB  
const uchar tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};  
/*  
                     0 1 2 3 4 5 6 7 8 9 A B C D E F      
*/  
void delay(void){  
    uint i;  
    for(i=0;i<2000;i++);  
}  
void dis_int(uint dis_data)  
{ //Four-digit common cathode digital tube , hexadecimal display  
     LED_DATA=tab[(uchar)((dis_data&0xf000)>>12)]; //Display thousands digit  
     PORTD=0xf7;                  
     delay(); //Delay  
    
     LED_DATA=tab[(uchar)((dis_data&0x0f00)>>8)]; //Display hundreds digit  
     PORTD=0xfb;   
     delay(); //Delay  
                            
     LED_DATA=tab[(uchar)(dis_data&0x00f0)>>4]; //Display tens digit  
     PORTD=0xfd;  
     delay(); //Delay  
       
     LED_DATA=tab[(uchar)dis_data&0x000f]; //Display ones digit  
     PORTD=0xfe;  
     delay(); //Delay   
}  
void port_init(void)  
{  
 PORTA = 0xFF;  
 DDRA = 0x00;  
 PORTB = 0xFF;  
 DDRB = 0xFF;  
 PORTC = 0xFF;   
 DDRC = 0xFF;  
 PORTD = 0xFF;  
 DDRD = 0x0F;  
}  
void timer1_init(void)  
{  
 T CC R1B = 0x00; //stop  
 TCNT1H = 0x00; //setup  
 TCNT1L = 0x00;  
 IC R1H = 0x00;  
 ICR1L = 0x08;  
 TCCR1A = 0x00;  
/*Connect the DATA pin of the integrated receiver to the PD6 (ICP1) pin of ATmega16, and decode by rising edge capture*/  
/* The crystal oscillator is 6M, without frequency division , and 8M is too large (the frequency division is too small)*/  
 TCCR1B = 0x41; //start Timer  
}  
uint arr[16];//Save the capture value  
uchar times;//Record the number of captures  
uchar index;//Array index  
uchar ir_code;//Infrared remote control key code  
uchar OK_flag;//Decoding completed flag  
/*------------------------------------------------------------------------------  
Module Name: PD6 (ICP1) pin rising edge capture interrupt program  
impact: Store captured value in arr[16]  
    ___ ___  
   | | | |  
___| |_________| |__________  
   |


//------------------------------------------------

Use M64, T3, crystal 7.3728, GCC 20040214


void timer1_init(void)  
{  
 TCCR3B = 0x00; //stop  
 TCNT3H = 0x00; //setup  
 TCNT3L = 0x00;  
 ICR3H = 0x00;  
 ICR3L = 0x08;  
 TCCR3A = 0x00;  
/*Connect the DATA pin of the integrated receiver to the PE7 (ICP3) pin of ATmega64, and use the rising edge capture method to decode*/  
/*The crystal oscillator is 7.3728M, divided by 8*/  
 TCCR1B = 0xC2; //start Timer @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@change 
}  
2


SING(XXXXXXXXXXXXXXX) 
{     
    uint value;  
    value=ICR3L;                     
    value|=(uint)(ICR3H << 8);   
    TCNT3H = 0x00;   
    TCNT3L = 0x00;   
    times++;    
    if(times>18)&&(times<35){  
      //Save from the 19th rising edge to the 34th, there are 36 rising edges when short pressing  
      arr[index]=value;     
      index++;    
    }  
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@changeelse 
  if(times>35)@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@change

 //else if(times>=35) //When this statement is used, the first bit of the second key value is reused by the 36th pulse of the previous key value, 
{  
        //When the 35th rising edge arrives, decoding is completed    
       times=0;  
       index=0;  
       OK_flag=1;  
    }  
}  


Reference address:Decoding program for infrared coding chips such as AVR microcontroller uPD6121/AS6122

Previous article:AVR dual CPU communication program (asynchronous mode) UART
Next article:ATMEGA88 analog serial port program

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号