Assuming the crystal oscillator bit 6MHZ, timing 10ms
SCM System Crystal frequency of 6MHz, the system Clock frequency (also the timing pulse frequency ) is 500KHZ, a pulse period of 2us, 10ms is 5,000 pulses, so
tmod=0x01;
th0= (65536-5000)/256;
tl0= (65536-5000)%256;
Mode 0:13 bit timing counting method, the maximum count value is 2^13=8192, timing 8,192 machine cycle . This method is no longer used, is to be compatible with the previous microcontroller, the beginning of the study do not have to master.
Mode 1:16-bit timing counting method, the maximum count value is 2^16=65536, timing 65,536 machine cycle . This way, the maximum timing time and maximum count times can be achieved. is one of the most common ways.
Mode 2:8-bit automatic reload count mode, the maximum count value is 2^8=256, timing 256 machine cycle . This mode of operation is timed or counted to a high precision without reloading the initial value. In addition, the serial communication is often used in this way. is one of the most common ways.
Mode 3: Special mode of operation. The timer 0 is divided into two 8-bit functions of the timer counter, to occupy the T1 part of the function. Also not used.
Calculation of timer, baud rate, th and TL values