Четверг, Сентябрь 24, 2020

Генератор импульсов

 

 

 

 

            LIST        P=16F628A
            INCLUDE     P16F628A.INC
            __CONFIG    _INTOSC_OSC_NOCLKOUT&_WDT_OFF&_PWRTE_ON&_MCLRE_OFF&_LVP_OFF&_CP_OFF
            ERRORLEVEL  -302
            CBLOCK      20H
            CCP1TMPL
            CCP1TMPH
            W_TEMP
            STATUS_TEMP
            ENDC
BANK0       MACRO
            BCF         STATUS,RP0
            BCF         STATUS,RP1
            ENDM
BANK1       MACRO
            BSF         STATUS,RP0
            BCF         STATUS,RP1
            ENDM
            ORG         0
            GOTO        START
            ORG         4
            GOTO        ISR
START       MOVLW       7
            MOVWF       CMCON
            CLRF        PORTB
            CLRF        PORTA
            BANK1
            CLRW
            MOVWF       TRISB
            BANK0
            MOVLW       B'11111111'
            MOVWF       CCP1TMPL
            MOVLW       B'11111111'
            MOVWF       CCP1TMPH
            CLRF        TMR1L
            CLRF        TMR1H
            MOVLW       B'00110001'
            MOVWF       T1CON
            MOVLW       B'00001000'
            MOVWF       CCP1CON
            
MAIN
LOOP        BTFSS       PIR1,CCP1IF
            GOTO        LOOP
            BTFSC       PORTB,3
            GOTO        CLEAR
            CLRF        CCP1CON
            MOVFW       CCP1TMPL
            MOVWF       CCPR1L
            MOVFW       CCP1TMPH
            MOVWF       CCPR1H
            MOVLW       B'00001000'
            MOVWF       CCP1CON
            CLRF        TMR1H
            CLRF        TMR1L
            BCF         PIR1,CCP1IF
            GOTO        MAIN
            
CLEAR       CLRF        CCP1CON
            MOVFW       CCP1TMPL
            MOVWF       CCPR1L
            MOVFW       CCP1TMPH
            MOVWF       CCPR1H
            MOVLW       B'00001001'
            MOVWF       CCP1CON
            CLRF        TMR1H
            CLRF        TMR1L
            BCF         PIR1,CCP1IF
            GOTO        MAIN
                   
ISR         MOVWF       W_TEMP
            SWAPF       STATUS,W
            BCF         STATUS,RP0
            MOVWF       STATUS_TEMP   
                     
EXIT_ISR    SWAPF       STATUS_TEMP,W
            MOVWF       STATUS
            SWAPF       W_TEMP,F
            SWAPF       W_TEMP,W
            RETFIE
TABLE       ADDWF       PCL,F
            RETLW       0
            END

 

 

 

 

 ;Генератор с кнопкой на RA4

            LIST        P=16F628A
            INCLUDE     P16F628A.INC
            __CONFIG    _INTOSC_OSC_NOCLKOUT&_WDT_OFF&_PWRTE_ON&_MCLRE_OFF&_LVP_OFF&_CP_OFF
            ERRORLEVEL  -302
            CBLOCK      20H
            CCP1TMPL
            CCP1TMPH
            TMP
            J
            K
            ENDC
BANK0       MACRO
            BCF         STATUS,RP0
            BCF         STATUS,RP1
            ENDM
BANK1       MACRO
            BSF         STATUS,RP0
            BCF         STATUS,RP1
            ENDM
            ORG         0
            GOTO        START
START       MOVLW       7
            MOVWF       CMCON
            CLRF        PORTB
            CLRF        PORTA
            BANK1
            CLRW
            MOVWF       TRISB
            BSF         TRISA,4               ;кнопка
            BANK0
            MOVLW       B'11111111'
            MOVWF       CCP1TMPL
            MOVLW       B'11111111'
            MOVWF       CCP1TMPH
            CLRF        TMR1L
            CLRF        TMR1H
            MOVLW       B'00110001'
            MOVWF       T1CON                    ;настройка таймера 1
            MOVLW       B'00001000'      ;настройка блока сравнения и совпадения курим даташит
            MOVWF       CCP1CON

;############################## осносной цикл программы #######################
MAIN        
            CALL        LOOP
            BTFSS       PORTA,4                 ;кнопка нажата?
            CALL        BUTTON
            GOTO        MAIN     

;############################################################################

LOOP        BTFSS       PIR1,CCP1IF        ;было совпадение?
            GOTO        LOOP
            BTFSC       PORTB,3                  ;на выходе 0 или 1?
            GOTO        CLEAR
            CLRF        CCP1CON
            MOVFW       CCP1TMPL
            MOVWF       CCPR1L
            MOVFW       CCP1TMPH
            MOVWF       CCPR1H
            MOVLW       B'00001000'
            MOVWF       CCP1CON
            CLRF        TMR1H
            CLRF        TMR1L
            BCF         PIR1,CCP1IF
            RETURN
            
CLEAR       CLRF        CCP1CON
            MOVFW       CCP1TMPL
            MOVWF       CCPR1L
            MOVFW       CCP1TMPH
            MOVWF       CCPR1H
            MOVLW       B'00001001'
            MOVWF       CCP1CON
            CLRF        TMR1H
            CLRF        TMR1L
            BCF         PIR1,CCP1IF
            RETURN
            
BUTTON      CALL        DELAY
            MOVFW       CCP1TMPH
            MOVWF       TMP
            MOVLW       7
            SUBWF       TMP,F
            BTFSC       STATUS,Z
            GOTO        NEXT
            MOVFW       CCP1TMPH
            MOVWF       TMP
            MOVLW       0
            SUBWF       TMP,F
            BTFSC       STATUS,Z
            GOTO        NEXT
            MOVLW       .62                     ;отнимаем от регистра CCPR1H тем самым сокращаем время импульса
            SUBWF       CCP1TMPH,F    ;можно организовать таблицу данных и загружать их в регистр сравнения
            GOTO        EXIT
NEXT        CLRW
            MOVWF       CCP1TMPH
            MOVLW       .15
            SUBWF       CCP1TMPL,F
            MOVFW       CCP1TMPL
            MOVWF       TMP
            CLRW
            SUBWF       TMP,F
            BTFSC       STATUS,Z
            GOTO        RESET_ALL
            GOTO        EXIT
RESET_ALL   MOVLW       0FFH
            MOVWF       CCP1TMPL
            MOVWF       CCP1TMPH
EXIT       
            BTFSS       PORTA,4
            GOTO        EXIT
            RETURN
            
DELAY       MOVLW       .40
            MOVWF       J
JLOOP       MOVLW       .255
            MOVWF       K
KLOOP       DECFSZ      K,F
            GOTO        KLOOP
            DECFSZ      J,F
            GOTO        JLOOP
            RETURN
            END

 

Back to Top