IMHO = In My Humble Opinion, good luck. Funny I don't even use cell phone . . .
do I have to do the hole code in assy?
No ooooooo
Here is a timer1 demo I made tonight for 16F690
Code:
@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BOR_OFF & _FCMEN_OFF & _IESO_OFF
INCLUDE "DT_INTS-14.bas" ; Darrel Taylors instant interrupts
DEFINE OSC 4
; * * * * * * * * * * * * * Setup Darrel's Instant Interrupts * * * * * * * *
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _Flash, ASM, no
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE TMR1_INT ; enable external (INT) interrupts
; * * * * * * * * * * * * * Provide system variables to save return address' * * * *
;wsave VAR BYTE $20 SYSTEM ; location for W if in bank0
wsave VAR BYTE $70 SYSTEM ; alternate save location for W
; * * * * * * * * * * * * SETUP DEBUG Parameters * * * * * * * * * * * * *
DEFINE DEBUG_MODE 0 ' Debug sending True serial data
DEFINE DEBUG_REG_PORTA ' Debug Port = PortA as required by PICKIT2 serial Monitor
DEFINE DEBUG_BIT 0 ' Debug.bit = PortA.0
DEFINE DEBUG_BAUD 19200 ' Default baud rate = 9600
DEFINE DEBUGIN_REG PORTA' Debug Port = PortA as required by PICKIT2 serial Monitor
DEFINE DEBUGIN_BIT 1 ' Debugin bit PortA.1
DEFINE DEBUGIN_BAUD 19200' Default baud rate = 9600
DEFINE DEBUGIN_MODE 0 ' Debugin receiving data true = 0 inverted = 1
; * * * * * * * * * * * * Setup Timer 1 registers * * * * * * * * * * *
TMR1IF var PIR1.0 ' Explain to PBP which bit is the T1IF bit
INTCON = %11010000 ; GIE,PEIE,T0IE,INTE set RABIE,T0IF,INTF,RABIF cleared
PIR1 = %00000000
PIE1 = %00000001 ; -,ADIE ,RCIE ,TXIE ,SSPIE ,CCP1IE,TMR2IE,TMR1IE
T1CON = %01000101 ; T1GINV,TMR1GE,T1CKP,T1CKP,T1OSCEN,T1SYNC,TMR1CS,TMR1ON
CM2CON1 = %00000000
temp var word
overFlow var word
overFlow = 0
temp.highbyte = 0
temp.lowbyte = 0
main:
if temp.lowbyte >= 255 then
temp.highbyte = temp.highbyte +1
endif
if temp >= 65535 then
overFlow = overFlow + 1 ;track number of temp roll overs
endif
debug " Temp Var High = ",#temp.highbyte," Temp Var Low = ",#Temp.Lowbyte," ",10
debug "OverFlow = ",#overFlow," temp var ",#temp,10
goto main
; * * * * * * * * * * * * * End of Main Function * * * * * * * * * * * * *
@ INT_DISABLE TMR1_INT
Flash:
if TMR1IF then ; Flash is the ISR
temp = temp + 1 ; add 1 to timer roll over count
endif
TMR1L = 0 ; preload timer 0 with ? of 255 allows you to set counts until reset
TMR1H = 0
TMR1IF = 0 ; Clear T1 Interrupt flag bit
@ INT_ENABLE TMR1_INT
@ INT_RETURN
All this does is overflow the timer and display the results in PICKit2 USART display. It has Darrel's Instant Interrupts installed so you can pretty much copy paste, then use your registers as required
Bookmarks