Implement count procedure

Post Reply
aldoo
Posts: 20
Joined: Sat Feb 09, 2019 6:23 pm

Implement count procedure

Post by aldoo » Wed Aug 14, 2019 4:44 pm

How to implement a PLC procedure that count with hard key and reset when get a certain value?

ivan
Posts: 59
Joined: Tue Apr 16, 2019 5:30 pm

Re: Implement count procedure

Post by ivan » Thu Aug 15, 2019 2:30 pm

Good morning. Here is an example Software PLC procedure that would do what you are asking:

Code: Select all

main()
{
a0=portget(0);

do{
a1=portget(0); 
if (a0==0)
{

  if (a1!=0)  //if hard key is pressed
  {
    count++;  //add 1 to the count
    
      if (count>50)  
      {
         count=0; //resets after 50 hard key presses
      };
   gvarset(500,count);  //sets a global variable to be equal to the count number 
                        //this can be changed depending on your needs
  };
};

a0=a1;

}while(1); 



};

Post Reply