PIC16F84产生两组PWM输出的实例源程序

pic16f84产生两组pwm输出的实例源程序
;**********************************************************************
list p=16f84 ; list directive to define processor
#i nclude ; processor specific variable definitions
__config _cp_off & _wdt_off & _pwrte_off & _rc_osc
; '__config' directive is used to embed configuration data within .asm file.
; the lables following the directive are located in the respective .inc file.
; see respective data sheet for additional information on configuration word.
;********************** const definitions******************************
full_work = 10 ; 程?㏄戳箇砞?
def_work1 = 2 ; pwm1㏄戳箇砞?
def_work2 = 8 ; pwm2㏄戳箇砞?
port_out = portb ; pwm块?梆
pin_pwm1 = 0 ; pwm1块?竲?
pin_pwm2 = 1 ; pwm2块?竲?
;********************** variable definitions***************************
cblock 0x0c
w_temp ; variable used for context saving
status_temp ; variable used for context saving
pwm_full ; 程?㏄戳璸计竟(?计)
pwm_work_cfg1 ; pwm1 ㏄戳砞﹚既?竟
pwm_work_cfg2 ; pwm2 ㏄戳砞﹚既?竟
pwm_work_cnt1 ; pwm1 ㏄戳璸计竟(?计)
pwm_work_cnt2 ; pwm2 ㏄戳璸计竟(?计)
endc
;**********************************************************************
;****************** 垂竚?祘α秈?翴 ***********************
;**********************************************************************
org 0x000 ; processor reset vector
resetstart
goto main ; go to beginning of program
;**********************************************************************
;****************** い耞狝叭祘α秈?翴 *************************
;**********************************************************************
org 0x004 ; interrupt vector location
movwf w_temp ; save off current w register contents
movf status,w ; move status register into w register
movwf status_temp ; save off contents of status register
bsf status,rp0
bcf intcon,t0if ; 睲埃璸?竟い耞篨腹
bcf status,rp0
decfsz pwm_full,f ; 浪琩琌?чθ㏄戳
goto isr_pwm1
bsf port_out,pin_pwm1 ; pwm1/pwm2?確high筿?
bsf port_out,pin_pwm2
movlw full_work ; ?穝砞﹚?㏄戳璸计竟
movwf pwm_full
movf pwm_work_cfg1,w
movwf pwm_work_cnt1
movf pwm_work_cfg2,w
movwf pwm_work_cnt2
goto isr_exit
isr_pwm1
decfsz pwm_work_cnt1,f ; 浪琩pwm1㏄戳
goto isr_pwm2
bcf port_out,pin_pwm1 ; ㏄戳挡盢块?砞?low筿?
isr_pwm2
decfsz pwm_work_cnt2,f ; 浪琩pwm2㏄戳
goto isr_exit
bcf port_out,pin_pwm2 ; ㏄戳挡盢块?砞?low筿?
isr_exit
movf status_temp,w ; retrieve copy of status register
movwf status ; restore pre-isr status register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr w register contents
retfie ; return from interrupt
;**********************************************************************
;****************** ?﹍てpwm *******************************
;**********************************************************************
initpwm
bsf status,rp0 ; 砞﹚pwm1/pwm2竲?块?
bcf port_out,pin_pwm1
bcf port_out,pin_pwm2
bcf status,rp0
bsf port_out,pin_pwm1 ; 箇砞pwm1/pwm2块?蔼筿?
bsf port_out,pin_pwm2
movlw full_work ; 砞﹚?既?竟ぇ箇砞?
movwf pwm_full
movlw def_work1
movwf pwm_work_cfg1
movwf pwm_work_cnt1
movlw def_work2
movwf pwm_work_cfg2
movwf pwm_work_cnt2
retlw 0
;**********************************************************************
;****************** ?﹍て璸?竟 *******************************
;**********************************************************************
inittimer
bsf status,rp0
bsf option_reg,t0cs ; 氨ゎ?历竟?猧块?
bsf option_reg,psa ; 砞﹚ぃㄏノ?猧箇埃竟
bsf intcon,gie ; ゴ秨?办い耞秨闽(い耞羆秨闽)
bcf intcon,t0if ; 睲埃璸?竟い耞篨腹
bcf status,rp0
retlw 0
;**********************************************************************
;****************** 币笆璸?竟 *******************************
;**********************************************************************
starttimer
bsf status,rp0
bcf option_reg,t0cs ; 砞﹚?历竟?猧块?(1/4 osc)
bsf intcon,t0ie ; ゴ秨璸?竟い耞
bcf status,rp0
retlw 0
;**********************************************************************
;****************** 氨ゎ璸?竟 *******************************
;**********************************************************************
stoptimer
bsf status,rp0
bsf option_reg,t0cs ; 氨ゎ?历竟?猧块?
bcf intcon,t0ie ; 闽?璸?竟い耞
bcf status,rp0
retlw 0
;**********************************************************************
;****************** ?祘α秈?翴 *******************************
;**********************************************************************
main
bcf status,rp0 ; select page 0 for port access
call initpwm
call inittimer
call starttimer
goto $
;**********************************************************************
end ; directive 'end of program'

SPI总线工作过程及传输方式分析
为什么要重视电源噪声
机器人技术研发与专利分析
Trinamic完美替代TI DRV型号大全
上汽智能驾驶版图:5G、车联网、地图一个都不少
PIC16F84产生两组PWM输出的实例源程序
物联网RFID技术及应用场景
iphone8什么时候上市?iphone8最新消息汇总:iphone8原型机曝光,无实体实体Home键,指纹识别会放侧面?
三星Galaxy Tab S6 5G平板今年第一季度在韩国市场推出
浅谈线对板连接器中的贴片连接器
LED防爆灯要注意哪一些问题
对于面板对地绝缘阻抗过低的问题的应对和分析
科大讯飞是否能抓住人工智能的东风?
高速交流电力测功机原理及特点
家用手持吸尘器什么牌子好?超越戴森没话说!
地物光谱仪在地球资源研究中的应用
DC-DC降压芯片48V转12V600MA芯片AH8672A
功率半导体市场的状况 增长势头过于强劲
华为签下中东5G大单  华为麒麟9000成为中移动智能硬件榜单No1
阿童木助力广东某企业实现不锈铁片材单双张检测