📄 main.c
字号:
#include "comm.h"
#include "ir.h"
#include "ic165.h"
#include "message.h"
#include "Key_process.h"
#include "debug.h"
/*
*SYSTEM CLOCK IS 4MHz
*/
//extern uint pre_code;
//unsigned
uchar user_key = 0xff;
int linear_timer = 0;
uchar Get_key_timer = 0;
#ifdef DEBUG_PRINTF1
bit test_flag = 0;
#endif
uchar codeIR;
bit ir_enable = 0; /*IR receive valid?*/
bit power_flag = 0; /*POWER valid?*/
void timer1_interrupt_service() interrupt 3
/*system timer increase 10mS*/
{
#ifdef DEBUG_PRINTF1
static uchar delay_time_cnt = 0;
#endif
TR1 = 0;
TH1 = TIMER0_RELOAD_HIGH;//0xB1;
TL1 = TIMER0_RELOAD_LOW;//0xED; /*add 0xd to adjust timer*/
TR1 = 1;
if(linear_timer > 0)
{
linear_timer = linear_timer - 1;
}
if(Get_key_timer >0) /*扫描按键的时间*/
{
Get_key_timer --;
}
#ifdef DEBUG_PRINTF1
delay_time_cnt ++;
if( delay_time_cnt == 100)
{
test_flag = 1;
delay_time_cnt = 0;
}
#endif
/* linear_timer ++;*/
}
void system_timer_init()
/*I use timer1 to generate system time*/
{
TH1 =TIMER0_RELOAD_HIGH ;//0xBE;
TL1 = TIMER0_RELOAD_LOW;//0xE0;
TR1 = 1;
ET1 = 1;
}
#if 1
void delay(unsigned int j) /*0.173ms*/
{
unsigned char i ;
for(;j>0;j--)
{
i = 10;
while(--i); /*10uS*/
}
}
#endif
void set_system_baud_rate(uchar mode) /*7.3728 MHz /2*/
{
uchar reg_brgr0 = 0,reg_brgr1 = 0;
switch(mode)
{
case 0:
reg_brgr0 = 0x50;
// baud_rate = 38400;
break;
case 1:
reg_brgr0 = 0xB0;
reg_brgr1 = 0x00;
// baud_rate = 19200;
break;
case 2:
reg_brgr0 = 0x70;
reg_brgr1 = 0x01;
// baud_rate = 9600;
break;
case 3:
reg_brgr0 = 0x10;
// baud_rate = 115200;
break;
case 4:
reg_brgr0 = 0xF0;
reg_brgr1 = 0x02;
// baud_rate = 4800;
break;
}
PCON = 0x40;
SCON = 0x50;
BRGCON = 0;
BRGR0 = reg_brgr0;
BRGR1 = reg_brgr1;
BRGCON = 3;
}
/*
QUASI_BIDIRECTIONAL: 00
PUSH_PULL: 01
INPUT_ONLY: 10
OPEN_DRAIN: 11
*/
void io_config()
{
P0M1 = 0x00;/* 0.0 推挽*/
P0M2 = 0x23;
//P0 = 0x7c /**/;
P1M1 = 0x06;//0x04 jian
P1M2 = 0x17;
/*p1.1 LED 为准双向设置
p1.2 发送为输出1 0
p1.3 IR 接受,准双向 00.
p1.4 rst_n 输入
*/
// P1 = 0xB0;
}
#if 0
unsigned char LSbTMsb(unsigned char Ldata)
{
unsigned char Mdata,i;
for (i =0 ;i<8;i++)
{
if(Ldata & 0x01)
{
Mdata |= 0x01;
}
else
{
Mdata &= ~0x01;
}
Ldata >>= 1;
if(i < 7)
Mdata <<= 1;
}
return Mdata;
}
#endif
void main()
{
#ifdef DEBUG_PRINTF
// extern unsigned char ivcode,sys_code;
#endif
DIVM = 1; /*将时钟分为一半的频率*/
io_config();
set_system_baud_rate(3); /*115200*/
/*start system timer*/
TMOD = 0x11;
TH0 = 0x00;
TL0 = 0x00;
ET0 = 1;
EX0 = 1;
TR0 = 0;
IT0 = 1; /*中断1 下降廷触发*/
EA = 1;
system_timer_init();
//STANDBY_LED = LED_POWER_ON;
// proc_ir_sel_disp(14);
P1M1 = 0x06;
STANDBY_LED = LED_STANDBY; /**/
RST_N = 0; /*复位脚先拉低*/
OUTPUT_IR = 1;
STANDBY_CTRL = CTRL_POWER_OFF;
#if 0
RST_N = 0; /*复位脚先拉低*/
STANDBY_CTRL = CTRL_POWER_ON;
//proc_ir_sel_disp(6); //delete zxl 07-10-09 去除灯闪烁
Rest_Mast_TvBox();
STANDBY_LED = LED_STANDBY;
power_flag = 1; /*POWER ON*/
#endif
// STANDBY_CTRL = CTRL_POWER_ON;
// power_flag = 0;
// proc_power_key();
while(1)
{
#if 1
if(Get_key_timer == 0) /*10ms扫描一次*/
{
GetPanelKeyThread();
Get_key_timer = 1;
}
#endif
if(ir_enable)
{
#ifdef DEBUG_PRINTF
tvbox_printf("button code:",codeIR,1);
// tvbox_printf("sys code:",sys_code,1);
// tvbox_printf("ivn code:",ivcode,1);
#endif
ir_enable = 0;
//codeIR = LSbTMsb(codeIR); /*jian add in 07-07-31*/
user_key = codeIR;
}
if(user_key != 0xff/*_NO_KEY*/)
{
// tvbox_printf("user key:",user_key,1);
key_service(user_key);
user_key = 0xff;/*_NO_KEY*/;
}
// PutChar(0x55);
#ifdef DEBUG_PRINTF1
if (test_flag == 1) /*1 s 一次*/
{
PutChar(0x55);
test_flag = 0;
}
#endif
delay(10);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -