P89LPC932A1 pulse width measurement assembly program

Publisher:心境恬淡Latest update time:2018-04-12 Source: eefocusKeywords:P89LPC932A1 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/********************CCU_Capture.asm***************************
;Program function: Capture each level jump of a square wave, and use the captured value to calculate
the pulse width, duty cycle, period or other of the square wave.
;****************************************************************/

$NOMOD51
$INCLUDE(REG932.INC)


ICRAH_DAT1 DATA 41H ; High byte of the first capture value
ICRAL_DAT1 DATA 42H ; Low byte of the first capture value
ICRAH_DAT2 DATA 43H ; High byte of the second capture value
ICRAL_DAT2 DATA 44H ; Low byte of the second capture value
ICRAH_DAT3 DATA 45H ; High byte of the third capture value
ICRAL_DAT3 DATA 46H ; Low byte of the third capture value

CAP_FLAG1 BIT 10H ; first capture flag
CAP_FLAG2 BIT 11H ; second capture flag

KEY  BIT P0.0

  ORG 0000H
  AJMP MAIN
  ORG 005BH
  AJMP CCU_ISR
;---------------------------------------
;Function: Main function
;---------------------------------------
  ORG 0080H
MAIN:
  MOV P2M1,#40H ;Port setting
  MOV P2M2,#40H

  MOV ICRAL_DAT1,#00H
  MOV ICRAH_DAT1,#00H
  MOV ICRAL_DAT2,#00H
  MOV ICRAH_DAT2,#00H
  MOV ICRAL_DAT3,#00H
  MOV ICRAH_DAT3,#00H 
MAIN_LOOP: 
  JB KEY,$ ;Wait for the key to
  be pressed JNB KEY,$ ;Wait for the key to be released
  ACALL INI_CCU ;Initialize CCU and set interrupt
  ACALL DISP ;Output the captured value to display
  SJMP MAIN_LOOP
  RET
;--------------------------------------
;Function: CCU initialization
;--------------------------------------
INI_CCU:
  MOV TOR2H,#00H ;Set CCU to reload high byte
  MOV TOR2L,#00H ;Set CCU to reload low byte
  MOV TPCR2H,#00H ;Set CCU pre- scaling controller
  MOV TPCR2L,#5
 
  MOV CCCRA,#10H ;Set the capture comparison channel A working mode to rising edge capture
  MOV TICR2,#81H ;Set CCU interrupt enable controller
  SETB ECCU ;Open CCU interrupt
  SETB EA ;Open all interrupts
  MOV TCR20,#00000001B ;Set CCU working mode, increment count
  RET
;--------------------------------------
;Function: CCU interrupt service routine
;--------------------------------------
CCU_ISR:
  CLR EA

  MOV A,TISE2
  ANL A,#07H
  CJNE A,#07H,CAP ;Judge whether it is CCU timer interrupt
  ANL TIFR2,#7FH ;If yes, clear TIFR2 (interrupt flag) to 0
  MOV A,TISE2 
CAP: CJNE A,#06H,INTS_CEXT ;Judge whether it is the interrupt of input capture event A, if not, exit
  JB CAP_FLAG1,CAP2 ;Judge whether it is the second interrupt, if yes, jump
;------------------
CAP1:
  PUSH ACC
  MOV A,ICRAL
  MOV ICRAL_DAT1,A
  MOV A,ICRAH
  MOV ICRAH_DAT1,A
  SETB CAP_FLAG1 ;The first capture interrupt is completed
  MOV CCCRA,#00H ;Set the capture compare A channel working mode to falling edge capture
  POP ACC
  AJMP INTS_CEXT
;------------------
CAP2: 
  PUSH ACC
  JB CAP_FLAG2,CAP3 ; Check if it is the third interrupt? If yes, jump to CAP3.
  MOV A,ICRAL ; Save the value captured for the second time
  MOV ICRAL_DAT2,A
  MOV A,ICRAH
  MOV ICRAH_DAT2,A

  SETB CAP_FLAG2 ;The second capture interrupt is completed
  MOV CCCRA,#10H ;Set the capture comparison channel A working mode to rising edge capture
  POP ACC
  AJMP INTS_CEXT
;-------------------
CAP3:
  MOV TCR20,#00H ;Stop CCU timer counting
  PUSH ACC
  MOV A,ICRAL ;Save the third capture value
  MOV ICRAL_DAT3,A
  MOV A,ICRAH
  MOV ICRAH_DAT3,A

  CLR CAP_FLAG1 ; Clear capture completion bit
  CLR CAP_FLAG2
  POP ACC
; AJMP INTS_CEXT
;------------------------
INTS_CEXT:
  MOV TIFR2,#00H ; Clear capture interrupt flag bit to 0
  SETB EA
  RETI
;-------------------------------------
; Function: Please add your data processing program here
;-------------------------------------
DISP:
  ;...... Please add your own statement here, for example, high level pulse width = (ICRAH_DAT2, ICRAL_DAT2)-(ICRAH_DAT1, ICRAL_DAT1)
  ;...... Process the obtained data to obtain the required value
  ;...... and display or transmit it to the host computer

  RIGHT
;-----------------------------------
  END 
;*********** ****************************************************** *****


Keywords:P89LPC932A1 Reference address:P89LPC932A1 pulse width measurement assembly program

Previous article:Making good use of microprocessors to simplify power supply design
Next article:Design of signal acquisition node based on P87C591 single chip microcomputer

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号