Milane,
evo koda za jedan impuls sirine 50us. Kada se zavrsi impuls, generise se interapt.
evo koda za jedan impuls sirine 50us. Kada se zavrsi impuls, generise se interapt.
PHP Code:
LIST P=12F683
#INCLUDE "P12F683.INC"
;***** CONFIGURATION WORD *****
__CONFIG _INTOSCIO & _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _BOD_ON & _IESO_OFF & _FCMEN_OFF
;***********************
;* KORISNICKI REGISTRI *
;***********************
W_TEMP EQU 0x20
STATUS_TEMP EQU 0x21
PULSE_WIDTH_HI EQU 0x23
PULSE_WIDTH_LO EQU 0x24
ORG 0x00
GOTO INIT
; ***** INTERAPT RUTIN *****
ORG 0x04
MOVWF W_TEMP ;COPY W TO TEMP REGISTER
SWAPF STATUS,W ;SWAP STATUS TO BE SAVED INTO W
;SWAPF ARE USED BECAUSE THEY DO NOT AFFECT STATUS BITS
BCF STATUS,RP0 ;SELECT BANK 0
MOVWF STATUS_TEMP ;SAVE STATUS TO BANK ZERO STATUS_TEMP REGISTER
BTFSS PIF1,CCP1IF ;ISPITIVANJE INTERAPTA OD CCP modula
GOTO INTEND
BCF PIR1, CCP1IF ; OCISTI CLEAR ON MATCH flag
;***** OVDE SE PISE PROGRAM KOJI SE IZVRSAVA KADA SE ZAVRSI GENERISANJE IMPULSA *****
INTEND
SWAPF STATUS_TEMP,W ;SWAP STATUS_TEMP REGISTER INTO W (SETS BANK TO ORIGINAL STATE)
MOVWF STATUS ;MOVE W INTO STATUS REGISTER
SWAPF W_TEMP,F ;SWAP W_TEMP
SWAPF W_TEMP,W ;SWAP W_TEMP INTO W
RETFIE ;RETURN FROM INTERRUPT
; ***** INICIJALIZACIJA MIKROKONTROLERA *****
INIT
BSF STATUS,RP0 ;SELECT BANK 1
MOVLW B'01110001' ;INTERNI OSCILATOR 8MHz
MOVWF OSCCON
BCF STATUS,RP0 ;SELECT BANK 0
MOVLW 07H
MOVWF CMCON0 ;ISKLJUCI KOMPARATORSKI MODUL.
BSF STATUS,RP0 ;SELECT BANK 1
MOVLW B'00000'
MOVWF TRISIO
BCF STATUS,RP0 ;SELECT BANK 0
CLRF GPIO
BCF PIR1,CCP1IF
BSF INTCON,GIE ;GLOBAL INTERRUPT ENABLE.
; ***** SIRINA IMPULSA = 50US ******
MOVLW 0x00
MOVWF PULSE_WIDTH_HI
MOVLW 0xc7
MOVWF PULSE_WIDTH_LO
MOVLW B'00000001'
MOVWF T1CON ; TMR1 RADI U FREE RUNNING MODU. NEMA DELJENJA TAKTA
LAB2 MOVF PULSE_WIDTH_HI,W
MOVWF CCPR1H
MOVF PULSE_WIDTH_LO,W
MOVWF CCPR1L
CLRF TMR1H
CLRF TMR1L
BCF PIR1,CCP1IF
MOVLW B'00001001' ;COMPARE MODULE. CLEAR ON COMPARE MATCH
MOVWF CCP1CON
BSF PIE1, CCP1IE ; OMOGUCI INTERAPT CCP-A
MAIN
GOTO MAIN
END