⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pca2r.asm

📁 用C8051FXX系列单片机的内部硬PCA产生两路不同相位的PWM波
💻 ASM
字号:
; RAM locations to store capture values
CAPTURE 0 DATA 30H
CAPTURE 1 DATA 32H
PHASE DATA 34H
FLAG 0 BIT 20H.0
FLAG 1 BIT 20H.1
;
ORG 0000H
JMP PCA INIT
ORG 0033H
JMP PCA INTERRUPT
;
PCA INIT:
; Same initialization for PCA timer, and interrupt as
; in Listing 1. Initialize two PCA modules as follows:
;
MOV CCAPM0, #21H ; Module 0 capture rising edges
MOV CCAPM1, #21H ; Module 1 same
;
;**************************************************************************************
; Main program goes here
;**************************************************************************************
; This code assumes only Modules 0 and 1 are being used.
PCA INTERRUPT:
JB CCF0, MODULE 0 ; Determine which module's
JB CCF1, MODULE 1 ; event caused the interrupt
;
MODULE 0:
CLR CCF0 ; Clear Module 0's event flag
MOV CAPTURE 0, CCAP0L ; Save 16-bit capture value
MOV CAPTURE 001, CCAP0H
JB FLAG 1, CALCULATE PHASE ; If capture complete on
; Module 1, go to calculation
SETB FLAG 0 ; Signify capture on Module 0
RETI

MODULE 1:
CLR CCF 1 ; Clear Module 1's event flag
MOV CAPTURE 1, CCAP1L
MOV CAPTURE 101, CCAP1H
JB FLAG 0, CALCULATE PHASE ; If capture complete on
; Module 0, go to calculation
SETB FLAG 1 ; Signify capture on Module 1
RETI
;
CALCULATE PHASE:
PUSH ACC ; This calculation does not
PUSH PSW ; have to be completed in the
CLR C ; interrupt service routine
;
JB FLAG 0, MOD0 LEADING
JB FLAG 1, MOD1 LEADING
;
MOD0 LEADING:
MOV A, CAPTURE 1
SUBB A, CAPTURE 0
MOV PHASE, A
MOV A, CAPTURE 101
SUBB A, CAPTURE 001
MOV PHASE01, A
CLR FLAG 0
JMP EXIT
;
MOD1 LEADING:
MOV A, CAPTURE 0
SUBB A, CAPTURE 1
MOV PHASE, A
MOV A, CAPTURE 001
SUBB A, CAPTURE 101
MOV PHASE01, A
CLR FLAG 1
EXIT:
POP PSW
POP ACC
RETI

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -