How to use the timer counter of C51 microcontroller?

Publisher:脑电狂潮Latest update time:2016-12-14 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

There are many methods, here is one for you, you can debug it, you can use different crystals to calculate the initial value of the timer, if you understand the timer part, it is very easy to adjust
#include 
sbit p1_0=P1^0; 
int i; //global variable

void timing(void) //the crystal is 3.6864M
{
   TMOD|=0x01; //timer T0, working mode 1
   TH0=0xC3;
   TL0=0xC7; //these two registers store the starting value of the counter, these two values ​​are accumulated to overflow, it is exactly 50ms
   ET0=1; //enable T0 interrupt to overflow
   EA=1; //enable total interrupt
   TF0=0; //clear overflow bit
   TR0=1; //enable T0
}
/********timing interrupt function************/
void time0_int () interrupt 1 //timing interrupt function

   TH0=0xC3; 
   TL0=0xC7; 
   i++;
}

main()
{
  i=0;
  timing();
  while(;)
  {
    if(i==20)
    {
       p1_0=~p1_0; //p1.0 port status flip
        i=0;
     }
  }
}

Keywords:C51 Reference address:How to use the timer counter of C51 microcontroller?

Previous article:iic standard code (real universal code 1161)
Next article:Counter of single chip microcomputer C51

Recommended ReadingLatest update time:2024-11-16 19:30

Proteus C51 simulation learning board 7——LCD1602
LCD1602 is the most basic character LCD display, which can display 16x02=32 characters. So the operation of timing - reading and writing is the most important content. Today, I will take you to read the timing. Before looking at the timing diagram, you need to understand the pin functions of the LCD to better unders
[Microcontroller]
Proteus C51 simulation learning board 7——LCD1602
MCU C Language Tutorial: C51 Variables
The variable mentioned in class is a quantity whose value can change continuously during the execution of a program. To use a variable in a program, you must first use an identifier as the variable name and indicate the data type and storage mode used, so that the compiler system can allocate the corresponding stora
[Microcontroller]
Design of floating point numbers and assembly program for C51 single chip microcomputer
In the data processing process of the single-chip microcomputer application system, decimal calculation problems are often encountered, such as solving the incremental formula of BCD, linearization processing, etc. Therefore, it is necessary to use binary numbers to represent decimals. There are generally two ways to r
[Microcontroller]
C51: write n data to 24C02, and then read n data
//Function function, //Write n data, then read n data. Display with LCD1602. #include reg51.h #include intrins.h   //Variable declaration #define uchar unsigned char #define uint unsigned int //Delay 1ms void delayms() {  uchar i;  for(i=0;i 250;i++);  for(i=0;i 80;i++); } void delaynms(uint s) {
[Microcontroller]
c51 1ms-6MHZ delay program
#include void delay(unsigned char n) //about n(ms) delay { unsigned char i,j,k;   for(k=0;k n;k++)     {       for(j=0;j 5;j++) //about 1ms delay        {          for(i=0;i 31;i++) //about 0.1ms delay            {;}         }      }  } main() {  while(1)     {       delay(15);      } }    /*Abo
[Microcontroller]
About the code in C51 idata data bdata pdata xdata
In terms of data storage type, the 8051 series has on-chip and off-chip program memory, on-chip and off-chip data memory. The on-chip program memory is also divided into direct addressing area and indirect addressing type, corresponding to code, data, xdata, idata and pdata type set according to the characteristics of
[Microcontroller]
Using STM32's TIMER for external counting
Use the input signal of the ETR pin as the counting clock. This example uses Timer 2, whose ETR input pin is PA1. The working mode of this pin is input. Input mode, Timer working mode is slave mode; in addition, use PC6 to output an analog square wave clock signal. When testing, short-circuit PC6 and PA1. (Yo
[Microcontroller]
C51 microcontroller watchdog program optimization design analysis
With the development of the economy, the continuous extension of science and technology has been promoted, and the microcontroller of the C51 system has also been continuously developed, which greatly meets the needs of practical work, but also inevitably brings some disadvantages. For example, the anti-interference p
[Microcontroller]
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号