Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/12/07 13:22
Read: times


 
#137031 - initialization sequencing
Responding to: ???'s previous message
but,when i add the code below before set EA=1,the program can run 18 houres without any error,and without the code ,an error will be occured in few houres(sometime less than 1 hour) and cause the MCU died,

if((TF0==1)&&((TI==1)||(RI==1)))

you will never get TF0 if you do not start the timer, so my guess is that your code looks something like this
set T0 L and H to some high value
start timer 0
go do a bit of stuff
execute if((TF0==1)&&((TI==1)||(RI==1)))

you will never get TI unless your UART is running and SBUF is loaded

you will never get RI unless your UART is running and the Rx input 'wiggles'. Often when you have asynchronous power up of the two sides of a serial link you will get a 'false read' when the other end power up and you have the UART running.

What I typically do, after everything else is ready is e.g. SCON = 0x50. That set the mode, REN and kill stray TI and RI. since there shouyld not be any at that time, who cares if those that should not be there are 'killed'

now for the important stuff
if a change in initialization 'fixes' an error will be occured in few houres the issue is regardless of anything else is that you have ignored the first rule of quality programming: good code works even when unexpected events occur.

Your proble clearly indicates that a 'noise character' at startup set the condition for your program to eventually fail.

BEFORE you 'fix' (more correctly, hide) the bug by the above, remove the 'fix' and find out what set up your code to fail. Often it is simple things like an uninitialized pointer that store 'the unexpected character' at a random place.

Erik

List of 10 messages in thread
TopicAuthorDate
two interrupts request at the same time            01/01/70 00:00      
   datasheet            01/01/70 00:00      
      right,but            01/01/70 00:00      
         error? what kind of error?            01/01/70 00:00      
            not reset,in debug PC don't change any more            01/01/70 00:00      
         Sounds like an atomicity problem            01/01/70 00:00      
         Maybe an event gets lost            01/01/70 00:00      
         initialization sequencing            01/01/70 00:00      
            a rare bug....            01/01/70 00:00      
         Interupts            01/01/70 00:00      

Back to Subject List