Reputation: 17
I have a loop for my clock, that I am trying to make an add 30 sec if keypad sends an x value of 30. It then displays on the LED display. It works, but I seem to be having an issue with adding 30 seconds and over 59 sec. The way it worked originally was it kept adding 30 to 60 to 90 + 120, etc. But I want it to roll over every 60 secs, when I add 30 sec. If I should rewrite the code, I am all game, but any leads would be helpful. Know this code is for an embedded item and is only a snippet. the inital set time is added before set loop, and is held as the value for test.
n=test;
for(i=0;i<n;i++){
q = test %100; /*q makes real time clock work in 60 sec decriments*/
if(q==0){
test = test - 40;
}
key = KeypadReadPort();
x = keys[key];
if(x==30){ /*add 30 seconds during count*/
n = n + 30;
sec1=(test+30)%90;
if(sec1>=60){
min=q;
sec2=(test+30)%60;
test=sec2+(100+q);
} else if (sec1<60){
test=test+30;
}
SevenSegWrite(test);/* display result on LED*/
}
test = test - 1; /*count down tick*/
SevenSegWrite(test);
OSTimeDlyHMSM(0, 0, 1, 0);/*1 second tick*/
if(test==0){
for(i=0;i<750;i++){ /*buzzer*/
PTT = PTT | 0x20;
OSTimeDlyHMSM(0,0,0,1);
PTT = PTT & 0xDF;
OSTimeDlyHMSM(0,0,0,1);
}
}
}
test=0;
Upvotes: 0
Views: 1132
Reputation: 40
I would do it this way. It works for me. You have a great start! You just need to break down your clock numbers a bit.
if(start<15){
min=0; /*microwave keypad numeric input method*/
n = test;
for(i=0;i<n;i++){
q = test %100; /*q makes real time clock work in 60 sec decriments*/
if(q==0){
test = test - 40;
}
key = KeypadReadPort();
x = keys[key];
if(x==30){ /*add 30 seconds during count*/
d4 = test % 10;
d3 = (test / 10) % 10;
d2 = (test / 100) % 10;
d1 = (test / 1000) % 10;
min=(d1*1000)+(d2*100);
sec1=(d3*10)+d4;
n = n + 30;
sec2=(sec1+30)%90;
if(sec2>=60){
min=min+100;
sec1=(sec1+30)%60;
test=sec1+(min);
} else if (sec2<60){
test=test+30;
}
SevenSegWrite(test);
}
test = test - 1; /*count down tick*/
SevenSegWrite(test);
OSTimeDlyHMSM(0, 0, 1, 0);
if(test==0){
for(i=0;i<750;i++){ /*buzzer*/
PTT = PTT | 0x20;
OSTimeDlyHMSM(0,0,0,1);
PTT = PTT & 0xDF;
OSTimeDlyHMSM(0,0,0,1);
}
}
Upvotes: 1