View previous topic :: View next topic |
Author |
Message |
deepeshmishra
Joined: 09 May 2014 Posts: 6
|
Timer interrupt for delay |
Posted: Fri May 09, 2014 8:20 am |
|
|
if(!input(TRIG))//////////SINGLE CYCLE AND TRIGGER
{
TIEMPO(); fw(); current_measure();HTO7S(s);
if(s>=r){ do{off(); d5=13;} delay_ms(3000); //wait delay
do{
rw();current_measure();HTO7S(s);
}while((!input(TRIG))&&(input(A_S)));
}
}
Here when i remove input then also it takes delay of 3 sec, please help me to do it with interrupt |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri May 09, 2014 8:52 am |
|
|
Code: |
if(!input(TRIG)){
TIEMPO();
fw();
current_measure();HTO7S(s);
if(s>=r){
do{ // you are stuck HERE <<<
off();
d5=13;
} // no exit !!
delay_ms(3000); //wait delay
do{
rw();
current_measure();
HTO7S(s);
}while((!input(TRIG))&&(input(A_S)));
}
} |
1- the IF (input_trg...) statement has no completing "}"
2- there is NO EXIT condition from your FIRST DO loop
and
3-won't compile as shown due to #1
a fine mess indeed |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19590
|
|
Posted: Fri May 09, 2014 8:59 am |
|
|
Seriously:
1) Learn to write documented and intelligible code.
2) Search the forum. How to do delays with a timer interrupt has been discussed hundreds of times.
3) The code as posted will fail (missing while):
Code: |
if(!input(TRIG))//////////SINGLE CYCLE AND TRIGGER
{
TIEMPO();
fw();
current_measure();
HTO7S(s);
if(s>=r)
{
do
{
off();
d5=13;
} //missing while.....
delay_ms(3000); //wait delay
do
{
rw();
current_measure();
HTO7S(s);
} while((!input(TRIG))&&(input(A_S)));
}
}
|
Since we don't know what anything does, we haven't got any chance of helping you at all...
I see asmboy said the same things while I was posting!... |
|
|
deepeshmishra
Joined: 09 May 2014 Posts: 6
|
|
Posted: Fri May 09, 2014 9:04 am |
|
|
Code: |
void main(){
config();
off(); d5=11; dot_0=0; dot_1=1; dot_2=0; dot_3=0; HTO7S(0); r=0; s=0;
for(;;){
if((!input(P_T_S))&&(input(M_R))&&(input(TRIG)))
{TIEMPO(); off();d5=11; set_measure();HTO7S(r); }
else if((!input(TRIG))&&(!input(A_S)))//////////AUTO REPETE AND TRIGGER
{
TIEMPO();current_measure();HTO7S(s); fw();
if(s>=r){ do{off(); d5=13;} delay_ms(3000); //wait delay "Here I wanted that delay if((input(TRIG)) go to default"
rw();
}
}
else if(!input(TRIG))//////////SINGLE CYCLE AND TRIGGER
{
TIEMPO(); fw(); current_measure();HTO7S(s);
if(s>=r){ do{off(); d5=13;} delay_ms(3000); //wait delay
do{
rw();current_measure();HTO7S(s);
}while((!input(TRIG))&&(input(A_S)));
}
}
else if(!input(M_R))/////////////////MANUAL REVERSE///////////
{
TIEMPO(); rw(); current_measure();HTO7S(s);
}
else ////////////// DEFAULT////////////////////
{
off();d5=11;
dot_0=0,dot_1=1,dot_2=0,dot_3=0;
HTO7S(0);r=0;s=0;
}
if(!input(A_3_6)){set_measure();if (r>300<600){r=300;}} ////if ! (3.5 a )else( 6 a)
else {set_measure();if (r>600){r=600;}}
}//END FOR(;;)
}//END MAIN
|
|
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Fri May 09, 2014 2:12 pm |
|
|
Guys,
I think we are being trolled by the RandomCodeBot |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri May 09, 2014 2:25 pm |
|
|
I get a headache from looking at this code. Sorry to say so, but this is one of the worst programs I have seen in a year on this forum.
There is very little info as to what the program is supposed to be doing and because the variables have no clear names it gets very confusing.
Please try to use variables with meaningful names! d, s, d5, fw, rw, HTO7S. This all makes no sense.
Please put only one command at a line.
Fix your indentation, now lines start at random positions and make reading difficult.
Add more comments about what the lines of code are meant to do. Now you have very little comments, and the comments that are there like 'wait delay' are not helpful. I can see it is a delay! This is comment you can leave out. What I want to know is _why_ you have a delay there.
You didn't fix the syntax error that has been pointed out to you (the missing 'while')
Code: | if (r>300<600){r=300;} | This is not valid C. |
|
|
deepeshmishra
Joined: 09 May 2014 Posts: 6
|
|
Posted: Fri May 09, 2014 10:54 pm |
|
|
thank you ckielstra for your valuable advice, I am new to programming and i will improve it |
|
|
|