PWM using PIC18F

Home Forums Microcontrollers PIC Microcontroller PWM using PIC18F

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #11037
    PN
    Participant

    I want to program PIC18F such that with push button 1 pressed, the relay/LED is on for 1 sec, off for 2 sec continuously unless button 2 pressed , in which relay/LED will be on for 2.5 sec and off for 5 sec. How to achieve this? I tried giving delay (as given below) but when i press RD1 it does not recognize. I want PIC to change timing whenever i press other button.

    while(1)
    {
      if(PORTD.RD0==0)
      {
        PORTB.RB0=1;
        delay_ms(2500);
        PORTB.RB1=0;
        delay_ms(5000);
        if(PORTD.RD1==0)
        {
          //condition of while RD0 becomes false
          //start a different delay
        }
      }
    }
    
    #11106
    Ligo George
    Keymaster

    You can program like this :

    .............
    .............
    TRISD.F0 = 1;
    TRISD.F1 = 1;
    .............
    .............
    while(1)
    {
      while(PORTD.F0 == 0)
      {
         LATB.F0 = 1; // Use LAT register to write output in 18F
         Delay_ms(1000);
         LATB.F0 = 0;
         Delay_ms(2000);
      }
      
      while(PORTD.F1 == 0)
      {
        LATB.F0 = 1;
        Delay_ms(2500);
        LATB.F0 = 0;
        Delay_ms(5000);
      }
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
>