Timer counting experiment

Publisher:糖三角Latest update time:2016-12-20 Source: eefocusKeywords:Timer Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include
typedef unsigned char u8;
typedef unsigned int u16;
sbit led = P1^0;
u8 timer;
void main (void)
{
    TMOD = 0x01; //Set TMOD to make T0 work in 16-bit timing.
    TH0 = (65535-50000) / 256;
    TL0 = (65535-50000) % 256;
    EA = 1; //Open the total interrupt
    ET0 = 1; //Open the overflow interrupt of timer 0
    TR0 = 1; //Start timing
    while(1) //The function is to end the program, otherwise the program will keep running here;
    {
        ;
    }
}
//Implementation method 1
void timer0_service(void) interrupt 1
{
    TH0 = (65535-50000) / 256;
    TL0 = (65535-50000) % 256;    
    //50ms has been set
    timer ++;
    if (timer == 20)
    {
        timer = 0;
        led = ~led;
    }
}

 

/**************************** Stay hungry, Stay foolish. @Rocky**************** **********/


Keywords:Timer Reference address:Timer counting experiment

Previous article:Talking about static digital tube
Next article:External interrupt experiment

Recommended ReadingLatest update time:2024-11-15 16:39

MCU timer working mode 0 (timer013 bit timer)
;Timer 0 working mode 0 (13-bit timer), P1.1 port is connected to the common anode LED lamp, the result of the operation is to make the LED light bright and dark ; Timing COUNT EQU 5000; Timing can only be 5ms LED EQU P1.1   ORG 0000H           MOV R0,#00H L0: DJNZ R0,L0 ;At the beginning, a small delay is perfo
[Microcontroller]
stm8s development (V) Use of TIMER: timing!
STM8S provides three types of TIM timers: advanced control type (TIM1), general type (TIM2/TIM3/TIM5) and basic timer (TIM4/TIM6). Although they have different functions, they are all based on a common architecture. This common architecture makes it very easy and convenient to design applications using various timers
[Microcontroller]
stm8s development (V) Use of TIMER: timing!
STM32 Timer1 TIM1 interrupt
/*Timer 1ms interrupt, dead wait timer delay*/ /*File Timer.c */ #include "stm32f10x.h"     unsigned int TimeDelay = 0; void TIM1_Configuration(void) {   NVIC_InitTypeDef NVIC_InitStructure; TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;   TIM_DeInit(TIM1); /*Reset TIM1 timer*/ RCC_APB2PeriphClockCmd(RCC_APB2Perip
[Microcontroller]
The TIMER2 timer cannot enter the interruption problem
The pin package diagram of STM8S103 is as follows It is a 20-pin 51-type microcontroller with 8K flash and 1k RAM. The STM8S207 pin package is as follows A 48-pin 64KFLASH and 6K RAM, also a 51 microcontroller, but with more functions such as serial port and timer. From the manual, timer1 is an ADVANCED timer,
[Microcontroller]
The TIMER2 timer cannot enter the interruption problem
PIC timer1 timer
Function: Use Timer1 to delay the LED light to flash in a cycle Requirements: MPLAB 8.2 or above, a MEO engineering board, PIC16-MCD2 simulation download, Chip configuration word, watchdog off, power-on delay on, power-off detection off, low voltage programming off, 4MXT mode oscillation  */ #include pic18.h int mai
[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号