Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OC na PIC-u
#2
Milane,

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 MODUNEMA 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 MODULECLEAR ON COMPARE MATCH
    MOVWF    CCP1CON    
    BSF    PIE1
CCP1IE                OMOGUCI INTERAPT CCP-A        

MAIN
    
GOTO    MAIN

    END 
Reply


Messages In This Thread
OC na PIC-u - by Milan_kg - 04-26-2018, 02:28 PM
RE: OC na PIC-u - by vojinilic - 04-26-2018, 03:18 PM
RE: OC na PIC-u - by npejcic - 04-26-2018, 09:19 PM
RE: OC na PIC-u - by Milan_kg - 01-04-2020, 06:51 PM
RE: OC na PIC-u - by vojinilic - 01-04-2020, 08:38 PM
RE: OC na PIC-u - by Milan_kg - 01-04-2020, 08:52 PM
RE: OC na PIC-u - by vojinilic - 01-04-2020, 08:54 PM
RE: OC na PIC-u - by Milan_kg - 01-04-2020, 08:57 PM
RE: OC na PIC-u - by gorankg - 01-04-2020, 08:59 PM
RE: OC na PIC-u - by Milan_kg - 01-04-2020, 09:06 PM
RE: OC na PIC-u - by enaB - 01-04-2020, 10:51 PM
RE: OC na PIC-u - by gorankg - 01-04-2020, 11:06 PM
RE: OC na PIC-u - by Milan_kg - 01-04-2020, 11:45 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)