Forum Replies Created

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • in reply to: PIC Microcontroller Non-Blocking Delay Implementation #12110
    emufambirwi
    Participant

    Sorry, my mistake, I had left some } in the code. But 1st LED blinks fast

    in reply to: PIC Microcontroller Non-Blocking Delay Implementation #12109
    emufambirwi
    Participant

    Thanks Mr George, now I can control the LED’s independently but they are forever ON. Let me see if I can do something about the timing

     

    in reply to: PIC Microcontroller Non-Blocking Delay Implementation #12105
    emufambirwi
    Participant

    This is how I have changed my code and the result is still the same :

    char uart_rd;
    char cnt, cnt1;
    
    void interrupt ()
    {
      if (TMR0IF_bit)
      {
        cnt++;                 // increment counters
        cnt1++;
        TMR0IF_bit = 0;        // clear TMR0IF
        TMR0L = 0xDC;             // set TMR0 for aproximetly 1 sec
        TMR0H = 0x0B;
      }
    }
    
    void one_min_delay ()
    {
      TRISB  = 0;              // PORTB is output
      TMR0H = 0x0B;
      TMR0L = 0xDC;               // Timer0 initial value
    
      T0CON = 0x84;            // Set TMR0 to 8bit mode and prescaler to 256
      GIE_bit = 1;             // Enable global interrupt
      TMR0IE_bit = 1;          // Enable Timer0 interrupt
    
      cnt = 0;                 // Initialize cnt
    
      do
      {
        if (cnt >= 60)
        {
          LATB = 0x00;      // turnoff PORTB LEDs
          cnt = 0;             // Reset cnt
        }
      }while(1);
    }
    
    void two_min_delay ()
    {
      TRISB  = 0;              // PORTB is output
      TMR0H = 0x0B;
      TMR0L = 0xDC;               // Timer0 initial value
      T0CON = 0x84;            // Set TMR0 to 8bit mode and prescaler to 256
      GIE_bit = 1;             // Enable global interrupt
      TMR0IE_bit = 1;          // Enable Timer0 interrupt
    
      cnt1 = 0;                 // Initialize cnt1
    
      do
      {
        if (cnt1 >= 120)
        {
          LATB = 0x00;      // turnoff PORTB LEDs
          cnt1 = 0;             // Reset cnt
        }
      }while(1);
    }
    
    void main()
    {
      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;
          one_min_delay();
        }
        else if (uart_rd == 'B')
        {
          PORTB = 0x02;
          two_min_delay ();
        }
        uart_rd ='\0';
      }
    }
    
    in reply to: PIC Microcontroller Non-Blocking Delay Implementation #12103
    emufambirwi
    Participant

    Thanks for the reply. I hope I get you well. The number of variables is the same as the number of LED’s to be controlled. Let me change my code and try that and I will give you feedback.

    Another question is: Is there any other way to do this without the use of interrupts?

     

Viewing 4 posts - 1 through 4 (of 4 total)
>