Introduction to manual calculation of timer interrupts

Source: Internet
Author: User


The following software calculates 12M crystal oscillator, timer mode 16 bit in 12T 1 milliseconds time

void Timer0init (void)//1 ms @12.000mhz{auxr &= 0x7f;//Timer clock 12T mode tmod &= 0xf0;//set timer mode tmod |= 0x01;//set Timer mode TL0 = 0x18;//Set Timing initial value TH0 = 0xfc;//Set Timing initial value TF0 = 0;//Clear TF0 Flag TR0 = 1;//Timer 0 start Timer}


Verify the results of the software:

Crystal oscillator 12M, one Oscillation time is (1/12m) seconds

12T microcontroller One machine cycle is 12 clock cycle 0.000001 seconds

12M Crystal oscillator 12T work a machine cycle consumes time is (1/12m) *12 seconds =0.000001 seconds =1 microseconds

Requires a delay of 1 milliseconds, which is 1000 microseconds

Low 8-bit and high 8 for a total of 16-bit 65535, can only be installed in 65535 microseconds time

thx= (65536-1000)/256=252=0XFC

tlx= (65536-1000)%256 =18=0x18





"Manual calculation" with 11.0592M delay 20 ms


20 milliseconds = 0.02 seconds

One machine cycle time (12/(11.0592*10^6)) seconds

0.02-second Cycle =0.02/(12/(11.0592*10^6)) = 18,432 Machine Cycles

11.0592M 12T 1-bit 20 ms

th0= (65536-18432)/256=0xb8

th0= (65536-18432)%256=0x00

Software to verify my calculations:

void Timer0init (void)//20 ms @11.0592mhz{auxr &= 0x7f;//Timer clock 12T mode tmod &= 0xf0;//set timer mode tmod |= 0x01;// Set Timer mode TL0 = 0x00;//Set Timing initial value TH0 = 0xb8;//Set Timing initial value TF0 = 0;//Clear TF0 Flag TR0 = 1;//Timer 0 start Timer}



The EA---allow bits in the global.

Ea=1, the global interrupt control is turned on, in which case the individual interrupt control bits determine the opening or closing of the corresponding interrupt.

Ea=0, turn off all interrupts.

ET2---Timer/Counter 2 interrupt allow bit.

Et2=1, open T2 interrupt.

Et2=0, close the T2 interrupt.


ES---Serial port interrupt allow bit.

Es=1, open the serial port interrupt.

Es=0, turn off the serial port interrupt.



ET1---Timer/counter 1 interrupt allow bit.

Et1=1, open T1 interrupt.

Et1=0, close the T1 interrupt.


EX1---External interrupt 1 interrupt allow bit.

Ex1=1, open an external interrupt 1 interrupt.

Ex1=0, close the external interrupt 1 interrupt.


ET0---Timer/Counter 0 interrupt allow bit.

Et0=1, open T0 interrupt.

Et0=0, close the T0 interrupt.


EX0---External interrupt 0 interrupt allow bit.

Ex0=1, open an external interrupt 0 interrupt.

Ex0=0, close the external interrupt 0 interrupt.


This article comes from "Life is endless, tossing and turning." "blog, declined reprint!"

Introduction to manual calculation of timer interrupts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.