⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nokon628.c

📁 Source code of Radio Control Nikon Digital Camera Shutle. Using for Fly RC Aircraft with Nikon D40,D
💻 C
字号:
#include "C:\PIC\CCS_PRJ\NIKON_16F628\Nokon628.h"
/*
#int_RDA
void  RDA_isr(void) 
{
return;
}

#int_TIMER1
void  TIMER1_isr(void) 
{
return;
}

#int_CCP1
void  CCP1_isr(void) 
{
return;
}

*/
#DEFINE BUTTON PIN_B4
#define LED_ON output_low
#define LED_OFF output_high
#define IR_LED PIN_B5
#DEFINE  DEBOUNCE_TIME  10
#define  PORTA    5
#define  PORTB    6
#define  _DOUT      PORTB, 5      // Outgoing data


int BUTTON_PRESSED()
{
    static int laststate=0;

    if (!input(BUTTON))
    {
        delay_ms(DEBOUNCE_TIME);   // debounce time
        if (bit_test(laststate,0))
        {
            laststate = 0;
            return (1);
        }
    } else
        bit_set(laststate,0);

    return (0);
}

//  IR command sequence for AF & shutter release   :
//     - starting pulse 2250us (IR on)    OR:   2ms on
//     - pause 27600us (IR off)                 28ms off
//     - 650us pulse                            0.5ms on
//     - pause 13750us                          1.5ms off
//     - 575us pulse                            0.5ms on
//     - pause 3350us                           3.5ms off
//     - pulse 650us                            0.5ms on
//     - pause 63msec                           60ms off pause
//     - repeat the above sequence one time
//
//  The IR on-pulses need to be gated/modulated with 40kHz,
//  i.e. on for 12.5us off for 12.5us
//
//  The PIC runs on its 4MHz internal oscillator, so one 
//  instruction cycle takes 1.0us (1/4th of clock)

void Pulse_12_5Khz_Out()
{
int8 Counter;
   #asm
   movlw   80
   movwf   Counter
   Loop2ms:   
   bsf   _DOUT      
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   bcf   _DOUT     
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   decfsz   Counter, F   
   goto    Loop2ms      
   #endasm
   return;
}

void Pulse_12_5Khz_Pause()
{
   int8 Counter;
   #asm
   movlw   80
   movwf   Counter
   Loop2ms:   
   bcf   _DOUT      
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   bcf   _DOUT     
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   decfsz   Counter, F   
   goto    Loop2ms      
   #endasm
   return;
}

void pause28ms()
{
int8 Counter, Counter2;
#asm
   movlw   20
   movwf   Counter2  
   Loop28msO:
   movlw   199     
   movwf   Counter     
   Loop28msI:
   nop        
   nop         
   nop        
   nop         
   decfsz   Counter, F   
   goto   Loop28msI   
            //       Total delay - 7 ins
   nop         
   nop        
   nop         
   decfsz   Counter2, F   
   goto   Loop28msO   
  #endasm
  return;
}
void SendNikonCommand ()
{
int count=0;
//- starting pulse 2250us (IR on)    OR:   2ms on
   for(count=0;count <80;count++)
      Pulse_12_5Khz_Out();
//- pause 27600us (IR off)                 28ms off
  pause28ms();
//- 650us pulse                            0.5ms on
    for(count=0;count <20;count++)
      Pulse_12_5Khz_Out();
//- pause 13750us                          1.5ms off
    for(count=0;count <60;count++)
      Pulse_12_5Khz_Pause();
//- 575us pulse                            0.5ms on
   for(count=0;count <20;count++)
      Pulse_12_5Khz_Out();
//- pause 3350us                           3.5ms off
   for(count=0;count <140;count++)
      Pulse_12_5Khz_Pause();
//- 650us pulse                            0.5ms on
    for(count=0;count <20;count++)
      Pulse_12_5Khz_Out();
      
//- pause 63msec                           60ms off pause
}


void main()
{

  // setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  // setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
  // setup_timer_2(T2_DISABLED,0,1);
  // setup_ccp1(CCP_CAPTURE_RE);
  // setup_comparator(NC_NC_NC_NC);
  // setup_vref(FALSE);
  
  set_tris_b(0x1F); //B4 - input, B5 - Output
  output_high(PIN_B4);
  
   // enable_interrupts(INT_RDA);
   //enable_interrupts(INT_TIMER1);
   //enable_interrupts(INT_CCP1);
   //enable_interrupts(GLOBAL);

   // TODO: USER CODE!!
   printf("Nikon IR Remote.\r\n");
   
while (1){
     
    
         if( BUTTON_PRESSED())
            {
             
              SendNikonCommand ();
              printf("Sent OK.\r\n");
            }
 
};

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -