⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a.i

📁 51下的红外解码源程序
💻 I
字号:
/*****************************************************
Project : 
Version : 
Date    : 2007-5-31
Author  : Cheung                          
Company : hhuc                            
Comments: 

Chip type           : ATmega16L
Program type        : Application
Clock frequency     : 1.000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/
// CodeVisionAVR C Compiler
// (C) 1998-2001 Pavel Haiduc, HP InfoTech S.R.L.

// I/O registers definitions for the ATmega16


#pragma used+
sfrb TWBR=0;
sfrb TWSR=1;
sfrb TWAR=2;
sfrb TWDR=3;
sfrb ADCL=4;
sfrb ADCH=5;
sfrw ADCW=4;      // 16 bit access
sfrb ADCSRA=6;
sfrb ADMUX=7;
sfrb ACSR=8;
sfrb UBRRL=9;
sfrb UCSRB=0xa;
sfrb UCSRA=0xb;
sfrb UDR=0xc;
sfrb SPCR=0xd;
sfrb SPSR=0xe;
sfrb SPDR=0xf;
sfrb PIND=0x10;
sfrb DDRD=0x11;
sfrb PORTD=0x12;
sfrb PINC=0x13;
sfrb DDRC=0x14;
sfrb PORTC=0x15;
sfrb PINB=0x16;
sfrb DDRB=0x17;
sfrb PORTB=0x18;
sfrb PINA=0x19;
sfrb DDRA=0x1a;
sfrb PORTA=0x1b;
sfrb EECR=0x1c;
sfrb EEDR=0x1d;
sfrb EEARL=0x1e;
sfrb EEARH=0x1f;
sfrw EEAR=0x1e;   // 16 bit access
sfrb UBRRH=0x20;
sfrb UCSRC=0X20;
sfrb WDTCR=0x21;
sfrb ASSR=0x22;
sfrb OCR2=0x23;
sfrb TCNT2=0x24;
sfrb TCCR2=0x25;
sfrb ICR1L=0x26;
sfrb ICR1H=0x27;
sfrb OCR1BL=0x28;
sfrb OCR1BH=0x29;
sfrw OCR1B=0x28;  // 16 bit access
sfrb OCR1AL=0x2a;
sfrb OCR1AH=0x2b;
sfrw OCR1A=0x2a;  // 16 bit access
sfrb TCNT1L=0x2c;
sfrb TCNT1H=0x2d;
sfrw TCNT1=0x2c;  // 16 bit access
sfrb TCCR1B=0x2e;
sfrb TCCR1A=0x2f;
sfrb SFIOR=0x30;
sfrb OSCCAL=0x31;
sfrb OCDR=0x31;
sfrb TCNT0=0x32;
sfrb TCCR0=0x33;
sfrb MCUCSR=0x34;
sfrb MCUCR=0x35;
sfrb TWCR=0x36;
sfrb SPMCR=0x37;
sfrb TIFR=0x38;
sfrb TIMSK=0x39;
sfrb GIFR=0x3a;
sfrb GICR=0x3b;
sfrb OCR0=0X3c;
sfrb SPL=0x3d;
sfrb SPH=0x3e;
sfrb SREG=0x3f;
#pragma used-

// Interrupt vectors definitions



/* CodeVisionAVR C Compiler
   Prototypes for standard library functions

   (C) 1998-2003 Pavel Haiduc, HP InfoTech S.R.L.
*/




#pragma used+

int atoi(char *str);
long int atol(char *str);
float atof(char *str);
void itoa(int n,char *str);
void ltoa(long int n,char *str);
void ftoa(float n,unsigned char decimals,char *str);
void ftoe(float n,unsigned char decimals,char *str);
void srand(int seed);
int rand(void);
void *malloc(unsigned int size);
void *calloc(unsigned int num, unsigned int size);
void *realloc(void *ptr, unsigned int size); 
void free(void *ptr);

#pragma used-
#pragma library stdlib.lib


// CodeVisionAVR C Compiler
// (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.


#pragma used+

void delay_us(unsigned int n);
void delay_ms(unsigned int n);

#pragma used-

/*****************************************************
FileName: hongwai
Version : 1.0
Date    : 2007-7-31
Author  : bw
Company : Benfei Studio                   
Comments: 适用于LC7461等红外编码芯片的红外解码
Chip type : Only for Atmega16

解码原理是利用AVR单片机的输入捕捉功能,捕捉相临下降沿之间的时间差
,系统时钟1M。使用时必须先初始化timer1。
应用此头文件,须在主函数中使用如下变量:

                uint      arr[16];        //捕捉中断之间的时间值;
                uchar   times;          //捕捉中断次数;
                uchar   index;          //数组索引;
                uchar   ir_code;        //接受红外编码;
                uchar   ok_flag;        //解码完毕标示;
                uchar   head;           //引导码标志;

*****************************************************/  

#pragma used+ 




unsigned int  arr[16];  //捕捉中断之间的时间值;
unsigned char   times;  //捕捉中断次数;
unsigned char   index;  //数组索引;
unsigned char   ir_code;  //接受红外编码;
unsigned char   ok_flag;  //解码完毕标示;
unsigned char   head;   //引导码标志;

void  time1_initial();         //定时器1初始化,确定输入捕捉的工作方式
unsigned char  get_code();            //结果:得到uchar型的键码ir_code,如果解码出错,则ir_code=0xff 
  
#pragma used-

#pragma library hongwai.lib




// Alphanumeric LCD Module functions
#asm
#asm
   .equ __lcd_port=0x18 ;PORTB
#endasm
/* LCD driver routines

  CodeVisionAVR C Compiler
  (C) 1998-2003 Pavel Haiduc, HP InfoTech S.R.L.

  BEFORE #include -ING THIS FILE YOU
  MUST DECLARE THE I/O ADDRESS OF THE
  DATA REGISTER OF THE PORT AT WHICH
  THE LCD IS CONNECTED!

  EXAMPLE FOR PORTB:

    #asm
        .equ __lcd_port=0x18
    #endasm
    #include <lcd.h>

*/


#pragma used+

void _lcd_ready(void);
void _lcd_write_data(unsigned char data);
// write a byte to the LCD character generator or display RAM
void lcd_write_byte(unsigned char addr, unsigned char data);
// read a byte from the LCD character generator or display RAM
unsigned char lcd_read_byte(unsigned char addr);
// set the LCD display position  x=0..39 y=0..3
void lcd_gotoxy(unsigned char x, unsigned char y);
// clear the LCD
void lcd_clear(void);
void lcd_putchar(char c);
// write the string str located in SRAM to the LCD
void lcd_puts(char *str);
// write the string str located in FLASH to the LCD
void lcd_putsf(char flash *str);
// initialize the LCD controller
unsigned char lcd_init(unsigned char lcd_columns);

#pragma used-
#pragma library lcd.lib



/*uint      arr[16];        //捕捉中断之间的时间值;
uchar   times;          //捕捉中断次数;
uchar   index;          //数组索引;
uchar   ir_code;        //接受红外编码;
uchar   ok_flag;        //解码完毕标示;
uchar   head;           //引导码标志;
*/
unsigned char   hex[3];        //十六进制解码
unsigned char   code[5];          //用于液晶显示所用的存储数据数组应设置长点!
flash unsigned char   showhex[]="The Code Is:0x";
flash unsigned char   showdec[]="Dec Code:";

void  dec_to_hex(unsigned char dec)                       //十进制转换十六进制显示
{
       unsigned char  temp[2],i;
       temp[0]=dec/16;
       temp[1]=dec%16;
       for(i=0;i<2;i++){
              switch(temp[i]){
                 case 0:temp[i]='0';break;
                 case 1:temp[i]='1';break;
                 case 2:temp[i]='2';break;
                 case 3:temp[i]='3';break;
                 case 4:temp[i]='4';break;
                 case 5:temp[i]='5';break;
                 case 6:temp[i]='6';break;
                 case 7:temp[i]='7';break;
                 case 8:temp[i]='8';break;
                 case 9:temp[i]='9';break;
                 case 10:temp[i]='A';break;
                 case 11:temp[i]='B';break;
                 case 12:temp[i]='C';break;
                 case 13:temp[i]='D';break;
                 case 14:temp[i]='E';break;
                 case 15:temp[i]='F';break;
              }
              hex[i]=temp[i];
       }
}



void  main()
{
       // port_initial();
        time1_initial();
        delay_us(200);
        lcd_init(16);
        delay_us(200);
        #asm("sei")              // Global enable interrupts
        while(1)
        {
                if(ok_flag)
                {
                        get_code();
                        dec_to_hex(ir_code);
                        ok_flag=0;
                        lcd_clear();
                        itoa(ir_code,code);
                }

                lcd_gotoxy(0,0);
                lcd_putsf(showhex);
                lcd_gotoxy(14,0);
                lcd_puts(hex);
                
                lcd_gotoxy(3,1);
                lcd_putsf(showdec);
                lcd_gotoxy(13,1);    
                lcd_puts(code);
                delay_us(500);
        };
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -