PIC16F887 timers

Status
Not open for further replies.

ytterx

New Member
hi, i'm trying to make a clock with this PIC. the only problem is that i don't het the timers working like i want. what i want is something like a loop that just cals an subroutine. and if the interrupt of the timer occures it executes another subroutine and then returns to the loop. could someone help me? i got al code for displaying the clock I only need it to be accurate to i want to use (a) timer(s).
 
How accurate do you want it to be? You'll either need to use a 32.768khz oscillator or perhaps a **broken link removed** (or equivalent).

Post the code you're having trouble with and a schematic.
 
it doesn't have to be very accurate, as long as it accurate enough, like 1 second miss on a hour is something i would like to see if possible.

hereś a link to the schematic: **broken link removed**
 
You need to make a clock but for the clock time base must run with built in timers?

Is that what you asking?

In my clocks I set a common interrupt occur time to do both work (show display + count 1 second time update).

The last clock I made 4 digit one I use 5mS interrupts
 
Last edited:
ok, if you guys won't help me further i search further..

so this is what i got at the moment: (it works..not exactly what i want..)

my include file
Code:
		;================================================================
		; 
		; include file for DB037 for a first program
		;
		; beeps and activates the LEDs with a 0x55 pattern
		;
		;================================================================

	        ; select target chip and hex file format
		LIST p=16f887, f=inhx32

        	; include target chip stuff
		#include <P16F887.INC> 
		
		; configuration settings
		__config _CONFIG1, 0x20E2 	; -debug, -LVP, -fcmen, -ieso, -boren,
                         			; -cpd, -cp, mclre, pwtre, -wdte, HSosc
		__config _CONFIG2, 0x3FFF 	; nothing special

        	; start code at 0
		ORG 0

		; start variables at 0x20
       cblock      0x20            ; Block of variables starts at address 20h
       w_temp                      ; Variable at address 20h
       pclath_temp                 ; Variable at address 21h
       status_temp                 ; Variable at address 22h
		temp_timer
       endc
	movlw h'00'
	movwf temp_timer
       
       goto        WContinue            ; Go to label "main"
       
;************************ INTERRUPT ROUTINE *********************************
       org         0x0004          ; Interrupt vector
       movwf       w_temp          ; Saves value in register W
       movf        STATUS          ; Saves value in register STATUS
       movwf       status_temp
       movf        PCLATH          ; Saves value in register PCLATH
       movwf       pclath_temp

;increment PORTD for leds..
       banksel     PORTD           ; Selects bank containing PORTB
       incf        PORTD


       banksel     INTCON          ; Selects bank containing INTCON
       bcf         INTCON,TMR0IF   ; Clears interrupt flag TMR0IF
       
       movf        pclath_temp,w   ; PCLATH is given its original content
       movwf       PCLATH
       movf        status_temp,w   ; STATUS is given its original content
       movwf       STATUS
       swapf       w_temp,f        ; W is given its original content
       swapf       w_temp,w
        
       bsf         INTCON,GIE      ; Global interrupt enabled
       retfie                      ; Return from interrupt routine

my .asm file:

Code:
	;================================================================
	; 
	; CLOCK
	;
	;================================================================

    
	#include <DB038-01.INC> ;my include file

;********************** Header **********************************************
;**************** DEFINING VARIABLES ****************************************

		; shadow registers and flush subroutines
		
FLUSH_MACRO MACRO Shadow, Port
		CBLOCK
			Shadow
		ENDC
		MOVFW Shadow
		MOVWF Port
		RETURN
		ENDM

PORTA_FLUSH		FLUSH_MACRO PORTA_SHADOW, PORTA
PORTB_FLUSH		FLUSH_MACRO PORTB_SHADOW, PORTB
PORTC_FLUSH		FLUSH_MACRO PORTC_SHADOW, PORTC
PORTD_FLUSH		FLUSH_MACRO PORTD_SHADOW, PORTD
PORTE_FLUSH		FLUSH_MACRO PORTE_SHADOW, PORTE
		
                ; ===========================================================
		; WWAIT

WWAIT
		CBLOCK
			WWaitCounter
		ENDC
		MOVLW 0x00
		MOVWF WWaitCounter
WWaitLoop
		CALL WWaitReturn
		DECFSZ WWaitCounter, f
			GOTO WWaitLoop
WWaitReturn
		RETURN

WContinue
                ; ===========================================================
		; A0..A2 and D and E0..E2 are outputs
		
		BSF STATUS, RP0

		MOVLW 0xD8
		MOVWF ( 0x80 ^ TRISA )
		
		MOVLW 0x00
		MOVWF ( 0x80 ^ TRISD )
		
		MOVLW 0xF8
		MOVWF ( 0x80 ^ TRISE )
		
		BCF STATUS, RP0
		
				
                ; ===========================================================
		; beep

		CBLOCK
			WBeepCounter
		ENDC
		CLRF WBeepCounter
		MOVLW H'02'
		MOVWF PORTE_SHADOW
		CALL  PORTE_FLUSH
		
WBeepLoop
		BSF PORTA_SHADOW, 1
		CALL PORTA_FLUSH
		CALL WWAIT
		BCF PORTA_SHADOW, 1
		CALL PORTA_FLUSH
		CALL WWAIT
		DECFSZ WBeepCounter, f
			GOTO WBeepLoop


                ; ===========================================================
		; activate the LEDs
		
		BSF   PORTA_SHADOW, 2
		CALL  PORTA_FLUSH	
		
		MOVLW H'04'
		MOVWF PORTE_SHADOW
		CALL  PORTE_FLUSH	
		
		MOVLW H'55' ^ H'FF'
		MOVWF PORTD_SHADOW
		CALL PORTD_FLUSH
		

       
;************************ MAIN PROGRAM **************************************
main                               ; Start of the main program

       banksel     ANSEL           ; Bank containing register ANSEL
       clrf        ANSEL           ; Clears registers ANSEL and ANSELH
       clrf        ANSELH          ; All pins are digital
       
       banksel     TRISB           ; Selects bank containing register TRISB
       clrf        TRISB           ; All port B pins are configured as outputs
       
       banksel     OPTION_REG      ; Bank containing register OPTION_REG
       bcf         OPTION_REG,T0CS ; TMR0 counts pulses from oscillator       
       bcf         OPTION_REG,PSA  ; Prescaler is assign to timer TMR0
       
       bsf         OPTION_REG,PS0  ; Prescaler rate is 1:256
       bsf         OPTION_REG,PS1
       bsf         OPTION_REG,PS2
       
       banksel     INTCON          ; Bank containing register INTCON
       bsf         INTCON,TMR0IE   ; TMR0 interrupt overflow enabled
       bsf         INTCON,GIE      ; Global interrupt enabled
 
       banksel     PORTD           ; Bank containing register PORTB
       clrf        PORTD           ; Clears port B
		clrf temp_timer
loop


       goto        loop            ; Remain here

       end

the problem is i cant set increment a var in the interupt section.. am i'm doing something wrong??
 
BUMP!!

no respons..

i really need help on this. the interrupts work and the timer 2 but somehow it won't let me output it on the 7-segments. plz help!!
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…