AT89C51 MCU timer terminal mode and query settings

Publisher:sdlg668Latest update time:2015-01-16 Source: 51heiKeywords:AT89C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere


T1 is timing mode, timing 65.536ms, the LED corresponding to P2.0 flashes once, T0 is counting mode, the counting pulse is input from P3.4 pin with a button, one press, one count, so the initial count value is 0FFFFh, no press, an overflow occurs, the LED corresponding to P2.5 flashes, and the digital tube adds 1 to the display.
1. Timer/Counter Terminal Mode
        org 0000h
        ljmp bb; Jump to the main program entry bb
        org 000bh; Timer 0 interrupt response starts here
        cjne r2,#9d,xx       
        mov r2,#00h
        ljmp xx11
        org 001bh; Timer 1 interrupt response starts here
         ljmp xxx

bb: mov p1,#3fh ;at the main program entry
        mov tmod,#05h ;05h=0000 0101B Set T1 timing T0 counting mode, 0 timing, 1 counting
                                      ; 00 is 13-bit binary counting mode 0, the upper 4 bits control T1
                                      ; 01 is 16-bit binary counting mode 1, the lower 4 bits control T0
        mov dptr,#0300h ;store the table entry address
        mov r2,#00h                 
        setb et0 ;same effect as setb 0afh 
        setb ea ;same as setb 0abh
        setb et1 ;same as setb 0a9h
        setb tr0
        setb tr1
       
        mov th0,#0ffh ;The upper 8 bits of the initial count value of counter 0
        mov tl0,#0fdh ;The lower 8 bits of the initial count value of counter 0 (the initial count value for the first time)
        sjmp $ ;When the program is executed, it will wait for the statement in place. When there is no interrupt request,
                                      ;it will count in place at this position and jump to the interrupt entry to execute the interrupt when there is a request
xx: inc r2
xx11: mov th0,#0ffh ;The upper 8 bits of the initial count value of counter 0
           mov tl0,#0fdh ;The lower 8 bits of the initial count value of counter 0 (the initial count value for the second time and after)  
           mov a,r2
           movc a,@a+dptr
           cpl p2.5
           mov p1,a           
           reti
xxx: mov th1,#00h ; the upper 8 bits of the initial count value of counter 1
            mov tl1,#00h ; the lower 8 bits of the initial count value of counter 1
            cpl p2.0
            reti
           org 0300h ; seven-segment display table entry
           db 3fh, 06h, 5bh, 4fh, 66h, 6dh, 7dh, 07h, 7fh, 6fh
          end
2. Timer/Counter Query Mode
          org 0000h
          ljmp bb ; jump to main program entry bb
bb: mov tmod,#15h ; At the main program entry
                                        ; Set T1 timing mode to work in counting mode 0, set T0 counting mode  
                                        to work in counting mode 1
        mov dptr,#0300h ;store the table entry address        
                             
        clr et0 ;turn off timer/counter 0 interrupt
        setb ea ;same as setb 0abh, turn on the general interrupt switch
        setb et1 ;same as setb 0a9h, turn on timer/counter 1 interrupt   
        setb tr0
        setb tr1       
        mov th0,#0ffh ;high 8 bits of the initial count value of counter 0
        mov tl0,#0ffh ;low 8 bits of the initial count value of counter 0 (initial value for the first start of counting)
  CX: JBC TF0, xx ;query the overflow flag of timer/counter 0, if there is overflow, jump to xx to execute
         JBC TF1, xxx ;query the overflow flag of timer/counter 1, if there is overflow, jump to xxx to execute
         sjmp CX ;no overflow, jump to CX to continue querying
   ;overflow occurs when THi and TLi count fully and exceed FFFFH, TFi is automatically set to 1, interrupts and queries are
   responded to based on whether this flag is 1.                         
xx: mov th0,#0ffh ;high 8 bits of counter 0 count initial value
           mov tl0,#0ffh ;low 8 bits of counter 0 count initial value (start counting initial value after the second time)  
           cjne r2,#10d,xx11      
           mov r2,#00h
xx11: mov a,r2
           movc a,@a+dptr ;look up the table and use seven-segment code to display the count number
           cpl p2.5 ;and make the LED on P2.5 have a flashing effect
           mov p1,a ;display the digital effect and output from P1 port
           inc r2 ;add 1 to count  
           ret
xxx: mov th1,#00h ; the high 8 bits of the initial count value of counter 1
           mov tl1,#00h ; the low 8 bits of the initial count value of counter 1
           cpl p2.0 ; t0 timing mode, when the timing is reached, P2.0 is inverted, and the LED achieves a flashing effect
           ret
           org 0300h ; seven segment display table entry
    db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh
          end  
Keywords:AT89C51 Reference address:AT89C51 MCU timer terminal mode and query settings

Previous article:About the use of 51 single chip microcomputer serial port
Next article:Multifunctional electronic clock based on AT89S52 and HD7279A

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号