Reply To: PIC Microcontroller Non-Blocking Delay Implementation

Home Forums Microcontrollers PIC Microcontroller PIC Microcontroller Non-Blocking Delay Implementation Reply To: PIC Microcontroller Non-Blocking Delay Implementation

#12108
Ligo George
Keymaster

Sorry, I don’t understand your code. You have 3 infinite loops in your program. One in main loop, one in 1 min delay loop and other in 2 min delay loop.

You can try like this :

void main()
{
  unsigned int a, b;
  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize
  TRISB = 0x00;

  while (1)
  {
    if (UART1_Data_Ready())
    {     // If data is received,
      uart_rd = UART1_Read();
    }

    if (uart_rd=='A')
    {
      LATB = 0x01;
      a = 100;
    }
    else if (uart_rd == 'B')
    {
      LATB = 0x02;
      b = 200;
    }
    uart_rd ='\0';
    
    if(a > 0)
    {
       Delay_ms(1);
       a--;
    }
    else
      LATB = 0;
    
   if(b > 0)
   {
     Delay_ms(1);
     b--;
   }
   else
     LATB = 0;
  }
}
>