예제 #1
0
void IRsend_mark(u16 time)
{
    u16 i;
    // Sends an IR mark for the specified number of microseconds.
    // The mark output is modulated at the PWM frequency.

    // duty cycle = 50% = Enable PWM output
    PWM_setPercentDutyCycle(irparams.outpin, 50);
    
    // loopcounter i = time - correction factor
    // Without the NOPs the loop has an execution time of ~13 microseconds
    i = time-13;
    
    // while () {} needs much less time than for (;;) {}
    // for loop without NOPs : ~ 1,3 ms (889 iterations on 18f26j50)
    // while loop without NOPs: ~ 712 µs (889 Iterations on 18f26j50)
    while (i) {
      _1us_
      i--;
    }
    
/*
    for (i=0; i<time; i++)
    {
;        _1us_
    }
*/
}
예제 #2
0
	void Tone(u8 pin, u16 freq, u16 duration)
	{
		PWM_setFrequency(freq);
		PWM_setPercentDutyCycle(pin, 50);
		Delayms(duration);						// length of sound in ms 
		noTone(pin);
	}
예제 #3
0
// Note: first bit must be a one (start bit)
void IRsend_sendRC5(u32 data, u16 nbits)
{ 
    u16 i;

    PWM_setFrequency(36000);
    PWM_setPercentDutyCycle(irparams.outpin, 50);
    data = data << (32 - nbits);

    IRsend_mark(RC5_T1); // First start bit
    IRsend_space(RC5_T1); // Second start bit
    IRsend_mark(RC5_T1); // Second start bit

    for (i = 0; i < nbits; i++)
    {
        if (data & TOPBIT)
        {
            IRsend_space(RC5_T1); // 1 is space, then mark
            IRsend_mark(RC5_T1);
        } 
        else
        {
            IRsend_mark(RC5_T1);
            IRsend_space(RC5_T1);
        }
        data <<= 1;
    }

    IRsend_space(0); // Turn off at end
}
예제 #4
0
	void noTone(u8 pin)
	{
		PWM_setFrequency(0);					// note (range 1..14)
		PWM_setPercentDutyCycle(pin, 0);		// silence
		//pinmode(pin, INPUT);
		//CCP1CON = 0;							// stop sound = stop pwm
		//T2CONbits.TMR2ON = OFF;				// disable Timer2 = stop pwm = stop sound
	}
예제 #5
0
/* Leave pin off for time (given in microseconds) */
void IRsend_space(u16 time)
{
    u16 i;
    // Sends an IR space for the specified number of microseconds.
    // A space is no output, so the PWM output is disabled.

    // duty cycle = 0% = Disable PWM output
    PWM_setPercentDutyCycle(irparams.outpin, 0);

    // loopcounter i = time - correction factor
    // without the NOPs the loop has an execution time of ~70 microseconds
  
    i = time - 70; // correction factor: 13 microseconds
    while (i) {
      _1us_
      i--;
    }
/*
    for (i=0; i<time; i++)
    {
        _1us_
    }
*/
}