' ' TIMER0 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 T0_INT_OFF = %01111111 ' Interrupts disabled Symbol T0_INT_ON = %11111111 ' Interrupts enabled ' ' TIMER0 configuration masks - to be 'anded' together and passed to the OPEN_TIMER0 macro ' ' Timer Width ' Symbol T0_16BIT = %10111111 ' Timer 0 is in 16 Bit mode Symbol T0_8BIT = %11111111 ' Timer 0 is in 8 bit mode ' ' Timer Source ' Symbol T0_SOURCE_INT = %11011111 ' Internal clock source Symbol T0_SOURCE_EXT = %11111111 ' External clock source ' ' External Clock Source ' Symbol T0_EDGE_RISE = %11101111 ' External rising edge clocs timer Symbol T0_EDGE_FALL = %11111111 ' External falling edge clocks timer ' ' Prescaler value ' Symbol T0_PS_1_1 = %11111111 ' Prescaler 1:1 (NO Prescaler) Symbol T0_PS_1_2 = %11110000 ' 1:2 Symbol T0_PS_1_4 = %11110001 ' 1:4 Symbol T0_PS_1_8 = %11110010 ' 1:8 Symbol T0_PS_1_16 = %11110011 ' 1:16 Symbol T0_PS_1_32 = %11110100 ' 1:32 Symbol T0_PS_1_64 = %11110101 ' 1:64 Symbol T0_PS_1_128 = %11110110 ' 1:128 Symbol T0_PS_1_256 = %11110111 ' 1:256 '--------------------------------------------------------------------------------- ' Macro Name : OPEN_TIMER0 ' Return Value : None ' Parameters : Bit definitions to configure Timer0 ' Notes : Reset the Timer0 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_TIMER0 MACRO PARAM_CONFIG #if(PRM_COUNT != 1) #error "OPEN_TIMER0 Macro requires a parameter" EXITM #endif #if((PRM_1 != NUM8) && (PRM_1 != NUM16) && (PRM_1 != NUM32)) #error "OPEN_TIMER0 Macro parameter must be a constant value" EXITM #endif #if((0X7F & PARAM_CONFIG) == 0) Clrf T0CON #else Movlw (0X7F & PARAM_CONFIG) Movwf T0CON ' Configure timer0, but don't start it yet #endif TMR0H = 0 ' Reset Timer0 to 0x0000 TMR0L = 0 Bcf INTCON,T0IF ' Clear Timer0 overflow flag #if(PARAM_CONFIG & 0X80) ' If interrupts enabled Bsf INTCON,T0IE ' Enable Timer0 overflow interrupt #else Bcf INTCON,T0IE #endif Bsf T0CON,TMR0ON ENDM '--------------------------------------------------------------------------------- ' Macro Name : CLOSE_TIMER0 ' Return Value : None ' Parameters : None ' Description : Disable the Timer0 interrupt and stop Timer0 ' CLOSE_TIMER0 MACRO Bcf INTCON,TMR0IE ' Disable the Timer0 interrupt, if it is enabled T0CON = $7F ' Stop TMR0 ENDM '--------------------------------------------------------------------------------- ' Macro Name : READ_TIMER0 ' Return Value : Timer0 8-bit or 16-bit value ' Parameters : Size of Timer0 8 or 16 ' Description : Read an 8 or 16-bit value from Timer0. ' READ_TIMER0 MACRO PARAM_SIZE #if(PRM_COUNT != 1) #error "READ_TIMER0 Macro requires a parameter of 8 or 16" EXITM #endif #if((PRM_1 != NUM8) && (PRM_1 != NUM16) && (PRM_1 != NUM32)) #error "READ_TIMER0 Macro parameter must be a constant value of 8 or 16" EXITM #endif #if(PARAM_SIZE == 8) #if(READ_TIMER0_RETURN == 1) #if((RETURN_TYPE == BYTE) || (RETURN_TYPE == WORD) || (RETURN_TYPE == DWORD)) #if(RETURN_VAR == WREG) Movfw TMR0L #else Byte_Byte TMR0L,RETURN_VAR ' Copy Timer0 low byte #endif #endif #endif #else #if(READ_TIMER0_RETURN == 1) #if(RETURN_TYPE == BYTE) #if(RETURN_VAR == WREG) Movfw TMR0L #else Byte_Byte TMR0L,RETURN_VAR ' Copy Timer0 low byte #endif #endif #if(RETURN_TYPE == WORD) Byte_Byte TMR0L,RETURN_VAR ' Copy Timer0 low byte Byte_Byte TMR0H,RETURN_VAR + 1 ' Copy Timer0 high byte #endif #endif #endif ENDM '--------------------------------------------------------------------------------- ' Macro Name : WRITE_TIMER0 ' Return Value : None ' Parameters : Size of Timer0 8 or 16 ' : Value to write to Timer0 ' Description : Write a 16-bit value to Timer0 ' WRITE_TIMER0 MACRO PARAM_SIZE, PARAM_TIMER #if(PRM_COUNT != 2) #error "WRITE_TIMER0 Macro requires 2 parameters of 8 or 16, and the value placed into TIMER0" EXITM #endif #if((PRM_1 != NUM8) && (PRM_1 != NUM16) && (PRM_1 != NUM32)) #error "WRITE_TIMER0 Macro parameter 1 must be a constant value of 8 or 16" EXITM #endif #if(PRM_2 == NUM8) #if(PARAM_SIZE == 8) #if(PARAM_TIMER == 0) Clrf TMR0L #else Movlw (PARAM_TIMER) Movwf TMR0L #endif #else Clrf TMR0H #if((PARAM_TIMER & 255) == 0) Clrf TMR0L #else Movlw (PARAM_TIMER & 255) Movwf TMR0L #endif #endif #endif #if((PRM_2 == NUM16) || (PRM_2 == NUM32)) #if(PARAM_SIZE == 8) #if((PARAM_TIMER & 255) == 0) Clrf TMR0L #else Movlw (PARAM_TIMER & 255) Movwf TMR0L #endif #else #if(((PARAM_TIMER >> 8) & 255) == 0) Clrf TMR0H #else Movlw (PARAM_TIMER >> 8) Movwf TMR0H #endif #if((PARAM_TIMER & 255) == 0) Clrf TMR0L #else Movlw (PARAM_TIMER & 255) Movwf TMR0L #endif #endif #endif #if(PRM_2 == BYTE) #if(PARAM_SIZE == 8) #if(PARAM_TIMER == WREG) Movwf TMR0L #else Byte_Byte PARAM_TIMER,TMR0L #endif #else Clrf TMR0H Byte_Byte PARAM_TIMER,TMR0L #endif #endif #if((PRM_2 == WORD) || (PRM_2 == DWORD)) #if(PARAM_SIZE == 8) #if(PARAM_TIMER == WREG) Movwf TMR0L #else Byte_Byte PARAM_TIMER,TMR0L #endif #else Byte_Byte PARAM_TIMER + 1,TMR0H Byte_Byte PARAM_TIMER,TMR0L #endif #endif ENDM