Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

A simple MC program !!

Status
Not open for further replies.

Peter Nabil

New Member
Hi every single one
I AM GOING CRAZY AGAIN
I wrote this program to check the pin p2.2 , and then output the corresponding action on pin p2.4,
But the problem is the micro controller is working in the real time, by another meaning, when I change the input status the output changes !!
And I am wondering is there no end for this program !!!
I think the microcontroller check the input then make an action, then END.
But in reality it continues looping
Org 0H
Jnb p2.2,Finish
Sjmp Finish
Clr p2.4
Finish:END
 
Peter Nabil said:
Hi every single one
I AM GOING CRAZY AGAIN
I wrote this program to check the pin p2.2 , and then output the corresponding action on pin p2.4,
But the problem is the micro controller is working in the real time, by another meaning, when I change the input status the output changes !!
And I am wondering is there no end for this program !!!
I think the microcontroller check the input then make an action, then END.
But in reality it continues looping
Org 0H
Jnb p2.2,Finish
Sjmp Finish
Clr p2.4
Finish:END
Ofcourse it will loop. What it does is that it will jump to the Finish label, and then it will run series of NOPs until it will reach the end of program memory and wrap around to the ORG 0 again.
To stop it, simply add Goto $ instruction.
 
Peter Nabil said:
Hi every single one
I AM GOING CRAZY AGAIN
I wrote this program to check the pin p2.2 , and then output the corresponding action on pin p2.4,
But the problem is the micro controller is working in the real time, by another meaning, when I change the input status the output changes !!
And I am wondering is there no end for this program !!!
I think the microcontroller check the input then make an action, then END.
But in reality it continues looping
Org 0H
Jnb p2.2,Finish
Sjmp Finish
Clr p2.4
Finish:END

A computer program does what you tell it to do, not what you would like it to do! - there's often a BIG difference.

I've no idea what processor you're using, but you're not stopping the program running at all - so presumably it will run completely through memory and loop back to the satrt and run again?.

If you want the program to 'end' you simply add an andless loop, for a PIC it could be something like this:

Finish: GOTO Finish

Which makes that line loop for ever.
 
Peter Nabil said:
Hi every single one
I AM GOING CRAZY AGAIN
I wrote this program to check the pin p2.2 , and then output the corresponding action on pin p2.4,
But the problem is the micro controller is working in the real time, by another meaning, when I change the input status the output changes !!
And I am wondering is there no end for this program !!!
I think the microcontroller check the input then make an action, then END.
But in reality it continues looping
Org 0H
Jnb p2.2,Finish
Sjmp Finish
Clr p2.4
Finish:END

Since I deal with opcodes instead of text commands, I can't help you much with the arrangement of the code.

If I am right, What happens when the code runs is that you are starting at the beginning (org 0H), and because a bit is not set, you ask the program to go to the end. Once the end is reached, whatever is coded in the chip after the address of the "finish:end" instruction will execute.

What microcontroller do you use?
 
Thanks mstechca, Nigel Goodwin for your support,
Your idea works properly, but I really wonder what's the job of end command ?!!
Is it meaningless?!!!
Thanks a million
 
Peter Nabil said:
Thanks mstechca, Nigel Goodwin for your support,
Your idea works properly, but I really wonder what's the job of end command ?!!
Is it meaningless?!!!
Thanks a million
The END is a Directive, which tells Compiler where user commands end in the ASM file... That's all. MCU won't see it.
 
[quote="Peter Nabil"...but I really wonder what's the job of end command ?!!
Is it meaningless?!!!
Thanks a million[/quote]

To me personally, yes.

To 99.9% of the compilers, no. The END statement typically means thats the end of the code.

But if you are like me and want to force an END statement, simply create a jump statement that goes to itself. A.K.A. an endless loop. LOL

OR

better yet, create a special bit pattern and use logic gates to detect it, and once it is detected, prevent the on-board clock from running, and then the controller shuts down!
 
Status
Not open for further replies.

Latest threads

Back
Top