Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Timer1 Module/Interrupts

Status
Not open for further replies.
Hello,
I'm trying to work out how to user the timer1 module for a project, but have so far been unsuccesful. Can anybody point out where i'm going wrong. The code does go to the interupt handler, but the delay is shorter than i was expecting and it only seems to work with the internal oscillator. Ideally i need to use an external one because my application requires a reasonably accurate clock. Here's what I've got so far. My knowledge of interputs is poor so any explaination would be very helpful.

Thanks in advance.
Code:
ISR:
bcf       INTCON,T0IF
movwf     W_Save
movf      STATUS,w
movwf     STATUS_Save
INCF 	  NUMBER_OF_BREATHS
BTFSC	  NUMBER_OF_BREATHS,7
CALL	  LETTER 
BTFSC 	  NUMBER_OF_BREATHS,7
clrf	  NUMBER_OF_BREATHS
movf      STATUS_Save,w
movwf     STATUS
swapf     W_Save,f
swapf     W_Save,w
retfie
INTERRUPTTEST: 
bsf 	STATUS,RP0
bsf 	PIE1,0 
bcf		STATUS,RP0
bsf 	INTCON,7 
BSF		INTCON,PEIE 
CLRF 	TMR1L
CLRF	TMR1H
MOVLW	B'00110001'
MOVWF	T1CON

man:
nop 
nop
nop
goto man
Code:
 
You appear to be clearing timer zero interrupt flag instead of timer 1. I'm not sure how you are getting any interrupts at all as you don't set the timer 1 interrupt enable bit (PIE1,TMR1IE).

Mike.
 
ok that should make it work. i believe i am setting the interrupt enable, i think it is bit 0? i'll check this out in the morning. it's 2 now and i need to sleep.

thanks:)
 
Ahhh, yes, you are setting PIE1,TMR1IE but you're not clearing PIR1,TMR1IF in your ISR.

Mike.
 
Can someone tell me which clock I'm using if i select the internal oscillator for the timer. Is this the oscillator included in the chip, or is this oscillator from which the microcontroller is already running (I'm already using an external oscilltor). Also, how accurate is the internal 4 MHz oscillator. Is it very poor like the 32k, or is it ok?
 
Can someone tell me which clock I'm using if i select the internal oscillator for the timer. Is this the oscillator included in the chip, or is this oscillator from which the microcontroller is already running (I'm already using an external oscilltor). Also, how accurate is the internal 4 MHz oscillator. Is it very poor like the 32k, or is it ok?

hi,
If you are using a 4MHz xtal then the internal clock to the timers is 1MHz.

What sort of timing accuracy are you looking for.?
 
Ok so it runs off a 1MHZ internal osclliator which comes from the external source?I was looking to achieve at least +-5%. I'm assuming that this is ok now if the clock comes from the external source?
 
Ok so it runs off a 1MHZ internal osclliator which comes from the external source?I was looking to achieve at least +-5%. I'm assuming that this is ok now if the clock comes from the external source?

hi,
I think you have misunderstood, the external crystal , 4MHz in your case, is automatically divided by 4 by the PIC, so that the PIC's internal clocking rate is 1MHz.

EDIT:

000esp05.gif
 
Last edited:
Yeah, that sort of what i was getting at. i've got one final question if anyone knows the answer. How do i get the counter to rest and continue to periodically interrupt the program?
here's what i've tried, it will only interrupt the program once?

Code:
INTERRUPTTEST: 
bsf 	STATUS,RP0
bsf 	PIE1,0 
bcf		STATUS,RP0
bsf 	INTCON,7 
BSF		INTCON,PEIE 
CLRF 	TMR1L
CLRF	TMR1H
MOVLW	B'00110000'
MOVWF	T1CON
BSF		T1CON,0 

man:
nop 
nop
nop
goto man

ISR:
movwf     W_Save
movf      STATUS,w
movwf     STATUS_Save
BCF		  PIR1,TMR1IF
CALL	  LETTER
CLRF 	  TMR1L
CLRF	  TMR1H 
BSF		  T1CON,0
movf      STATUS_Save,w
movwf     STATUS
swapf     W_Save,f
swapf     W_Save,w
retfie
 
hi,
You have to re enable tmr1 inter at the end of your ISR

edit:
You should also reload the Tmr1 h/l with your timed value periods.

It would help if you posted your full program so that we can see the initialise.
 
Last edited:
Yeah, it still doesn't work. I wouldn't be concerned with the initialisation routine, i'm sure the problem is in either the interrupttest subroutine or the ISR.
Code:
       ORG     0
        GOTO    START
ISR:
movwf     W_Save
movf      STATUS,w
movwf     STATUS_Save
BCF		  PIR1,TMR1IF
CALL	  LETTER
bsf 	STATUS,RP0
bsf 	PIE1,TMR1IF 
bcf		STATUS,RP0
bsf 	INTCON,7 
BSF		INTCON,PEIE 
CLRF 	TMR1L
CLRF	TMR1H
;MOVLW	B'00110000'
;MOVWF	T1CON
;BSF		T1CON,0 
movf      STATUS_Save,w
movwf     STATUS
swapf     W_Save,f
swapf     W_Save,w
retfie

; MAIN PROGRAM STARTS HERE:
START   CLRW			; CLEAR W.	
        MOVWF   PORTA           ; ENSURE PORTA IS ZERO BEFORE WE ENABLE IT.
        MOVWF   PORTB           ; ENSURE PORTB IS ZERO BEFORE WE ENABLE IT.
		movwf 	PORTC
		BSF     STATUS,RP1
		movlw	H'00'
		movwf 	ANSEL
		MOVLW	B'00001000'
		movwf 	ANSELH
		BCF     STATUS,RP1
        BSF     STATUS,RP0      ; SELECT BANK 1
		MOVLW	B'01100101'
		MOVWF	OSCCON
        MOVLW   H'00'           ; MASK FOR PORTA FOR ALL OUTPUTS.
        MOVWF   TRISA           ; SET TRISA REGISTER.
        MOVLW   B'00100000'     ; MASK FOR PORTB FOR ALL OUTPUTS.
        MOVWF   TRISB           ; SET TRISB REGISTER.
		MOVLW	H'00'
		MOVwf	TRISC
		movlw   0x10           ; A2D Clock Fosc/8 4MHz CLOCK
    	movwf   ADCON1 	
        BCF     STATUS,RP0      ; RESELECT BANK 0.
		MOVLW	B'10101101'		; ADCON0 . ADCON 0 BIT 7=0 LJ. BIT 6=0 VDD REF. BITS 5-2 1011 SEL AN11. BIT 1 GO/DONE BIT. BIT0=1 ENABLE IT.
		MOVWF	ADCON0
		
	    CALL	INIT_LCD	; Initialse the LCD
 	    MOVLW   CLRSCR		; Clear the screen
  	    CALL    COMMAND		; Initiate the command in the W reg	
		CLRF	NUMBER_OF_BREATHS 
		
		CALL	INTERRUPTTEST
LETTER:
MOVLW	'Y'
CALL 	DISPLAY
RETURN
INTERRUPTTEST: 
bsf 	STATUS,RP0
bsf 	PIE1,0 
bcf		STATUS,RP0
bsf 	INTCON,7 
BSF		INTCON,PEIE 
CLRF 	TMR1L
CLRF	TMR1H
MOVLW	B'00110000'
MOVWF	T1CON
BSF		T1CON,0 

man:
nop 
nop
nop
goto man
 
hi,
I have no idea which PIC you are using, I would request that you post the full program.
 
ok, here's the code. I was reluctant to post it all because most of it isn't relevant to the routine. It's really long and messy atm sorry.
I think he problem is that the program isn't returning from the interrrupt. I made it so the program looped dsiplaying a B each time it completed a loop. It did it went to the interrupt service routine, displayed a different character as instructed and never came back?

Code:
#include <p16F690.inc>
    __config (_XT_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
	



;----------------------------------------
; DELAY EQUATES
CNT          	  EQU 0X25         ;ADDRESS FOR COUNTER
CNT2          	  EQU 0X26         ;ADDRESS FOR COUNTER2
CNT3          	  EQU 0X27         ;ADDRESS FOR COUNTER3
CNT4          	  EQU 0X28         ;ADDRESS FOR COUNTER4
BREATH_ADC0	  	  EQU 0X29		   ;ADDRESS FOR RECEIVED BIT
BREATH_ADC1   	  EQU 0X2A
NUMBER_OF_BREATHS EQU 0X2B
CNT5																																																																										  	  EQU 0X2C
BINARY		      EQU 0X2D
t1				  EQU 0X2E
w2			 	  EQU 0X2F
COUNTER 		  EQU 0X30
TEMP			  EQU 0X31
D1				  EQU 0X32
D0				  EQU 0X33
SAMPLEREG		  EQU 0X34
D2				  EQU 0X35
D3				  EQU 0X36
SAMPLEOLD 		  EQU 0X37
SAMPLENEW 		  EQU 0X38
D4				  EQU 0X39
D5				  EQU 0X3A
D6				  EQU 0X3B
SAMPLEOLDLOW	  EQU 0X3C
SAMPLEOLDHIGH	  EQU 0X3D
SAMPLENEWLOW	  EQU 0X3E
SAMPLENEWHIGH	  EQU 0X3F
W_Save			  EQU 0X40
STATUS_Save		  EQU 0X41



; LCD EQUATES AND DEFINES
#DEFINE     DDRE   TRISB,7     ;DATA DIRECTION
#DEFINE     DDRRS  TRISB,4     ;DATA DIRECTION
#DEFINE     E      PORTA,2     ;ENABLE LINE ON LCD
#DEFINE     RS     PORTB,4     ;INSTRUCTION/DATA SELECT
#DEFINE 	RW	   PORTB,6
TEMP_LCD    EQU 0X3A           ;STORAGE FOR LCD
LCD         EQU PORTC          ;LCD DATA PORT
CLRSCR      EQU B'00000001'    ;COMMAND FOR CLRSCR
HOME        EQU B'00000010'    ;SENDS CURSOR TO HOME
ON          EQU B'00001100'    ;TURNS ON THE DISPLAY
OFF         EQU B'00001000'    ;TURNS THE DISPLAY OFF
LEFT        EQU B'00011000'    ;LEFT SHIFT
RIGHT       EQU B'00011100'    ;RIGHT SHIFT
LIN2        EQU B'11000000'    ;SETS TO LINE 2


;----------------------------------------
	; VECTOR FOR NORMAL START UP.
        ORG     0
        GOTO    START
ISR:
movwf     W_Save
movf      STATUS,w
movwf     STATUS_Save
BTFSS	  PIR1,TMR1IF
GOTO	  $-1
BCF		  PIR1,TMR1IF
CALL	  LETTER
CLRF 	  TMR1L
CLRF	  TMR1H
BCF		  PIR1,TMR1IF
movf      STATUS_Save,w
movwf     STATUS
swapf     W_Save,f
swapf     W_Save,w
retfie

; MAIN PROGRAM STARTS HERE:
START:
	   CLRW			; CLEAR W.	
        MOVWF   PORTA           ; ENSURE PORTA IS ZERO BEFORE WE ENABLE IT.
        MOVWF   PORTB           ; ENSURE PORTB IS ZERO BEFORE WE ENABLE IT.
		movwf 	PORTC
		BSF     STATUS,RP1
		movlw	H'00'
		movwf 	ANSEL
		MOVLW	B'00001000'
		movwf 	ANSELH
		BCF     STATUS,RP1
        BSF     STATUS,RP0      ; SELECT BANK 1
		MOVLW	B'01100101'
		MOVWF	OSCCON
        MOVLW   H'00'           ; MASK FOR PORTA FOR ALL OUTPUTS.
        MOVWF   TRISA           ; SET TRISA REGISTER.
        MOVLW   B'00100000'     ; MASK FOR PORTB FOR ALL OUTPUTS.
        MOVWF   TRISB           ; SET TRISB REGISTER.
		MOVLW	H'00'
		MOVwf	TRISC
		movlw   0x10           ; A2D Clock Fosc/8 4MHz CLOCK
    	movwf   ADCON1 	
        BCF     STATUS,RP0      ; RESELECT BANK 0.
		MOVLW	B'10101101'		; ADCON0 . ADCON 0 BIT 7=0 LJ. BIT 6=0 VDD REF. BITS 5-2 1011 SEL AN11. BIT 1 GO/DONE BIT. BIT0=1 ENABLE IT.
		MOVWF	ADCON0
		
	    CALL	INIT_LCD	; Initialse the LCD
 	    MOVLW   CLRSCR		; Clear the screen
  	    CALL    COMMAND		; Initiate the command in the W reg	
		CLRF	NUMBER_OF_BREATHS 
		
		CALL	INTERRUPTTEST

INCFNOB:
	BTFSC	 SAMPLEREG,1
	INCF 	 NUMBER_OF_BREATHS 
	BSF		 SAMPLEREG,1
	RETURN
	

CHECK:
MOVLW  D'1'
MOVWF  SAMPLENEW 
MOVLW  D'2'
MOVWF  SAMPLEOLD 
CALL   SAMPLENEW_GT_SAMPLEOLD
BTFSC  SAMPLEREG,0
GOTO   DISPLAY_K
GOTO   CHECK 
DISPLAY_K
MOVLW	'K'
CALL DISPLAY
GOTO CHECK 



SAMPLENEW_GT_SAMPLEOLD:
MOVFW 	ADRESH			    ;STORE NEW SAMPLE AND SUBTRACT IT FROM OLD
MOVFW	SAMPLENEW
SUBWF 	SAMPLEOLD 
BTFSS	STATUS,C
BSF 	SAMPLEREG,0	 		;IF NEW SAMPLE IS GREATER THAN OLD THIS BIT WILL BE SET  
BTFSC	STATUS,C
BCF		SAMPLEREG,0	
RETURN 	 

SAMPLEOLD_GT_SAMPLENEW:
BTFSC	SAMPLEREG,1			;IF THIS BIT IS SET MEANS THAT THERE HAS BEEN A CHANGE IN VOLTAGE DIRECTION 
GOTO	INCFNOB
MOVFW	ADRESH
INCF	W					;NEEDS TO BE INCREMENTED SO CARRY FLAG DOESN'T SET WHEN THEY ARE EQUAL 
MOVFW	SAMPLENEW
SUBWF 	SAMPLEOLD  
BTFSS	STATUS,C
BCF 	SAMPLEREG,0 		;IF NEW SAMPLE IS GREATER THAN OLD THIS WILL BE CLEAR
MOVFW 	SAMPLENEW
MOVWF 	SAMPLEOLD


RETURN  
DISPLAYADC0:
MOVLW	  D'255'
MOVWF	  SAMPLEOLDLOW
MOVWF	  SAMPLEOLDHIGH
CLRF	  NUMBER_OF_BREATHS 
DISPLAYADC:
BSF       ADCON0,GO      ; start conversion
BTFSS     ADCON0,GO      ; this bit will change to zero when the conversion is complete
GOTO      $-1
MOVFW 	  ADRESH
MOVWF	  SAMPLENEWHIGH
MOVFW	  ADRESL
MOVWF	  SAMPLENEWLOW 
CALL	  LARGECOMPAREOLDGTNEW 
BTFSC	  SAMPLEREG,0
CALL	  INCFNOB
MOVFW	  NUMBER_OF_BREATHS
CALL 	  DISPLAYBCD 
CALL 	  TENTH_SEC_DELAY 
MOVLW     CLRSCR		; Clear the screen
CALL      COMMAND
MOVFW	  SAMPLENEWHIGH
MOVWF	  SAMPLEOLDHIGH
MOVFW	  SAMPLENEWLOW
MOVWF	  SAMPLEOLDLOW

GOTO 	  DISPLAYADC

RETURN

ADCTRIAL

BSF       ADCON0,GO      ; start conversion
BTFSS     ADCON0,GO      ; this bit will change to zero when the conversion is complete
GOTO      $-1
MOVFW 	  ADRESH 
MOVWF 	  SAMPLENEW
CALL	  SAMPLENEW_GT_SAMPLEOLD
BTFSS	  SAMPLEREG,0
INCF 	  NUMBER_OF_BREATHS
MOVLW     CLRSCR		; Clear the screen
CALL      COMMAND	 
MOVFW	  NUMBER_OF_BREATHS
CALL 	  DISPLAYBCD
CALL 	  TENTH_SEC_DELAY
GOTO	  ADCTRIAL 

RETURN

DISPLAYBCD:
MOVWF 	BINARY 
CALL 	GETHNDS 
CALL 	LOOKUP_TABLE
CALL 	DISPLAY
MOVFW 	BINARY
CALL 	GETTENS
CALL 	LOOKUP_TABLE
CALL 	DISPLAY
MOVFW 	BINARY
CALL 	GETONES
CALL 	LOOKUP_TABLE
CALL 	DISPLAY
RETURN

	 	
LOOKUP_TABLE:
	;MOVF	  NUMBER_OF_BREATHS,W 
	ANDLW     B'00001111'	;STOP VALUE GOING BEYOND TABLE RANGE 
	ADDWF	  PCL	
	RETLW 	  '0'	               
	RETLW	  '1'
	RETLW	  '2'
	RETLW 	  '3'
	RETLW	  '4'
    RETLW 	  '5'
	RETLW     '6'
	RETLW 	  '7'
	RETLW	  '8'
	RETLW	  '9'



; ------------------------------------------- 
; RECEIVE CHARACTER FROM RS232 AND STORE IN W 
; ------------------------------------------- 
; This routine does not return until a character is received. 
; 
RECEIVE:
		 	
		 btfss PIR1,RCIF         ; (5) check for received data 
         goto RECEIVE 
		 BCF  RCSTA,CREN
		 BSF  RCSTA,CREN		 
		
        movf RCREG,W          ; save received data in W 
        return 
; 
; ------------------------------------------------------------- 
; SEND CHARACTER IN W VIA RS232 AND WAIT UNTIL FINISHED SENDING 
; ------------------------------------------------------------- 
; 
SEND:    
		movwf TXREG            ; send data in W 
		BCF PIR1,RCIF
 		BSF     STATUS,RP0
WtHere  btfss TXSTA,TRMT        ; (1) transmission is complete if hi 
       goto WtHere 
		 BCF     STATUS,RP0
        return 	
	
UART_SETUP:
        movlw D'51'              ; 0x19=9600 bps (0x0C=19200 bps) 
		bsf	STATUS,RP0
        movwf SPBRG 
        movlw b'00100100'       ; brgh = high (2) 
        movwf TXSTA             ; enable Async Transmission, set brgh 

        bcf STATUS,RP0          ; RAM PAGE 0 

        movlw b'10010000'       ; enable Async Reception 
        movwf RCSTA 
	    return 
;**************************lcdv6******************************
;Porta 1 for the enable and porta 2 for rs/ portb for lcd data
;*************************************************************
;************************************************************
; Initialize the LCD 
;************************************************************
INIT_LCD:
CALL  MILLSEC30	           ; '' ''
MOVLW B'00110000'                  ;tell display its two lines
CALL COMMAND                       ;output to the screen
CALL MILLSEC30
MOVLW B'00110000'
CALL COMMAND
MOVLW .100
CALL MDELAY
MOVLW B'00110000'
CALL COMMAND
MOVLW .100
CALL MDELAY
MOVLW B'00111100'					;FUNCTION SET
CALL COMMAND


MOVLW ON                           ;turn on display
CALL COMMAND                       ;output to the screen
MOVLW 0X01
CALL COMMAND
MOVLW B'00000110'                  ;shift along every write
CALL COMMAND                       ;output to the screen
RETURN
;************************************************************
; This routine is to set the lcd to the second line 
;************************************************************
SECOND_LINE:
MOVLW LIN2                     ;set to line 2
CALL COMMAND                   ;output to the screen
RETURN
;************************************************************
; THis executes a command in the W reg
;************************************************************
COMMAND:
BCF RS  
BCF	RW                       ;command coming
MOVWF LCD                      ;PUT OUT ONTO PORT
MOVLW .200                     ;delay time in microsecs
CALL MDELAY                    ;wait a while
MOVLW .250                     ;delay time in microsecs
CALL MDELAY                    ;WAIT
BSF E                          ;make sure the enable line is up 
MOVLW .200                     ;delay time
CALL MDELAY                    ;wait a while
MOVLW .250                     ;delay time in microsecs
CALL MDELAY                    ;WAIT
BCF E                          ;clock the data in
MOVLW .200                     ;delay time
CALL MDELAY                    ;wait a while
MOVLW .250                     ;delay time in microsecs
CALL MDELAY                    ;WAIT
BSF RS                         ;return to a data input
RETURN
;************************************************************
; This controls the module. When you call this 
; routine, the contents of the 'w' register is 
; displayed on the LCD screen. It is written in a 
; module like this for portability!! 
;************************************************************
DISPLAY:
BSF RS     
BCF	RW                    ;make sure it will accept data
MOVWF LCD                      ;send data to lcd
MOVLW .250                     ;delay time in microsecs
CALL MDELAY                    ;WAIT
MOVLW .250                     ;delay time in microsecs
CALL MDELAY                    ;WAIT
BSF E                          ;make sure the enable line is up 
MOVLW .250                     ;delay time
CALL MDELAY                    ;wait a while
MOVLW .250                     ;delay time in microsecs
CALL MDELAY                    ;WAIT
BCF E                          ;clock the data in
MOVLW .250                     ;delay time
CALL MDELAY                    ;wait a while
MOVLW .250                     ;delay time in microsecs
CALL MDELAY                    ;WAIT
RETURN
	
;*************************************************************
; 1 MICROSECOND DELAY 
;*************************************************************
MDELAY:
MOVWF CNT          ;LOAD DELAY TIME
COUNT:
NOP         ;TWO NO OPERATIONS
NOP                ;TO OBTAIN THE DELAY
DECFSZ CNT,1       ;DECREMENT THE COUNTER
GOTO COUNT         ;GOTO COUNT IF NOT FINISHED
RETURN


;*************************************************************
; 0.1 SECOND DELAY 
;*************************************************************
TENTH_SEC_DELAY:  ;99993 cycles
	movlw	0x1E
	movwf	D0
	movlw	0x4F
	movwf	D1
Delay_0
	decfsz	D0, f
	goto	$+2
	decfsz	D1, f
	goto	Delay_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return
;---------------------------------------------------------------
;30 MILLISECOND DELAY
;--------------------------------------------------------------
MILLSEC30:
			;29993 cycles
	movlw	0x6E
	movwf	D2
	movlw	0x18
	movwf	D3
Delay_1
	decfsz	D2, f
	goto	$+2
	decfsz	D3, f
	goto	Delay_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return




RETURN
HALF_SECOND_DELAY:
			;499994 cycles
	movlw	0x03
	movwf	D4
	movlw	0x18
	movwf	D5
	movlw	0x02
	movwf	D6
Delay_2
	decfsz	D4, f
	goto	$+2
	decfsz	D5, f
	goto	$+2
	decfsz	D6, f
	goto	Delay_2

			;6 cycles
	goto	$+1
	goto	$+1
	goto	$+1

RETURN

WAIT:		
movlw D'6'
movwf CNT3
movlw D'24'
movwf CNT4
movlw D'167'
movwf CNT5
loop decfsz CNT5,1
goto loop
decfsz CNT4,1
goto loop
decfsz CNT3,1
goto loop
return

        
 RETURN             ; all done!

GETHNDS	
		movwf	t1
        clrf    w2
gethnds_loop
		movlw	.100
		incf	w2,f
		subwf	t1,f
		btfsc	STATUS,C
		goto 	gethnds_loop
		decf	w2,w
		return		
;---
;This routine will return the number of decimal 
;tens from an 8-bit binary
;Loop based, so it might take some time...
;It needs getones too
GETTENS		movwf	t1
                clrf    w2
gettens_loop	movlw	.10
		incf	w2,f
		subwf	t1,f
		btfsc	STATUS,C
		goto 	gettens_loop
		decf	w2,w
		goto	GETONES

;---
;This routine will return the number of decimal 
;ones from an 8-bit binary	
GETONES		movwf	w2
		movlw	.10
deltens_loop	subwf	w2,f
		btfsc	STATUS,C
		goto 	deltens_loop
		addwf	w2,w
		return


;RECEIVE_DATE:
;	BTFSS	PIR1,RCIF
;	GOTO	RECEIVE_DATE
;	BTFSS	RCSTA,OERR
;	BCF		RCSTA,CREN
;	BSF		RCSTA,CREN
;	SUBLW	'G'
;	BTFSS	STATUS,2
;	GOTO	RECEIVE_DATE
;PLABEL:
;	BTFSS	PIR1,RCIF
;	GOTO	PLABEL
;	BTFSS	RCSTA,OERR
;	BCF		RCSTA,CREN
;	BSF		RCSTA,CREN
;	SUBLW	'P'
;	BTFSS	STATUS,2
;	GOTO	RECEIVE_DATE
;RLABEL:
;	BTFSS	PIR1,RCIF
;	GOTO	RLABEL
;	BTFSS	RCSTA,OERR
;	BCF		RCSTA,CREN
;	BSF		RCSTA,CREN
;	SUBLW	'R'
;	BTFSS	STATUS,2
;	GOTO	RECEIVE_DATE
;MLABEL:
;	BTFSS	PIR1,RCIF
;	GOTO	MLABEL
;	BTFSS	RCSTA,OERR
;	BCF		RCSTA,CREN
;	BSF		RCSTA,CREN
;	SUBLW	'M'
;	BTFSS	STATUS,2
;	GOTO	RECEIVE_DATE
;CLABEL:
;	BTFSS	PIR1,RCIF
;	GOTO	CLABEL
;	BTFSS	RCSTA,OERR
;	BCF		RCSTA,CREN
;	BSF		RCSTA,CREN
;	SUBLW	'C'
;	BTFSS	STATUS,2
;	GOTO	RECEIVE_DATE
;	CALL	COUNT_COMMA

;ADD9:
;COUNT_COMMA:
;	BTFSS	PIR1,RCIF
;	GOTO	COUNT_COMMA
;	BTFSS	RCSTA,OERR
;	BCF		RCSTA,CREN
;	BSF		RCSTA,CREN
;	SUBLW	','
;	BTFSS	STATUS,2
;	GOTO	COUNT_COMMA
;	INCF	COMMA
;	SUBLW	D'9'
;	BTFSS	STATUS,2
;	GOTO	ADD9
;	GOTO	STORE_DATE

;STORE_DATE:
;	BTFSS	PIR1,RCIF
;	GOTO	STORE_DATE
;	BTFSS	RCSTA,OERR
;	BCF		RCSTA,CREN
;	BSF		RCSTA,CREN
;	MOVFW	RCREG
;	MOVWF	DATA1
;STORE_DATE1
;	BTFSS	PIR1,RCIF
;	GOTO	STORE_DATE1
;	BTFSS	RCSTA,OERR
;	BCF		RCSTA,CREN
;	BSF		RCSTA,CREN
;	MOVFW	RCREG
;	MOVWF	DATA2
;STORE_DATE2
;	BTFSS	PIR1,RCIF
;	GOTO	STORE_DATE2
;	BTFSS	RCSTA,OERR
;	BCF		RCSTA,CREN
;	BSF		RCSTA,CREN
;	MOVFW	RCREG
;	MOVWF	DATA3
;STORE_DATE3
;	BTFSS	PIR1,RCIF
;	GOTO	STORE_DATE3
;	BTFSS	RCSTA,OERR
;	BCF		RCSTA,CREN
;	BSF		RCSTA,CREN
;	MOVFW	RCREG
;	MOVWF	DATA4
;STORE_DATE4
;	BTFSS	PIR1,RCIF
;	GOTO	STORE_DATE4
;	BTFSS	RCSTA,OERR
;	BCF		RCSTA,CREN
;	BSF		RCSTA,CREN
;	MOVFW	RCREG
;	MOVWF	DATA5
;STORE_DATE5
;	BTFSS	PIR1,RCIF
;	GOTO	STORE_DATE5
;	BTFSS	RCSTA,OERR
;	BCF		RCSTA,CREN
;	BSF		RCSTA,CREN
;	MOVFW	RCREG
;	MOVWF	DATA6
;	GOTO	DISPLAY_DATE

;DISPLAY_DATE:
;	MOVFW DATA1
;	CALL DISPLAY
;	MOVFW DATA2
;	CALL DISPLAY
;	MOVF DATA3
;	CALL DISPLAY
;	MOVFW DATA4
;	CALL DISPLAY
;	MOVFW DATA5
;	CALL DISPLAY
;	MOVFW DATA6
;	CALL DISPLAY
;	RETURN     

;--------------------------------------------------------------------------------------
.;COMPARE 16-BIT NUMBER 
;--------------------------------------------------------------------------------------

LARGECOMPAREOLDGTNEW: 
; if( NEW < OLD)
; by unknown
; Y and X are unchanged.
MOVFW SAMPLEOLDLOW
SUBWF SAMPLENEWLOW,w
MOVFW SAMPLEOLDHIGH
SKPC ; c=0 indicates a borrow we need to propagate.
INCFSZ SAMPLEOLDHIGH,w ; handle xh=0xff correctly, unlike ``incf xh,w''.
SUBWF SAMPLENEWHIGH,w
SKPNC
BCF	  SAMPLEREG,0
SKPC  
BSF	  SAMPLEREG,0
RETURN 
; then:
; /* y is less than x */
 
TEST:
MOVLW	D'10'
MOVWF 	SAMPLEOLDHIGH 
MOVLW	D'10'
MOVWF	SAMPLENEWHIGH
MOVLW	D'4'
MOVWF 	SAMPLEOLDLOW 
MOVLW	D'4'
MOVWF	SAMPLENEWLOW
CALL 	LARGECOMPAREOLDGTNEW
BTFSC	SAMPLEREG,0
CALL    LETTER
GOTO	$
RETURN

LETTER:
MOVLW	'Y'
CALL 	DISPLAY
RETURN

INTERRUPTTEST: 
CALL	LETTER
bsf 	STATUS,RP0
bsf 	PIE1,TMR1IF 
bcf		STATUS,RP0
bsf 	INTCON,7 
BSF		INTCON,PEIE 
CLRF 	TMR1L
CLRF	TMR1H
MOVLW	B'00110000'
MOVWF	T1CON
BSF		T1CON,0 
call	LETTER
man:
nop 
nop
nop
MOVLW	'B'
CALL 	DISPLAY
CALL	WAIT
goto man
RETURN

TIMER1:
CLRF 	TMR1L
CLRF	TMR1H
MOVLW	B'00110000'
MOVWF	T1CON

BSF		T1CON,0
REPEAT:
BTFSS	PIR1,TMR1IF
GOTO	$-1
BCF		PIR1,TMR1IF
CALL 	LETTER
GOTO	REPEAT

end
 
hi ed,
Have reformatted your program code and attached, makes it easier to read, don't worry too much about messy code at the moment.
Packing up for today.:)
 

Attachments

  • brighton1.asm
    14.6 KB · Views: 111
The first thing I noticed is that your ISR is at location 1. Change it to,
Code:
;----------------------------------------  
	; VECTOR FOR NORMAL START UP. 
	org	0
	goto	START
	[COLOR="red"]org	4[/COLOR] 
ISR:
	movwf	W_Save
	movf	STATUS,w

Edit, you're also using a lot of calls from your ISR (4 deep), so you'll get a stack overflow at some point as your main code also used the stack a lot.

Mike.
 
Last edited:
I know whats going wrong now. thank you for help.

hi Ed.
In light of Mike's findings, you can see why I was keen to see the complete program.

Sometimes the cause of a problem lies elsewhere from where you have convinced yourself it resides,,, thats why you have difficulty in finding it.:)
 
Yeah, obviously you were right, but my program was a joke so i wasn't very keen to post it. I thought it might put people off lol.
That was the problem in the end. For some unexplained reason i thought the label ISR was always linked to the location 04. I was wrong! anyway thanks for help. I really am very greatful.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top