Microcontroller timer 0, 1 demonstration program

Publisher:MysticDreamerLatest update time:2022-12-26 Source: zhihu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

//Experimental routine Prawn (DX-51) learning board timer 0, 1 usage routine

#include

#include

//MCU51 embedded professional emulator occupies 3 bytes of program space 0x003b, 0x003c, 0c003d,

//Use the code array declaration to prevent the compiler from locating the function in the program space where this three bytes are located.

unsigned char code DX58[3] _at_ 0x003b;

unsigned char count;

unsigned char direction;

unsigned char delay1;

unsigned char delay2;

void timer0(void) interrupt 1 using 0

{

TL0=0x06;

TH0=delay2;

/* Timer 0 interrupt*/

if (++delay1 > 4){

delay1 = 0;

if (++count > 7) count = 0;

P1 |= 0x0ff;

P1 &= ~(0x01 << count);

}

/* Timer 0 interrupt*/

}

void timer1(void) interrupt 3 using 0

{

TL1=0x06;

TH1=0x00;

/* Timer 1 interrupt*/

if (direction){

if (++delay2 == 128)direction = 0;

}

else {

if (--delay2 == 0)direction = 1;

}

/* Timer 1 interrupt*/

}

// Timer function demonstration program

// P01, P02, P03, P04 pins are connected to the light-emitting diodes led1, led2, led3, led4

// Connect the resistor on each LED string to the 5V power supply and run this demonstration program

// You will see the light-emitting diodes light up and go out in sequence, which is more beautiful than the colorful lights on the street.

// There are too many. If you don’t believe me, try it.

void main(void){

ET0 = 1; /* Allow timer 0 interrupt*/

ET1 = 1; /* Allow timer 1 interrupt*/

TMOD = 0x11; /* Timer working mode selection*/

TL0 = 0x06;

TH0 = 0x00; /* Assign initial value to timer*/

TL1 = 0x06;

TH1 = 0x00; /* Assign initial value to timer*/

TR0 = 1; /* Start timer*/

TR1 = 1; /* Start timer*/

EA = 1; /* Turn on total interrupt */

delay2 = 0;

direction = 1;

while(1){

_nop_ (); /* delay for hardware */

}

}


Reference address:Microcontroller timer 0, 1 demonstration program

Previous article:51 microcontroller external interrupt processing source program
Next article:Timer function demonstration program

Recommended ReadingLatest update time:2024-11-16 13:42

CC2530 bare metal programming series notes 1--Timer Timer1 mode programming
Timer/counter is one of the important resources of single-chip microcomputer, and the timer/counter of CC2530 has more working modes compared with the ordinary 51 series single-chip microcomputer. According to the study manual, CC2530 timer/counter has three working modes, namely free mode, modular mode and up/down co
[Microcontroller]
CC2530 bare metal programming series notes 1--Timer Timer1 mode programming
8-inch wafer foundry is in short supply, and the price is reportedly increased by 10%
According to Taiwan media Central News Agency, the 8-inch wafer foundry capacity is in short supply. Not only has the delivery time been extended to 4 months, but the quotation is also reported to increase by 10%. Some IC design factories have decided to follow suit and increase product prices to cope with the cost in
[Mobile phone portable]
Feixiang Technology completes over RMB 100 million in B+ round of financing to increase R&D of 5G RF chip products
According to 36Kr, Shenzhen Feixiang Technology Co., Ltd. completed a B+ round of financing with a scale of more than 100 million yuan. This round of financing was led by CICC Capital and Yuanhe Houwang. Long Hua, Chairman and CEO of Feixiang Technology, said that through this round of financing, Feixiang has obtain
[Mobile phone portable]
Researchers use graphene to make supercapacitors that retain 90% capacity after 10,000 charge and discharge cycles
According to foreign media reports, a collaborative team at the Technical University Munich (TUM) in Germany has developed an ultra-efficient supercapacitor. The energy storage device is based on a novel, powerful and sustainable graphene hybrid material, and its performance data is comparable to that of currently use
[Automotive Electronics]
Researchers use graphene to make supercapacitors that retain 90% capacity after 10,000 charge and discharge cycles
Samsung S22 Ultra decrypted: 1TB version costs over 10,000 yuan
      Currently, iPhone 13 Pro and iPhone 13 Pro Max are available in 1TB versions, priced at 11,999 yuan and 12,999 yuan respectively.   On January 17, according to LetsGoDigital, Samsung will also launch a 1TB version of its high-end flagship Galaxy S22 Ultra.   According to reports, the Samsung Galaxy S22 Ultra has
[Mobile phone portable]
stm32 about BOOT0 and BOOT1
BOOT0 and BOOT1 The storage media corresponding to the three boot modes of STM32 are all built-in to the chip, which are: 1) User Flash = Flash built into the chip. 2) SRAM = RAM area built into the chip, which is the memory. 3) System Memory = A specific area inside the chip. A Bootloader is preset in this area wh
[Microcontroller]
Overview of Three-Phase Power Factor Correction (PFC) Technology (1)
Abstract: The development status of three-phase power factor correction circuits is reviewed, and typical topologies are analyzed and compared. Keywords: three-phase rectifier; harmonics; power factor correction 1 Introduction In the past 20 years, power electronics technology has developed rapidly
[Power Management]
Overview of Three-Phase Power Factor Correction (PFC) Technology (1)
"Zhihuijun" resigns from Huawei and launches his first startup product, Zhiyuan Robotics' "Yuanzheng A1"
On August 18, Zhihuijun, who joined Huawei as a "genius boy", announced his resignation at the end of last year to start his own business, Zhiyuan Robotics. More than half a year later, he brought his first product - Zhiyuan Robotics Expedition A1. In the live broadcast of the press conference this morning, Zhi
[robot]
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号