Timer 0 working mode 3

Publisher:BlissfulDreamsLatest update time:2020-10-09 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

image

At this time, there are separate interrupts when the lower 8 bits and the upper 8 bits overflow


tl0 occupies T0


th0 occupies T1


The two counters are independent


/*

   Program function: timer0 verification program

   Version: v1

   Creation date: 2013.9.18

   creator:

 */

$NOMOD51 //Cancel the use of 51 internal default SFR

#include "REG8F301.INC"

dseg at 30h //General RAM byte segment starts at 30H


iseg at 80h //0-ffh address RAM segment 80h-ffh segment RAM can only be operated using indirect addressing


cseg at 0

        org 0000h

        jmp Start

        org 000bh

        jmp Timer0_Isr

        org001bh

        jmp Timer_Isr //TH0 is now occupying timer 1

        org 0030h

start:

        mov r0,#0x7f

ClrRam: //Clear internal 256Byte RAM

        mov @r0,#0

        djnz r0,ClrRam    

        mov dptr,#0x00 //Clear external 768Byte RAM

ClrOutRam:

        mov a,#0x00 //Write all 0x00 to external RAM

        movx @dptr,a

        inc dpl

        mov a,dpl

        cjne a,#0,ClrOutRam

        inc dph

        mov a,dph

        cjne a,#3,ClrOutRam 

SetTimer0:                                         

        mov tmod,#03h //Timer 1 works in mode 1

        mov th0,#HIGH(256-100)

        mov tl0,#LOW(256-100)

        setb tr0 //Start timer 0 counting

        setb et0 //Enable timer 1 interrupt

        setb tr1 //Start timer 1 counting

        setb et1 //Enable timer 1 interrupt

        setbea

main:    

        ljmp main


Timer0_Isr:

    push acc

    push psw

    mov tl0,#LOW(256-100)

    nop

    nop

    pop psw

    pop acc

    reti

Timer_Isr:

    push acc

    push psw

    mov th0,#LOW(256-100)

    nop

    nop

    pop psw

    pop acc

    reti

    end


Reference address:Timer 0 working mode 3

Previous article:Usage of R8051XC2 Timer 2
Next article:C51 MCU interrupt number and interrupt vector

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号