找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 2967|回復(fù): 2
收起左側(cè)

AVR 8515單片機(jī)遙控器 解碼程序

[復(fù)制鏈接]
ID:716413 發(fā)表于 2020-3-26 19:02 | 顯示全部樓層 |閱讀模式
這個程序?qū)崿F(xiàn)K1D和中國電信機(jī)頂盒遙控器解碼。
剛剛從51單片機(jī)轉(zhuǎn)到AVR ,也剛剛學(xué)習(xí)用C編程,一些語句格式糾錯搞了一天,終于完成,效果很好。共享給大家。
我這里只貼上解碼部分的文件,顯示部分文件就算了。大家知道的。
第一次發(fā)帖,請大家鼓勵一下!

//ICC-AVR application builder : 2020/3/25
// Target : 8515     TH186_K1D遙控器解碼
// Crystal: 8.0000Mhz

#include <io8515v.h>
#include <macros.h>
#include "lcd1602.h"  //兩個C文件都要這
//////////////////////////////////
void Sound_bj(char t)   //報警聲
{
                  char r;
       for(r=0;r<t;r++)
                            { KL_OFF;
                     delay_ms(3);
                         KL_ON;
                         delay_ms(3);
                         }
}
/////////////////////////////////
void port_init(void)
{
PORTA = 0x00;
DDRA  = 0xFF;
PORTB = 0x00;
DDRB  = 0xFF;
PORTC = 0x00;
DDRC  = 0xFF;
//PORTD = 0x00;
DDRD  = 0xF8;
}
//TIMER0 initialize - prescale:256
// desired value: 10KHz
// actual value: 10.417KHz (4.0%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop timer
TCNT0 = 0xfc; //=fd set count value  10kHz
TCCR0 = 0x04; //start timer
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer0_init();

MCUCR = 0x02; //int0 02=下降沿中斷,03=上升沿中斷
GIMSK = 0x40;
TIMSK = 0x02;
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//////////////////////定時器0中斷////////////////////////////////////////
#pragma interrupt_handler timer0_ovf_isr:8
char time_js0;          //定時中斷計數(shù)器

void timer0_ovf_isr(void)//reload counter value
{
TCNT0 = 0xfc;//FD;
time_js0++;
}


///////////////////////外部中斷PD2接遙控接收///////////////////
#pragma interrupt_handler int0_isr:2

char js1=0,js5=0;
char jsq8=0,jsq9=0;
char wlcd[9]={""};

void int0_isr(void) //external interupt on INT0
{      

                time_js0 &=0xf0;
               
       if(time_js0==0x00)   //=0
          {
                   js1 >>= 1;
                   js1 &= 0x7f;
                   jsq8++;        
                   if (jsq8==8) {jsq8=0;
                                                 wlcd[jsq9]= js1; //實際"1"=0x00,所以+1變?yōu)?x01
                                                jsq9++;
                                                }
          }

   else if(time_js0==0x10)  //=1
          {
                   js1 >>= 1;
                   js1 |= 0x80;
                   jsq8++;        
                   if (jsq8==8) {jsq8=0;
                                                 wlcd[jsq9]= js1;//實際"1"=0x00,所以+1變?yōu)?x01
                                                jsq9++;
                                                }
          }
                  
    else if(time_js0>0x20)         //前導(dǎo)碼等
          {
                  jsq8=0; jsq9=0;js1=0;
          }
                  
                 
    time_js0=0;
}




//////////////////////////////////////////////////////////////////////////////
void main(void)
{
    init_devices();         //初始化系統(tǒng)
    LCD_init();           //LCD初始化

while(1)
    {
        
            if (jsq9==4)
             {
             jsq9=0;
                 LCD_SET_XY(0,0);
                                                  js5=(wlcd[2] >>4)+0x30;   
                                                   if(js5>0x39){js5=js5+0x07;}
                                                    Write_Data(js5);//寫入當(dāng)前H字符并顯示

                                                    js5=(wlcd[2] &0x0f)+0x30;
                                                   if(js5>0x39){js5=js5+0x07;}
                                                    Write_Data(js5);//寫入當(dāng)前L字符并顯示
                  Sound_bj(8);  //報警聲
                 }
        
        //
        //wlcd[8]=0x08;
        //wlcd[9]=0x01;
        //LCD_write_str(0, 0,wlcd );
        }
}

回復(fù)

使用道具 舉報

ID:1 發(fā)表于 2020-3-26 20:10 | 顯示全部樓層
本帖需要重新編輯補(bǔ)全電路原理圖,源碼,詳細(xì)說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
回復(fù)

使用道具 舉報

ID:716413 發(fā)表于 2020-3-26 20:29 | 顯示全部樓層
謝謝管理!我會努力的
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表