0

I try to increment a integer value from 0 to 2 and again roll back to zero again every time when button is clicked. when i click the button the value is incremented up to 1 and stops there itself. i am using dsPIC33 microcontroller with a switch and LCD display for viewing the values. And iam using mplab x ide for coding. Iam using Elcom MPS-1 switch (4A, 250V).And Here is my code.

#define GreenButton PORTBbits.RB3 // Assigned as input pin

void longdelay()
{
    long unsigned int i;
    for(i=0;i<300000;i++);
}

void display()
{
   sprintf(buff1,"mode");
   sprintf(buff2,"  ");
   sprintf(buff3,"%d",v); 
   call_display();
   lcddelay(); 
}

int main()
{
        int v = 0;
        int cnt = 2;
        display();
        
        while((cnt)&&(GreenButton == 0))
        {   
            v++;
            display();
            cnt--;
           longdelay();
           longdelay();
           longdelay();
        }
        
        longdelay();
        longdelay();
        longdelay();
}
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
V_J viji
  • 39
  • 1
  • 7
  • 2
    What I think is happening here is that once you press `GreenButton`, its state changes, but you do not change its state back, so the `while` condition is false continuously and thus does not increment. – debruss Jul 08 '21 at 11:51
  • 1
    does this even compile ? you don't even type or declare variable ? – Thibaud Jul 08 '21 at 14:17
  • @debruss can you please explain how to change the status of the input pin (GreenButton)?. – V_J viji Jul 09 '21 at 04:33
  • Port B3 should be a digital input. Where did you define that? – Mike Aug 02 '21 at 13:44

0 Answers0