我的紅外處理程序中有個問題想不通,存放IR_PIN的高電平時間的變量,清0的時機選擇問題。具體請看下注釋,
- void IR_Recevie() {
- static uchar i,j,high_t;
- uint err_time;
- high_t=0;
- Delay8us(875);
- if(IR_Pin==LOW)
- {
- err_time=10;
- while((IR_Pin==LOW)&&(err_time>0))
- {
- Delay8us(125); //延時1ms
- err_time--;
- }
- if(IR_Pin==HIGH)
- {
- err_time=6;
- while((IR_Pin==HIGH)&&(err_time>0))
- {
- Delay8us(100); //延時0.8ms
- err_time--;
- } for(i=0;i<4;i++)
- {
- for(j=0;j<8;j++)
- {
- err_time=2;
- while((IR_Pin==LOW)&&(err_time>0))
- {
- Delay8us(40); //延時0.32ms
- err_time--;
- }
- err_time=100;
- while((IR_Pin==HIGH)&&(err_time>0))
- {
- Delay8us(20); //延時0.16ms
- err_time--;
- high_t++;
- if(high_t>20)
- return;
- }
- ir_code[i]=ir_code[i]>>1;
- if(high_t>=6)
- {
- ir_code[i]|=0x80; [b] // 當high_t 如果在這里面清0,[/b][b]遙控就接受不到正確的值[/b]
- }
- high_t=0;
- }
- }
- }
- if(ir_code[2]!=~ir_code[3])
- return;
- }
- }
復制代碼
|