本帖最后由 麦小播 于 2019-4-24 16:01 编辑  
 
原帖链接:https://www.cnblogs.com/wangh0802PositiveANDupward/p/3243639.html 
 
 
 if(DeviceFlag == 0x55) 
  {     amount++; 
     switch(amount%2) 
     { 
        case 1: Command_Out =1; break; 
        case 0: Command_Out =0; break; 
     } 
     if(amount==8)//16*8=128ms 
     {   
        amount=0;  
        DeviceStatus = TurnOn; 
        DeviceFlag = 0xFF; 
     } }  //发出波形的方式很多种,   1、可用两个定时器,第一用作定时占空比,并且执行一次就关闭,由另外一个定时器开启,另外一个定时器作为定时周期。  
- //----------发送命令变量----------------------------
 
 - static unsigned int  current;                  //延时计数器
 
 - static unsigned char irdata_silent[]={0,1,0,1,2,0,1,0,1,2,0,1,0,1,2};   //kaiji指令
 
 - static unsigned char irdata_TurnOn[]={1,0,1,0,2,1,0,1,0,2,1,0,1,0,2};//guanji zhiling
 
 - /***************************************************************
 
 - *总体格式:静默指令(共三帧指令):0101 S 0101 S 0101 S(左移) ASASAS
 
 - * 开启指令(共三帧指令):1010 S 1010 S 1010 S(左移) 5S5S5S
 
 - *左移:0101,0x05,开;1010,0x0A,关;“S”代码(STOP):1mS高电平+9mS低电平
 
 - ***************************************************************/
 
 - void SendCommand(unsigned char data)
 
 - {
 
 -     p_irdate = data;
 
 -     switch(p_irdate)
 
 -     {
 
 -        case 0:     Timer01_Init();   //1ms
 
 -                    Timer35_Init();   //5ms 
 
 -                    break;
 
 -        case 1:     Timer04_Init();   //4ms            
 
 -                       Timer35_Init();   //5ms
 
 -                    break;
 
 -       case 2:     Timer01_Init();   //1ms
 
 -                   Timer310_Init();  //10ms
 
 -                   break;
 
 -     }
 
 -     T0CONbits.TMR0ON = 1;
 
 -     T3CONbits.TMR3ON = 1;
 
 -     Command_Out = 1;
 
 - }
 
 - /*******************************
 
 - *中断处理函数
 
 - *******************************/
 
 - #pragma code high_vector=0x08
 
 - void interrupt_at_high_vector(void)
 
 - {
 
 -     _asm goto high_isr _endasm
 
 - }
 
 - #pragma code
 
  
- #pragma code low_vector=0x18
 
 - void interrupt_at_low_vector(void)
 
 - {
 
 -     _asm goto low_isr _endasm
 
 - }
 
 - #pragma code
 
  
- #pragma interrupt high_isr
 
 - void high_isr(void)  //TMR0
 
 - {
 
 -     if(INTCONbits.TMR0IF==1)      
 
 -       {
 
 -            INTCONbits.TMR0IF=0; 
 
 -            Command_Out = !Command_Out;
 
 -            mLED_1_Off();
 
 -            T0CONbits.TMR0ON = 0;
 
 -     }
 
 -     
 
 - }
 
  
- #pragma interruptlow low_isr
 
 - void low_isr(void)      
 
 - {    
 
 -     if(PIR2bits.TMR3IF==1)   
 
 -       {
 
 -            PIR2bits.TMR3IF=0;
 
 -            Command_Out = 1;
 
 -            mLED_1_On();
 
 -            current++;
 
 -            if(current<15)
 
 -           {
 
 -                SendCommand(irdata_silent[current]);
 
 -            }
 
 -            else
 
 -           {   
 
 -                           current =0;
 
 -                           SendCommand(irdata_silent[current]);//      
 
 -              } 
 
 -           //T3CONbits.TMR3ON = 0;
 
 -          //T0CONbits.TMR0ON = 1;
 
 -     }
 
 - }
 
  
 
  |