Negative edge trigger interrupt (assembler)

Publisher:心灵清澈Latest update time:2016-09-13 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
 ; Understand the programming method of 8051 timer0 interrupt, use the interrupt method to generate timing, the light is on and off, if an external interrupt occurs, enter the external interrupt service program

COUNT EQU 9217 ;For the crystal oscillator of 11.0592, the delay is 10ms
LED1 EQU P1.1
LED2 EQU P1.3 ;Used as the display of external interrupt 0 
;
               ORG 0000H
               LJMP RESET ;Jump to the initialization program
               ORG 0003H ; INT0 (external interrupt 0)
               LJMP INT_ET0 ;Jump to the external interrupt 0 service program (this program interrupt is entered from here)  
               ORG 000BH ;TIMER0 (timer/counter T0)
               LJMP INT_TIMER0 ;Jump to the timer/counter interrupt service program
               // ORG 0013H ;External interrupt 1   
               // RETI ;Interrupt return instruction
               // ORG 001BH ;TIMER1 (timer/counter T1)
               // RETI
               // ORG 0023H ;Serial port interrupt
               // RETI
;
               ORG 0030H
RESET: MOV R0,#00H
               DJNZ R0,$ ;At the beginning, a small delay is performed to prepare various working registers
  
              SETB LED1
              SETB LED2
  
;Set timer interrupt 
             MOV TMOD,#00000001B
             MOV TH0,#HIGH(65536-COUNT)
             MOV TL0,#LOW(65536-COUNT)
             //MOV TH0,#(65536-COUNT)/256;Get the high eight bits of data
             // MOV TL0,#255 ;Get the bottom five bits (the largest)
             CLR TF0 ;Clear the overflow flag first
             SETB TR0 ;Start timing
             SETB ET0 ;ET0 is the overflow interrupt enable bit of timer/counter T0
;Set external interrupt 0
             SETB IT0 ;Set external interrupt 0 as jump trigger mode
             CLR IE0
             SETB EX0                                                                                                                                             
             SETB EA
             MOV IP,#00000001B; Set PX0 to high priority interrupt (external interrupt 0) 
             MOV R1,#00H; Used as timer accumulator

LOOP: SJMP LOOP ;Wait here
;
;IE0=1

INT_ET0://CLR LED2
            CPL TR0
            //CPL LED1
            ACALL DELAY
            CLR IE0
            CPL LED2
            RETI

;TF0=1  
INT_TIMER0:
            INC R2 ;Increment R1 by one
            CLR TF0 ;CLEAR TF0 AGAIN
            MOV TH0,#(65536-COUNT)/256;Get the high eight bits
            MOV TL0,#255 ;Get the bottom five bits (the maximum)

           CJNE R2,#10,L0; If not equal, transfer instruction, this number can be adjusted
           CPL LED1; Invert instruction
           MOV R2, #00H
L0: RETI

;Delay subroutine, 12M crystal delay is about R4
DELAY: ;Approximate value: 2us*256*256*2=260ms, can also be considered as 250ms
           PUSH PSW ;Site protection instruction (sometimes it can be omitted)
           MOV R4,#4   
L3: MOV R2 ,#00H
L1: MOV R3 ,#00H
L2: DJNZ R3 ,L2 ;Innermost loop: (256 times) 2 cycle instructions (R3 minus one, if greater than 1, turn to L2) 
           DJNZ R2 ,L1 ;Middle loop: 256 times
           DJNZ R4 ,L3 ;Outer loop: 2 times
 
          POP PSW
          RET

          END

Reference address:Negative edge trigger interrupt (assembler)

Previous article:Buzzer control advanced program
Next article:MCU assembly interrupt program (timer interrupt)

Recommended ReadingLatest update time:2024-11-16 14:31

ARM's ADS assembler and GCC assembler
1: An assembly program under ads: __main  EXPORT BootReset  BootReset                 B resetvec_reqset                 IMPORT  BootEntry                 IMPORT  |Image$$RO$$Limit|          AREA  BOOTROM, CODE, READONLY                LDR  r0, =|Image$$RO$$Limit|                BEQ  %1                ldr  pc, The ass
[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号