51 single chip timer works

51 MCU timer working principle and usage

TMOD : Controls how the timer works. 8 bits, the upper four bits control T1, and the lower four bits control T0. Because the timer has 4 modes of operation; TMOD = 0x00 (working mode 0), TMOD = 0x01 (working mode 0), TMOD = 0x02 (working mode 2), TMOD = 0x03 (working mode 3). The above is to control the lower 4 bits, so it corresponds to T0.

TR0: T0 timer enable switch, TR0 = 1, start working; =0 stop working.

ET0: T0 timer interrupt switch, when the timing time is up, it will run to interrupt the program. ET0=1, interrupt enable, 0 disable.

EA: Interrupt the main switch, you can imagine the total switch of the circuit, EA = 1, interrupt enable; =0, interrupt disabled.

TH0, TL0: T0 timer count register, which constitutes 16-bit count, 0x0000--0xFFFF (0--65535), as long as TH0TL0=0xFFFF (65535), the program will run to interrupt the program. In the interrupt program, we want Re-assign TH0, TL0.

If we say that we are timing 50 milliseconds, what value does TH0 and TL0 correspond to? As we said above, TH0, TL0, the 16-bit counter count range is 0---65535. 50ms = 50 000us, we only need to let TH0 TL0 count from (65535 - 50000), TH0, TL0 will continue to +1, until TH0, TL0 = 65535, is counted 50,000 times, the time is over 50ms. We only need to reassign to TH0 in the interrupt program, TL0 = (65535 - 50000), the timer will be interrupted every 50ms.

Therefore, TH0=(65535-50000)/256; TL0 = (65535-50000)%256;

Ok, T0 program example, timing 20ms program:

TO 20ms example program

After finishing the TO, what should I do with T1? I said at the beginning, TO, T1 is a pair of twins. Everyone puts the above T0 example program:

(TMOD = 0x01, ET0, TR0, TH0, TL0, interrput 1)

(TMOD = 0x10, ET1, TR1, TH1, TL1, interrput 3) This becomes the T1, timer program.

ZGAR AZ BOX Vape

ZGAR LEA BOX Vape


ZGAR electronic cigarette uses high-tech R&D, food grade disposable pod device and high-quality raw material. All package designs are Original IP. Our designer team is from Hong Kong. We have very high requirements for product quality, flavors taste and packaging design. The E-liquid is imported, materials are food grade, and assembly plant is medical-grade dust-free workshops.


Our products include disposable e-cigarettes, rechargeable e-cigarettes, rechargreable disposable vape pen, and various of flavors of cigarette cartridges. From 600puffs to 5000puffs, ZGAR bar Disposable offer high-tech R&D, E-cigarette improves battery capacity, We offer various of flavors and support customization. And printing designs can be customized. We have our own professional team and competitive quotations for any OEM or ODM works.


We supply OEM rechargeable disposable vape pen,OEM disposable electronic cigarette,ODM disposable vape pen,ODM disposable electronic cigarette,OEM/ODM vape pen e-cigarette,OEM/ODM atomizer device.



Disposable E-cigarette, ODM disposable electronic cigarette, vape pen atomizer , Device E-cig, OEM disposable electronic cigarette

ZGAR INTERNATIONAL(HK)CO., LIMITED , https://www.zgarvapepen.com