首先我不懂怎么计算 我是学生初学者 用示波器观察的时候就是看到占空比不断变化 那个表我是在网上随便找一个的现在就是要了解原理 恳求各位大侠教教哦 我还是学生 哦
/*PCA外部中断*/
iph equ 0b7h
epca_lvd equ ie.6
cl equ 0e9h ;pca低8位
ch equ 0f9h ;pca高8位
ccon equ 0d8h ;pca控制寄存器
/*各模块中断标志 */
ccf0 bit ccon.0
ccf1 bit ccon.1
ccf2 bit ccon.2
ccf3 bit ccon.3
ccf4 bit ccon.4
ccf5 bit ccon.5
cr bit ccon.6;允许pca计数必须软件清0
cf bit ccon.7;pca计数溢出
cmod equ 0d9h ;pca工作寄存器
/*pca模块的捕捉高8位 */
ccap0h equ 0fah
ccap1h equ 0fbh
ccap2h equ 0fch
ccap3h equ 0fdh
ccap4h equ 0feh
ccap5h equ 0ffh
/*pca模块的捕捉低8位 */
ccap0L equ 0Eah
ccap1L equ 0Ebh
ccap2L equ 0Ech
ccap3L equ 0Edh
ccap4L equ 0Eeh
ccap5L equ 0Efh
/*pca模块pwm寄存器*/
pca_pwm0 equ 0f2h
pca_pwm1 equ 0f3h
pca_pwm2 equ 0f4h
pca_pwm3 equ 0f5h
pca_pwm4 equ 0f6h
pca_pwm5 equ 0f7h
/*pca工作模式寄存器*/
ccapm0 equ 0dah
ccapm1 equ 0dbh
ccapm2 equ 0dch
ccapm3 equ 0ddh
ccapm4 equ 0deh
ccapm5 equ 0dfh
/*定义mcu管脚*/
led_mcu_start equ p1.7
led_5ms_flash equ p1.6
led_1s_flash equ p1.5
/*给计数器初值18.432mjz*/
channe0_5ms_h equ 1eh
channe0_5ms_l equ 00h; 初值0.05s中断一次
counter equ 30h ;
org 0000h
ajmp main
org 0033h
ljmp pca_interrupt
org 0100h
main: clr p1.7
mov sp,#7fh
mov counter,#0
lcall pca_init
ajmp $
/*初始化pca定时器*/
pca_init:mov cmod,#10000000b;模式寄存器分配
mov ccon,#00h;控制寄存器分配CF CR CCF3~CCF0
mov cl ,#00h ;清pca计数器
mov ch ,#00h
mov ccap1L,#channe0_5ms_l
mov ccap1h,#channe0_5ms_h ;给初值
mov ccapm1,#49h;设置pca0为16位软定时器
mov pca_pwm0,#00h
mov a,#00h
mov ccap0h,a
mov ccap0L,a
mov ccapm0,#42h ;p3.7
setb epca_lvd ;开pca中断标志位
setb ea
setb cr
ret
pca_interrupt:
push acc
push psw
/*5ms中断一次*/
mov a,#channe0_5ms_L
add a,ccap1L
mov ccap1l,a
mov a,#channe0_5ms_h
add a,ccap1h
mov ccap1h,a ;增加计数给ccap0h/L
clr ccf1 ;清标志位
CPL P1.6
mov cl ,#00h ;清pca计数器
mov ch ,#00h
inc counter
mov a,counter
cjne a,#188,siyuan
mov counter,#0
siyuan: MOV DPTR, #table ;查表
MOVC A ,@A+DPTR ;数组送给a
mov ccap0h,a
mov ccap0L,a
mov ccapm0,#42h ;p3.7 /*200*5ms=1000ms=1s*/
pca_exti:
pop psw
pop acc
reti
table:DB 80H,83H,86H,89H,8DH,90H,93H,96H
DB 99H,9CH,9FH,0A2H,0A5H,0A8H,0ABH,0AEH
DB 0B1H,0B4H,0B7H,0BAH,0BCH,0BFH,0C2H,0C5H
DB 0C7H,0CAH,0CCH,0CFH,0D1H, 0D4H,0D6H,0D8H
DB 0DAH,0DDH,0DFH,0E1H,0E3H, 0E5H,0E7H,0E9H
DB 0EAH,0ECH,0EEH,0EFH,0F1H, 0F2H,0F4H,0F5H
DB 0F6H,0F7H,0F8H,0F9H,0FAH, 0FBH,0FCH,0FDH
DB 0FDH,0FEH,0FFH,0FFH,0FFH, 0FFH,0FFH,0FFH
DB 0FFH,0FFH,0FFH,0FFH,0FFH, 0FFH,0FEH,0FDH
DB 0FDH,0FCH,0FBH,0FAH,0F9H, 0F8H,0F7H,0F6H
DB 0F5H,0F4H,0F2H,0F1H,0EFH, 0EEH,0ECH,0EAH
DB 0E9H,0E7H,0E5H,0E3H,0E1H, 0DEH,0DDH,0DAH
DB 0D8H,0D6H,0D4H,0D1H,0CFH, 0CCH,0CAH,0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