Produce tones at a specific time interval using C programming

Im uses the C language of the PIC18F to create tones so that each one reproduces a specific time interval. I used PWM to create the tone. But I do not know how to create intervals. Here is my attempt.

#pragma code                                    // 
void main (void)
{

 int i=0;
    // set internal oscillator to 1MHz  
    //OSCCON = 0b10110110;                    // IRCFx = 101
    //OSCTUNEbits.PLLEN = 0;                //PLL disabled

    TRISDbits.TRISD7 = 0;

    T2CON  = 0b00000101;                    //timer2 on
    PR2    = 240;
    CCPR1L = 0x78;
    CCP1CON= 0b01001100;



LATDbits.LATD7=0;
Delay1KTCYx(1000);

while(1);
}
+3
source share
3 answers

, , , , . , , , 0x01001010, , . ( ).

, , , PWM, . , :

  • , , , while. , PWM . , .
  • count0 count 0xFFFF-interval . ISR PWM, reset timer0 .

:

int flag=0;
void main()
{
  setup_interrupt(); //schedule interrupt for desired time.
  while (1)
  {  
     if (flag)
     {  
        update_something();
        flag = 0;
     }
  }

flag? :

void InterruptHandler()
{
  flag = 1;
  acknowledge_interupt_reg = 0;
}

, . update_something() PWM. : " , , . ( )"

while . , , - . - , , , .

+6

EDIT:
, . (-)? (do-re-me-fa -...)? , .


, , , , , .

  • PWM? ? , .
  • - , RA4/T0CKI? , T0, .
  • ? INT0IE, ,
  • ? , 0xFFFF / (clock_freq/8) TMR0H/L, - .
  • LATD7? ? , PWM?
  • Delay()? . , , . .
  • ? PR2? .

" ".

, , , .

0

Windows Beep kernel32:

    [DllImport("kernel32.dll")]
    private static extern bool Beep(int frequency, int duration);
-2

Source: https://habr.com/ru/post/1704083/


All Articles