日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]PIC16F84產(chǎn)生兩組PWM輸出的實(shí)例源程序;********************************************************************** list p=16F84 ; list directive to define processor #i nclude <p16F84.inc

ce="Verdana">PIC16F84產(chǎn)生兩組PWM輸出的實(shí)例源程序

;**********************************************************************
 list      p=16F84             ; list directive to define processor
 #i nclude <p16F84.inc>         ; 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  ;
DEF_WORK2 = 8  ;
PORT_OUT = PORTB           ;
PIN_PWM1 = 0               ;
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 ; 
 PWM_WORK_CFG2 ; 
 PWM_WORK_CNT1 ; 
 PWM_WORK_CNT2 ; 
 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 ; 
  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
;**********************************************************************
;**********************************************************************
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'

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉