C51 Manual Calculation Timer Interrupt Introduction

Publisher:心灵的旅程Latest update time:2021-07-07 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The following is calculated by software: 12M crystal oscillator, timer mode 16 bit, 12T, 1 millisecond time

wKiom1Z5P6KzA2uwAAAsu3U3GEY530.png

void Timer0Init(void) //1 millisecond@12.000MHz{
	AUXR &= 0x7F; //Timer clock 12T mode
	TMOD &= 0xF0; //Set timer mode
	TMOD |= 0x01; //Set timer mode
	TL0 = 0x18; //Set the initial timing value
	TH0 = 0xFC; //Set the initial timing value
	TF0 = 0; // Clear TF0 flag
	TR0 = 1; //Timer 0 starts timing}1.2.3.4.5.6.7.8.9.10.


Verify the software's results:                       

The crystal oscillator is 12M, and one oscillation takes (1/12M) seconds.

A machine cycle of a 12T microcontroller is 12 clock cycles (0.000001 seconds).

The time consumed by a 12M crystal oscillator 12T to work in one machine cycle is (1/12M)*12 seconds = 0.000001 seconds = 1 microsecond

The delay requirement is 1 millisecond, which is 1000 microseconds.

The lower 8 bits and the upper 8 bits are 16 bits in total, 65535, which can only hold 65535 microseconds of time.

THX=(65536-1000)/256=252=0xFC

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


【Manual calculation】 Use 11.0592M to delay 20 milliseconds                               


20 milliseconds = 0.02 seconds

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

The cycle used for 0.02 seconds = 0.02/(12/(11.0592*10^6)) = 18432 machine cycles

11.0592M 12T 1 bit 20 milliseconds

TH0=(65536-18432)/256=0xB8

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

The software verifies my calculations:   

wKioL1Z5P8Py7RrxAAArkX__5Ss930.png

void Timer0Init(void) //20 milliseconds @ 11.0592MHz {
	AUXR &= 0x7F; //Timer clock 12T mode
	TMOD &= 0xF0; //Set timer mode
	TMOD |= 0x01; //Set timer mode
	TL0 = 0x00; //Set the initial timing value
	TH0 = 0xB8; //Set the initial value of timing
	TF0 = 0; // Clear TF0 flag
	TR0 = 1; //Timer 0 starts timing}1.2.3.4.5.6.7.8.9.10.



EA---Global enable bit.

EA=1, turn on the global interrupt control. Under this condition, each interrupt control bit determines whether the corresponding interrupt is turned on or off.

EA=0, turn off all interrupts.

   

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

ET2=1, turn on T2 interrupt.              

ET2=0, turn off T2 interrupt.                  


ES---Serial port interrupt enable bit.              

ES=1, turn on serial port interrupt.           

ES=0, turn off serial port interrupt.           



ET1---Timer/Counter 1 interrupt enable bit.     

ET1=1, turn on T1 interrupt.

ET1=0, turn off T1 interrupt.


EX1---External interrupt 1 interrupt enable bit.

EX1=1, turn on external interrupt 1 interrupt.

EX1=0, turn off external interrupt 1.


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

ET0=1, turn on T0 interrupt.

ET0=0, turn off T0 interrupt.


EX0---External interrupt 0 interrupt enable bit.

EX0=1, turn on external interrupt 0 interrupt.

EX0=0, turn off external interrupt 0.


Keywords:C51 Reference address:C51 Manual Calculation Timer Interrupt Introduction

Previous article:C51 WARNING L6: XDATA SPACE MEMORY OVERLAP
Next article:51 single chip microcomputer menu implementation problem

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号