#include<reg51.h> sbit op1=P0^0; sbit op2=P0^1; sbit op3=P0^2; sbit op4=P0^3; int c; void delay(void)//delay .5 second { int d; for(d=0;d<10;d++) { TF1=0;//clear overflow flag TL1=0xB0; TH1=0x3C; TR1=1; //start timer while(TF1==0) TR1=0; //stop timer } } void intr1(void) interrupt 2 //external interrupt1 function { EX1=0; //disable all interrupts TH0=0x00; //reset counter TL0=0x00; TR0=1; //start counter delay(); TR0=0; //stop counter c=TL0; //store count EX1=1; //enable all interrupts } void main() { TMOD=0x25; //initialize T0 as 16bit counter and T1 as 16bit timer IE=0x84; //enable external interrupt 1 if((c>=0x73)&&(c<=0x7D)) { if(op1==0) { op1=1; } else { op1=0; } } else if((c>=0x5F)&&(c<=0x69)) { if(op2==0) { op2=1; } else { op2=0; } } else if((c>=0x4B)&&(c<=0x55)) { if(op3==0) { op3=1; } else { op3=0; } } else if((c>=0x37)&&(c<=0x41)) { if(op4==0) { op4=1; } else { op4=0; } } }
Saw this and thought OMG.
To the OP:
If the program does what you want it to do, then it could be considered correct.
I doubt it does what you want it to do though.
Here is a readable version:
when you ask if this program is right, the answer is simple: no it is not -or- yes it is. This all depends upon what you want to do.
If this code is supposed to control a satellite's solar panels, I'd say its wrong.
People should be clear on what it is they intend to do and not just post code.
--Cpt. Vince Foster 2nd Cannon Place Fort Marcy Park, VA
It is similar to this: "Is this right?"
2.5v | | +5v _____/\/\/\/\/\__*__/\/\/\/\_____ GND 20k 20k
Some people would say yes. But if it is supposed to be a motion controller with PID capability, the answer is NO!
It returns from main() - which is almost certainly not correct!
With all due respect Andy, that might be exactly what the project requires... as stupid as that might be.
Yes - that's why I said "almost certainly"
As you say, it is possible (though unlikely) that that this is, indeed, the intended behaviour.
As you said originally, it is impossible to say whether it's "correct" or not without having a proper definition of "correct" - or, indeed, any indication whatsoever of what the program is actually supposed to do!
Just as well the OP didn't ask for comments on the code ... It would have been quite a long list.
In my opinion the return from main is just a minor!