📄 ir.c
字号:
/*********************************************************************
Note:
1. Master mode is set to NTSC mode only. 4/17'02
And no auto detection function.
See "master_mode_source()" & "get_master_mode_hv_info()"
**********************************************************************/
#include <absacc.h>
#include "ir.h"
//#include "mic_232.h" //add RS232
//=========chang1==
#if (IR_FREQ == 24)
//add RS232
//for real 8051 24MHZ
#define BAUD 243 //add: 243 for 9600 , 230 for 4800
#define TMRH 0xff //Operate on 24Mhz crystal, 100us timer
#define TMRL 0x50 //0x48 //100us=(12/24)*200us; 65536-200=65336=0xff38
#define IR_SAMPLE_TIME 1800 //1800*0.5us ~= 0.9ms for NEC
#define IR_WAIT_TIME 1400 // 1200 for NEC
#define IR_PHILIPS_TIME 2400 // about 1.2ms=2400*0.5us for PHILIPS
#elif (IR_FREQ == 11) //add: 8051 operate on 11.0592Mhz
#define BAUD 250 //add: for 9600
#define TMRH 0xff //Operate on 11.0592Mhz ,about 100us
#define TMRL 0xba //add: 100/(12/11.0592)=92 65536-92=0xffa4
#define IR_SAMPLE_TIME 800 // about 0.9MS 800
#define IR_WAIT_TIME 600
#define IR_PHILIPS_TIME 1100 // about 1.2ms=1100*(12/11)us
#else
// for ICE 22.1184MHZ
#define BAUD 244 //add: for 9600
#define TMRH 0xff //Operate on 22Mhz crystal, 100us timer
#define TMRL 0x60 //0x58 //100us=(12/22)*183us; 65536-183=65352=0xff48
#define IR_SAMPLE_TIME 1600 // about 0.9MS 1600
#define IR_WAIT_TIME 1200
#define IR_PHILIPS_TIME 2200 // about 1.2ms=2200*(12/11)*0.5us
#endif
//======for philips========
unsigned char ir_command;
bit data ir_command_ok=0;
unsigned char ir_100us_count=0;
unsigned char dat[9], old_dat[6];
//unsigned int act_ind = act_ind_dat;
bit data initial=1;
bit data time_1ms,time_10ms,time_100ms;
bit data ch0_set, ch1_set, dis_set;
unsigned char form, freq, io_port;
unsigned int time_count;
/*
typedef struct {
BYTE ircode;
void (*irfunc)(void);
} t_ircode_entry;
*/
// add: void init_51sreg(void)
void init_51sreg(void)
{
PCON = 0x80; // SMOD = 1
TMOD = 0x21; // timer 1 set to mode2 ; timer0 set to mode1
TH0 = TMRH;
TL0 = TMRL;
TH1 = BAUD;
TL1 = BAUD;
SCON = 0x50; // 01010000 mode1(10bit asynchronous communication) REN=1
IE = 0x12; // (not) enable interrupt and ES=1, ET0=1
IP = 0x02; // timer 0 first priority PT0=1
TR0 = 1; // TCON = 0x10 start timer0
TR1 = 1; // TCON = 0x40
EA = 1;
}
//=====below for philips=========
void remote_check(void)
{
// perform(); here only for test philips ir
ir_command_ok = 0;
}
void Init_dat()
{
unsigned char i;
for (i=0; i<9; i++)
dat[i]=0;
for (i=0; i<6; i++)
old_dat[i]=0xff;
dat[0] = MC_INIT_REG0;
dat[1] = MC_INIT_REG1;
dat[2] = MC_INIT_REG2;
dat[3] = MC_INIT_REG3;
dat[4] = MC_INIT_REG4;
form = 0xff;
freq = 0xff;
io_port = 0xff;
}
void main()
{
init_51sreg(); // Init. Register for RS232
P0 = 0xff;
P1 = 0xfb; // CSNN = low
P2 = 0xff;
P3 = 0xff;
initial=1;
Init_dat();
while(1)
{
if (initial)
{
initial=0;
}
//===========change4=====
if(ir_command_ok) //ir_low9ms_ok=1;
{
remote_check();
//ir_1000us_count = 0; // later add,must! becuse ir interrupt is longer
}
if(time_count>=3000)
{
/*
update_time();
check_hv_sync(); // Check no signal / PAL / NTSC
time_count=0;
*/
}
}
}
static void ir_philips_find(void) using 0
{
unsigned int ir_data;
unsigned char ir_addr_code; // "215" for 2156_code
unsigned char ir_i;
unsigned int delay_time;
bit data ir_last_bit;
if(!ir_command_ok) // last ir command must be excuted, otherwise not check ir data
{
//<<<<<<<<< if start code first bit is "0", set as below.
TL0 = 0x0; TH0 = 0x0;
ir_last_bit=0;
ir_i = 0;
do{
if(ir_last_bit)
{
// =======recoed last bit=======
ir_data <<=1;
ir_data += 0x0001;
// =====now detect next bit====== when ir_last_bit=1, read duratione of high level
while(IR_PORT)
{
delay_time = TH0; delay_time <<= 8; delay_time += TL0;
if(delay_time > IR_PHILIPS_TIME*3)
{
if(ir_i<13) ir_i = 14; //after last bit,always high level
break;
}
}
if(delay_time < IR_PHILIPS_TIME) // about 1ms
ir_last_bit = 1;
else
ir_last_bit = 0;
if(ir_last_bit) //note:1->1 pass over low level , when 1->0, should not pass low level ;
{
TL0 = 0x0; TH0 = 0x0;
while(!IR_PORT) // pass over high level
{
delay_time = TH0; delay_time <<= 8; delay_time += TL0;
if(delay_time > IR_PHILIPS_TIME*3)
{
if(ir_i <13) ir_i = 14;
break;
}
}
}
TL0 = 0x0; TH0 = 0x0; // continuou count
}
else // ir_last_bit =0;
{
// =======recoed last bit=======
ir_data <<=1;
// =====now detect next bit====== when ir_last_bit=0, read duration of low level
while(!IR_PORT)
{
delay_time = TH0; delay_time <<= 8; delay_time += TL0;
if(delay_time > IR_PHILIPS_TIME*3) // at fact 1.778ms but here 3ms for tolerate
{
ir_i = 14;
break;
}
}
if(delay_time < IR_PHILIPS_TIME) // about 1ms at fact 0.8~0.9ms
ir_last_bit = 0; // for i++
else
ir_last_bit = 1;
if(!ir_last_bit) //note: when 0->1, should not pass high level; 0->0 pass high level
{
TL0 = 0x0; TH0 = 0x0;
while(IR_PORT) // pass over high level
{
delay_time = TH0; delay_time <<= 8; delay_time += TL0;
if(delay_time > IR_PHILIPS_TIME*3)
{
if(ir_i <13) ir_i = 14;
break;
}
}
}
TL0 = 0x0; TH0 = 0x0;
}
ir_i++;
}
while(ir_i < 14); //if err ir_i = 15;
if(ir_i == 14)
{
ir_command = (ir_data & 0x003f);
ir_addr_code = ((ir_data >>6)& 0x00ff);
// if((ir_addr_code==0x1f)) // 00011111B or 00111111 for KONKA,
ir_command_ok =1 ;
}
else
ir_command_ok =0 ;
}//ir_command check over
}
//===========change5=====
void ISR_Timer0(void) interrupt 1 using 0 //interrupt per 1000us
{
//For IR
if(IR_PORT)
{
ir_100us_count=0;
}
else
{
ir_100us_count++;
}
if(ir_100us_count>4) //about 0.4ms(mainly think of first bit of start code is 0, T= 1.778ms ;1.668ms when 33.333Mhz
{
ir_philips_find();
ir_100us_count = 0 ; // importance!
}
TL0 = TMRL; TH0 = TMRH; TF0=0; // TR0 = 1; // restart timer0 z: add TF0=0;
//For OSD
time_count++;
//Time // z: for OSD_time demo
// if( (time_count%10) == 0) time_1ms = 1;
// if( (time_count%100) == 0) time_10ms = 1;
// if( (time_count%1000) == 0) time_100ms = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -