PWM using PIC18F – electroSome https://electrosome.com/topic/pwm-using-pic18f/feed/ Sat, 18 Mar 2023 04:56:26 +0000 https://bbpress.org/?v=2.6.9 en-US https://electrosome.com/topic/pwm-using-pic18f/#post-11037 <![CDATA[PWM using PIC18F]]> https://electrosome.com/topic/pwm-using-pic18f/#post-11037 Fri, 13 Mar 2015 09:11:54 +0000 PN 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
    }
  }
}
]]>
https://electrosome.com/topic/pwm-using-pic18f/#post-11106 <![CDATA[Reply To: PWM using PIC18F]]> https://electrosome.com/topic/pwm-using-pic18f/#post-11106 Sun, 22 Mar 2015 14:21:58 +0000 Ligo George 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);
  }
}
]]>