Hello
here is the code
This is part of main code , I have separated it for debug purposes
'================================================= ===================================
'Configuration bits for PIC16F876A
@ __config _HS_OSC & _WRT_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CP_ALL
'================================================= ===================================
'Defines
@ #define DEBUG_MODE 1
DEFINE OSC 10
define INTHAND ISR ' Define interrupt service routine
wsave var byte $20 system ' temp save
wsave1 var byte $A0 system ' If device has RAM in bank1
wsave2 var byte $120 system ' If device has RAM in bank2
wsave3 var byte $1A0 system ' If device has RAM in bank3
ssave var byte $21 syst ' Used to save the STATUS reg. upon interrupt
psave var byte $22 system ' Used to save the PCLATH reg. upon interrupt
fsrsave var byte $23 system ' Used to save the FSR reg. upon interrupt
'---------------------------------------------------------------------
'------------Required variables---------------------------------------
detTone var byte
valDTMF var bit
timer0_ofcnt var byte
tonebuf var byte
timer0 var byte
enddigit var byte
bf var byte[8]
i2 var byte
j2 var byte
endindex2 var byte
buffLen con 8
'---------------------------------------------------------------------
'Enable internal pull-up resistors
Poke $81,%01111111
'sets up controller porta to DIGITAL instead of analog VIMP
ADCON1=7
T1CON =$34
'================================================= ===================================
'Initialize port pins
'================================================= ===================================
'Make entire register B as input
'Poke TRISB,%11111111
TRISB = %11111111
' Set up interrupts
T1CON = %00110000 ' Set timer 1 for 1: prescalar, timer mode, on
OPTION_REG = %00010111
PIE1 = %00000011 ' Enable timer 1 interrupts
INTCON = %11010000 'Enable global interrupts,external interrupt
'Make serial data pins as normal pins for using serout
RCSTA = %00000000
'When received tone pair is registered dv becomes 1
'portB.1-B.4 are the bcd value of the received dtmf. all go high when active
dv VAR PORTB.0
'Make serial data pins as normal pins for using serout
RCSTA = %00000000
'TURN OFF THE SERIAL PORT IE USART AND USE SEROUT
rs_Dout VAR PORTC.6
GOTo prebegin
'================================================= ===================================
'***** Interrupt Service Routine *****
'================================================= ==============================
' The ISR first saves the processor context, and then jumps to either the Timer1
' ISR, or the Receive Data ISR, depending on the Int. Flags.
asm
ISR
; Save processor context
movf FSR, w ; Save the FSR in fsrsave
movwf fsrsave
; Check interrupt flags to see which interrupt fired
btfsc INTCON, INTF ; Else if Ext. Interrupt,
goto DTMF_ISR ; Go to Ext. Int. ISR
; If an unknown interrupt fired, exit the ISR
clrf INTCON
goto End_ISR
;================================================= ==============================
; External Interrupt Service Routine
;================================================= ==============================
; The external int. ISR
DTMF_ISR
endasm
'this routine gets the dtmf tones from line and stores them in buffer
GOto GETDTMF
instbintr:
@ IF DEBUG_MODE
serout rs_Dout,4,[32,"Hi thr",32]
@ ENDIF
asm
bcf INTCON, INTF
goto End_ISR
End_ISR
; Restore processor context
movf fsrsave, w ; Restore the previous FSR from fsrsave
movwf FSR
movf psave, w ; Restore the previous PCLATH from psave
movwf PCLATH
swapf ssave, w ; Restore the previous STATUS from ssave
movwf STATUS
swapf wsave, f ; Restore W from wsave without modifying
swapf wsave, w ; the STATUS reg.
; Return from interrupt
retfie
endasm
PREBEGIN: main
@ IF DEBUG_MODE
serout rs_Dout,4,["Program serial testing "]
@ ENDIF
GOTO PREBEGIN
end
getdtmf:
detTone = 0
valDTMF = 0
timer0_ofcnt = 0
back:
if dv = 1 then
'-------------------------START TIMER 0--------------------------------
option_reg.5 = 0
INTCON.5 = 1 'START
'--------------------------------------------------------------------
detTone = PORTB
'Due to pin connection on the board the following code
detTone = detTone >> 1
tonebuf = detTone & $0f
'--------------------------------------------
'lookup table for digits
'1-9 <=> 1-9 , 0<=>a, .<=> B, # <=> C, A <=> D,B <=> E,C<=>F, D<=> 0
'My digit equivalents 0-9 <=> 0-9, A-D <=> 10 to 13,. <=> 14, # <=>
15
'---------------------------------------------------------------------
lookup tonebuf, ["D",1,2,3,4,5,6,7,8,9,0,"*","#","A","B","C"], detTone
valDTMF = 1
endif
'---------------------------------------------------------------------
if dv = 0 then done
goto back
done:
INTCON.5 = 0
timer0 = TMR0
timer0 = 26 * timer0_ofcnt + timer0 * 103/1000
@ IF DEBUG_MODE
serout rs_Dout,4,["TMR1",#timer0,32,#timer0_ofcnt,32,"tt",detTon e,32]
@ ENDIF
TMR0= $00
'----------store tone in buffer--------------
bf(endDigit) = detTone
@ IF DEBUG_MODE
serout rs_Dout,4,["dit",#enddigit,32,#bf(endDigit),32]
@ ENDIF
endDigit = endDigit + 1
valDTMF = 0
if (endDigit > (buffLen-1)) then
endindex2 = buffLen - 2
enddigit = buffLen-1
for i2 = 0 to endindex2 step 1
j2 = i2+1
bf(i2) = bf(j2)
next i2
endif
goto instbintr
urgent word in subject is due to my flustration of not being able to debug this since last few days and time deadline of project
Bookmarks