avatar_Hattuşa

MACRO KUTUPHANELERİ

Başlatan Hattuşa, 31 Aralık 2015, 13:57:55

Hattuşa

slm arkadaşlar;
basicte veya protonda macro kütüphaneleri oluşturulup bunları programa dahil ederek nasıl kullanıyoruz?
örnek olarak protonun sources dosyasında bulunan "timer1_18.inc" dosyasında ki gibi;

Alıntı Yap'
' TIMER1 MACROS
'
' For 16-bit core (18F) devices using version 3.1 onwards of the Proton Compiler
' This file is supplied as-is and without warranty.
'
' It is encouraged that devices that are not supported be added by the users
' of the Proton compiler and made available on the Proton forum.
' www.protonbasic.co.uk
'
' However, do not Modify unless you are absolutely sure of what you are doing.
'
'
' Interrupt bit mask to be 'anded' with the other configuration masks and
' passed as the PARAM_CONFIG parameter to the 'open' macros.
'
   Symbol T1_INT_OFF   = %01111111         ' Interrupts disabled
   Symbol T1_INT_ON    = %11111111         ' Interrupts enabled
'
' TIMER1 configuration masks - to be 'anded' together and passed to the OPEN_TIMER1 macro
'
' Timer Width
'
   Symbol T1_8BIT_RW        = %10111111      ' 8-bit mode
   Symbol T1_16BIT_RW       = %11111111      ' 16-bit mode
'
' Clock Source
'
   Symbol T1_SOURCE_INT     = %11111101      ' Internal clock source
   Symbol T1_SOURCE_EXT     = %11111111      ' External clock source
'
' Prescaler
'
   Symbol T1_PS_1_1         = %11001111      ' 1:1 prescale value
   Symbol T1_PS_1_2         = %11011111      ' 1:2 prescale value
   Symbol T1_PS_1_4         = %11101111      ' 1:4 prescale value
   Symbol T1_PS_1_8         = %11111111      ' 1:8 prescale value
'
' Oscillator Use
'
   Symbol T1_OSC1EN_OFF     = %11110111      ' Timer 1 oscilator enable off
   Symbol T1_OSC1EN_ON      = %11111111      ' Timer 1 oscilator enable on
'
' Synchronize Clock Input
'
   Symbol T1_SYNC_EXT_ON    = %11111011      ' Synchronize external clock input
   Symbol T1_SYNC_EXT_OFF   = %11111111      ' Do not synchronize external clock input
'---------------------------------------------------------------------------------
' Macro Name   : OPEN_TIMER1
' Return Value   : None
' Parameters   : Bit definitions to configure Timer1
' Notes         : Reset the Timer1 regs to the POR state and configures the interrupt, clock source, edge and prescaler.
'             : The bit definitions for PARAM_CONFIG can be found at the top of this file.
'
OPEN_TIMER1 MACRO PARAM_CONFIG
     #if(PRM_COUNT != 1)
       #error "OPEN_TIMER1 Macro requires a parameter"
       EXITM
    #endif
    #if((PRM_1 != NUM8) && (PRM_1 != NUM16) && (PRM_1 != NUM32))
       #error "OPEN_TIMER1 Macro parameter must be a constant value"
       EXITM
    #endif
    #if((0X7E & PARAM_CONFIG) == 0)
       Clrf T1CON
    #else
       Movlw (0X7E & PARAM_CONFIG)
        Movwf T1CON               ' Configure timer1, but don't start it yet
     #endif
    #if(PARAM_CONFIG & 0x40)          ' The 8/16 selection bit isn't in the
      Bsf T1CON,RD16              ' right place so we need to move it
     #else
      Bcf T1CON,RD16
    #endif
    TMR1H = 0                      ' Reset Timer1 to 0x0000
     TMR1L = 0
     Bcf PIR1,TMR1IF               ' Clear Timer1 overflow flag
     #if(PARAM_CONFIG & 0X80)        ' If interrupts enabled
       Bsf PIE1,TMR1IE             ' Enable Timer1 overflow interrupt
    #else
       Bcf PIE1,TMR1IE
     #endif
     Bsf T1CON,TMR1ON
   ENDM
'---------------------------------------------------------------------------------
' Macro Name    : CLOSE_TIMER1
' Return Value   : None
' Parameters   : None
' Description   : Disable the Timer1 interrupt and stop Timer0
'
CLOSE_TIMER1 MACRO
    Bcf T1CON,TMR1ON            ' Disable Timer1
     Bcf PIE1,TMR1IE               ' Disable Timer1 overflow interrupts
    ENDM
'---------------------------------------------------------------------------------
' Macro Name     : READ_TIMER1
' Return Value   : Timer1 16-bit value
' Parameters   : None
' Description   : Read a 16-bit value from Timer1.
'
READ_TIMER1 MACRO

    #if(READ_TIMER1_RETURN == 1)
        #if(RETURN_TYPE == BYTE)
           #if(RETURN_VAR == WREG)
                Movf TMR1L,W
            #else
                Byte_Byte TMR1L,RETURN_VAR     ' Copy Timer1 low byte
           #endif
        #endif
        #if(RETURN_TYPE == WORD)
           Byte_Byte TMR1L,RETURN_VAR        ' Copy Timer1 low byte
           Byte_Byte TMR1H,RETURN_VAR + 1     ' Copy Timer1 high byte
        #endif
        #if(RETURN_TYPE == DWORD)
           Byte_Byte TMR1L,RETURN_VAR        ' Copy Timer1 low byte
           Byte_Byte TMR1H,RETURN_VAR + 1     ' Copy Timer1 high byte
           Num_Word 0,RETURN_VAR + 2
        #endif
   #endif
     ENDM
'---------------------------------------------------------------------------------
' Macro Name     : WRITE_TIMER1
' Return Value   : None
' Parameters   : Value to write to Timer1
' Description   : Write a 16-bit value to Timer1
'
WRITE_TIMER1 MACRO PARAM_TIMER

   #if(PRM_COUNT != 1)
       #error "WRITE_TIMER1 Macro requires a parameter of the value placed into TIMER1"
       EXITM
    #endif

    #if(PRM_1 == NUM8)
       Clrf TMR1H
        #if((PARAM_TIMER & 255) == 0)
            Clrf TMR1L
          #else
           Movlw (PARAM_TIMER & 255)
            Movwf TMR1L
          #endif
    #endif
    #if((PRM_1 == NUM16) || (PRM_1 == NUM32))
       #if(((PARAM_TIMER >> 8) & 255) == 0)
             Clrf TMR1H
       #else
            Movlw (PARAM_TIMER >> 8)
           Movwf TMR1H
          #endif
        #if((PARAM_TIMER & 255) == 0)
           Clrf TMR1L
        #else
            Movlw (PARAM_TIMER & 255)
           Movwf TMR1L
         #endif
    #endif
    #if(PRM_1 == BYTE)
       Clrf TMR1H
        Byte_Byte PARAM_TIMER,TMR1L
    #endif
    #if((PRM_1 == WORD) || (PRM_1 == DWORD))
       Byte_Byte PARAM_TIMER + 1,TMR1H
        Byte_Byte PARAM_TIMER,TMR1L
    #endif
    ENDM
   

Powered by EzPortal