天堂草原最受欢迎的角色,天堂动漫,天堂在线,色天堂下载,天堂中文在线资源,亚洲男人天堂

技術熱線: 4007-888-234
設計開發

專注差異化嵌入式產品解決方案 給智能產品定制注入靈魂給予生命

開發工具

提供開發工具、應用測試 完善的開發代碼案例庫分享

技術支持

從全面的產品導入到強大技術支援服務 全程貼心伴隨服務,創造無限潛能!

新聞中心

提供最新的單片機資訊,行業消息以及公司新聞動態

PIC16F84單片機產生兩組PWM輸出實例

更新時間: 2019-03-23
閱讀量:1712

十年專注單片機方案開發的方案公司英銳恩,分享PIC16F84單片機產生兩組PWM輸出實例。英銳恩現提供服務產品涉及主控芯片:8位單片機、16位單片機、32位單片機及各類運算放大器等。

list p=16F84 ; list directive to define processor
#include ; 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_WORK2 = 8 ; PWM2
PORT_OUT = PORTB ;
PIN_PWM1 = 0 ; P
PIN_PWM2 = 1 ;
;********************** 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
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 ;
goto ISR_PWM2
bcf PORT_OUT,PIN_PWM1 ; 
ISR_PWM2

decfsz PWM_WORK_CNT2,F ;
goto ISR_EXIT
bcf PORT_OUT,PIN_PWM2 ; 
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 ;
bcf PORT_OUT,PIN_PWM1
bcf PORT_OUT,PIN_PWM2
bcf STATUS,RP0
bsf PORT_OUT,PIN_PWM1 ;
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 ;
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'

联系我们: 武城县| 牙克石市| 平山县| 怀宁县| 太谷县| 天全县| 铜陵市| 新田县| 民丰县| 聂拉木县| 安国市| 巴南区| 苍南县| 池州市| 同江市| 松潘县| 靖安县| 彭阳县| 榆树市| 同仁县| 奉节县| 宜良县| 茶陵县| 西乌| 杭州市| 靖安县| 天柱县| 探索| 漳州市| 开原市| 龙胜| 廊坊市| 禄丰县| 广元市| 济宁市| 开封县| 偏关县| 朝阳县| 遂宁市| 北票市| 合肥市|