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.
Does anybody know how to set 8051 timer to sleep for a few second and then wake up by itself?
in line 27 of the code 8051fx_idle.zip, what does TMOD &= ~0x0F; /* 16-bit, no prescale mode */ mean?
The statement clears the low four bits of the TMOD register, while leaving the upper four bits unchanged. The comment would indicate that this is intended to put timer 0 into 16-bit timer mode, without any prescaling. You could check the manual for the chip to see what clearing those bits really does on this part. According to the documentation for my variant, setting the low two bits of TMOD to 0 makes Timer 0 a 13-bit timer (or 8-bit timer with a 5-bit prescaler, if you prefer). Perhaps this code is correct for an 8051fx, or perhaps the comment is wrong. You'll have to check the documentation to be sure. (And try an experiment yourself really to be certain!)
Well, it probably helps to show the whole section of code so that the comment really makes sense.
/*------------------------------------------------ Setup TIMER0 to generate a regular interupt. ------------------------------------------------*/ TR0 = 0; /* Stop Timer 0 */ TMOD &= ~0x0F; /* 16-bit, no prescale mode */ TMOD |= 0x01; TL0 = 0; /* Set T0 */ TH0 = 0; PT0 = 0; /* Low Priority Interrupt */ ET0 = 1; /* Enable Timer0 Interrupt */ TR0 = 1; /* Start Timer 0 */ EA = 1; /* Enable Global Interrupts */