Thanks Groove. I still have some trouble understanding why stack is so high and gets higher unless it's going up (like 8088) instead of coming down.
Here's my hmi(), which takes arguments current value, lower and upper limits, and steps. This function interacts with user to set value to current value and makes sure it's within lower and upper limit and increases in multiples of steps.
It calls wait_on_escape to wait on button push or escape after a set period of 50 ms. This way updates can go on if no button is pressed for 50ms.
Button.sense() just reads button pin status and outputs things like button is up, button is down (button is pressed), button is released (after it's was up), button is held (after it's down for a set period of time).
I don't see anything recurring. Plus, it only restarts when it quits silly. While in silly the stack value is stable.
Coding badly, is there a limit on how many bytes can be popped at function return? I was thinking about 8088 asm where there is a command ret n. This emptys n bytes on return, besides the instruction pointer. If say this ret n in 328 or 168 is only up to 7, then the function will not leave stack intact on return. Say 11 bytes were pushed before a call address, then the sub can only pop up to 7 bytes due to this limit. Then Every time a function with too many parameters gets called, it leaves 4 bytes on the stack (which should butt up the return address of the caller). If even one of these calls is done, the the caller will not be able to reture to ITS caller. Make any sense? (couldn't sleep well with this hanging in my mind)
int hmi(int current, int lower, int upper, byte inc)
{
int number;
int temp1;
byte cond=1;
int ret=0;
number=current;
while(cond)
{
temp1=wait_on_escape(50);
switch (temp1)
{
case -1:
cond=0;
ret=-1;
break;
case 1:
cond=0;
ret=number;
break;
case 2:
if (number+inc<=upper)
{
number+=inc;
}
break;
case 3:
if (number-inc>=lower)
{
number-=inc;
}
break;
default:
break;
}
lcd.setCursor(0,1);
if (number==0)
{
lcd.print("NO/LOW/0 ");
}
else if (number==1)
{
lcd.print("YES/HIGH/1");
}
else
{
char msg[10];
sprintf(msg,"%5d ",number);
lcd.print(msg);
}
}
return(ret);
}
int wait_on_escape(int ref_time)
{
//Wait on button push.
long temp0;
int cond=1;
int ret=0;
byte temp1, temp2, temp3;
temp0=millis();
while (cond&&((millis()-temp0<ref_time)))
{
temp1=btn_1.sense();
temp2=btn_2.sense();
temp3=btn_3.sense();
if ((temp2==buttons_down)&&(temp3==buttons_down))
{
sys_stat=sys_not_ready;
cond=0;
ret=-1;
}
else
{
if(temp1==buttons_released)
{
cond=0;
ret=1;
}
if((temp2==buttons_released)||(temp2==buttons_held))
{
cond=0;
ret=2;
}
if((temp3==buttons_released)||(temp3==buttons_held))
{
cond=0;
ret=3;
}
}
}
return (ret);
}