We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
/*hi all.. who can tell me my code right or have any bug? and anyone have better than the function ,but no assembler.*/ main() { /*reset function*/ unsigned char code rst[]={0xe4,0xc0,0xe0,0xc0,0xe0,0x32}; // reset code. (*((void (*)())(rst)))(); // call and run the reset code. } jane
"anyone have better than the function" If you have a watchdog, then far better than any function is just to allow the watchdog timer to expire & apply a hardware reset. That's the only way you can be truly certain that everything has been reset.
thanks Andrew.but you see that: http://www.keil.com/support/docs/307.htm i'm sorry my means:software reset :)
My point still stands, though: the only way to get a fully 100% totally reliable guaranteed complete reset is through a hardware reset; anything you do in software will always leave that possibility that you have missed something - and, due to Murphy's Law, that will always come back to bite you sooner or later. And when it does, it will be an absolute nightmare to debug...
I'd agree with Andrew completely. Why do you want to do a software reset anyway? I can't think of any reason why you would want to do this. Besides, apart from me looking up the opcodes of the machine code, what is your code supposed to do? The instructions as comments would have been most helpful - especially to yourself - what will those bytes mean in 6 months time?? You'll have to look them up again - a little time spent in commenting the code can save much time later on - and it would've helped all those who read your query.
thanks russell... i think of the reset function like the "goto" sentence.it can reset anyway.the keil faq said:You should note that the software reset sequence above does not clear the 8051 interrupt system or reset any 8051 peripherals. When the above code is executed inside an interrupt routine, the 8051 blocks subsequent interrupts. Therefore, this sequence cannot be used in interrupt service routines. and learn the function,you can using like that: ;------------------------------------- main ..... ;------------ ;any address you want to go to the tab address. tab: mov sp,#0xxh ... ret ;-------------- ;in you want to reset segment add like the code mov dptr,#tab push dpl push dph reti ;-------------- ... end
I understand the underlying method. But the question remains: why would you want to do this?? Your method of embedding machine code is fine as long as the byte array is a const and stored in code space. The more accepted method would be to write an assembler file and call that from the 'c' code. At least you could read the instructions rather than a table of bytes that just happens to be machine code.
thanks russell... i know your means.and u method is better than me... but i feel my method is easily,look like the assembler. because i using assembler ever. in the end ,i'm sorry to my poor english and in trouble u. sincerely jane:)