要製造一個PWM, 2秒一個週期, 要80% HIGH
現在我嘗試加入了2個dealy (Delayl 同Delayh) 加長了時間
我這樣做法有錯誤?
如有請指教
謝謝
#include <sfr51.inc>
F_0 equ 00h
F_1 equ 01h
#define PWMPIN P1.0;
SJMP PWM_SETUP
org 0BH
sjmp TIMER_0_INTERRUPT
LJMP Delayh
PWM_SETUP:
MOV TMOD,#00H ; Timer0 in Mode 0
MOV R7, #204 ;255*0.8=204
SETB EA ; Enable Interrupts
SETB ET0 ; Enable Timer 0 Interrupt
SETB TR0
here:
SJMP here
TIMER_0_INTERRUPT:
JB F_0, HIGH_DONE
LOW_DONE:
SETB F_0
SETB PWMPIN
MOV TH0, R7
LJMP Delayh
CLR TF0
RETI
HIGH_DONE:
CLR F_0
CLR PWMPIN
MOV A, #0FFH
CLR C
SUBB A, R7
MOV TH0, A
LJMP Delayl
CLR TF0
RETI
org 200H
Delayh:
mov R5,#255
D3: mov R3,#255
D2: mov R2,#11
D1: djnz R2,D1
djnz R3,D2
djnz R5,D3
reti
Delayl:
mov R5,#255
D6: mov R3,#255
D5: mov R2,#2
D4: djnz R2,D4
djnz R3,D5
djnz R5,D6
reti
END
此帖出自
小平头技术问答
一周热门 更多>