这个程序实现K1D和中国电信机顶盒遥控器解码。
刚刚从51单片机转到AVR ,也刚刚学习用C编程,一些语句格式纠错搞了一天,终于完成,效果很好。共享给大家。
我这里只贴上解码部分的文件,显示部分文件就算了。大家知道的。
第一次发帖,请大家鼓励一下!
//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; //定时中断计数器
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变为0x01
jsq9++;
}
}
else if(time_js0==0x10) //=1
{
js1 >>= 1;
js1 |= 0x80;
jsq8++;
if (jsq8==8) {jsq8=0;
wlcd[jsq9]= js1;//实际"1"=0x00,所以+1变为0x01
jsq9++;
}
}
else if(time_js0>0x20) //前导码等
{
jsq8=0; jsq9=0;js1=0;
}
time_js0=0;
}
//////////////////////////////////////////////////////////////////////////////
void main(void)
{
init_devices(); //初始化系统
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);//写入当前H字符并显示
js5=(wlcd[2] &0x0f)+0x30;
if(js5>0x39){js5=js5+0x07;}
Write_Data(js5);//写入当前L字符并显示
Sound_bj(8); //报警声
}
//
//wlcd[8]=0x08;
//wlcd[9]=0x01;
//LCD_write_str(0, 0,wlcd );
}
}
|