Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 24th January 2009, 01:01 AM   #1
Default PIC16f628a , Timer1 and seven segments

Hello everybody:

I'm having a this problem (see attached pics) using pic16f628's timer 1, when applied to a seven segments display.

As you can see in the second pic , the segments A and G don't show up. In the first pic I'm using a different program . Here's the current program :

Code:
; Timer using PIC16F628


	list      p=16f628A            ; list directive to define processor
	#include <p16f628A.inc>        ; processor specific variable definitions
	ERRORLEVEL	0,	-302			;suppress bank selection messages

	__CONFIG _CP_OFF & _WDT_OFF & _BOREN_OFF & _PWRTE_OFF & _MCLRE_OFF & _LVP_OFF & _INTOSC_OSC_NOCLKOUT

	cblock 	0x20 	;start of general purpose registers
		w_temp      ;auxiliary for interrupt service
		status_temp
		J 			; auxiliary variables
		K			; 
        M           ;
		N			; 
		Dig1		; Digit number one on displays
		Dig2		
    	Dig3
	    Dig4	
	endc

   
;===========================  MAIN  =========================
;==========================  PROGRAM  =======================

 	org  0x00             ; processor reset vector
    goto Main

	org	 0x04							; Vector de interrupción.
	goto InterruptService

Main:

	movlw	0x07				;Turn comparators off and
	movwf	CMCON				;enable pins for I/O functions
  
;------ Ports configuration

   	bsf 	STATUS, RP0		;select bank 1
   	movlw 	b'00000001'		;set PortB <1:7> all outputs, PB0 as input
   	movwf 	TRISB
	movlw 	b'00111100'		
	movwf	TRISA			;set PortA <2:5> inputs, <0:1,6:7> outputs
    bsf     PIE1,0          ; TMR1 Overflow Interrupt Enable bit

	bcf		STATUS,RP0		; select bank 0
	clrf	PORTA
    movlw   b'00111100'     ;disables timer b0, internal clock b1, enable oscillator b3
    movwf   T1CON           ;prescale 1:8 b5-b4

	;bsf		PORTA,4			;two points clock
	  
    
	movlw  00h		; initialize counter
	movwf  Dig1	   
	movwf  Dig2	   
	movwf  Dig3	 
	movwf  Dig4

    movlw  b'11000000'
    movwf  INTCON   ;enable global AND peripheral interrupts 
    bsf    T1CON,0  ;start timer

Main_loop:
  
 call Display
 goto Main_loop


;------------------------------------------
; led conversion lookup table

led7
; in:  number in W
; out: 7-seg code in W in format B'xgfedcba'

	andlw   B'00001111'
	addwf   PCL,f
; format 		B'agfedcbx'
	
	retlw	B'10111110'		;0
	retlw	B'00000110'		;1
	retlw	B'11011010'		;2
	retlw	B'11001110'		;3
	retlw	B'01100110'		;4
	retlw	B'11101100'		;5
	retlw	B'11111100'		;6
	retlw	B'10000110'		;7
	retlw	B'11111110'		;8
	retlw	B'11101110'		;9

;-------------------------------------------
;	do some time by executing nested loops

shorttime:
    movlw   D'14'
    movwf   J
jloop:
	movlw	D'255'	; w = 255 decimal
	movwf	K		; K = w
kloop:
	decfsz	K,f		; K = K - 1 , skip next if zero
  	goto kloop
    decfsz J,F
    goto jloop
 return

Display:

    movlw   D'17'   ; D'17'
    movwf   M
mloop:

 movf Dig1,W  
 call led7
 movwf PORTB
 bcf  PORTA,7
 bsf  PORTA,0
 call shorttime

 movf Dig2,W  
 call led7
 movwf PORTB
 bcf  PORTA,0
 bsf  PORTA,1
 call shorttime

 movf Dig3,W  
 call led7
 movwf PORTB
 bcf  PORTA,1
 bsf  PORTA,6
 call shorttime

 movf Dig4,W  
 call led7
 movwf PORTB
 bcf  PORTA,6
 bsf  PORTA,7
 call shorttime

 decfsz M,F
 goto mloop

 return


InterruptService:
  
 movwf w_temp      ;copy W to temp register could be in any bank
 swapf STATUS,W    ;swap status to be saved into W
 bcf   STATUS,RP0  ;change to bank 0 regardless of current bank
 movwf status_temp ;save status to bank 0 register

 bcf  PIR1,0    ;clear register overflowed

 incf Dig1,F 	;checks if Dig1 > 10
 movf Dig1,W
 addlw -d'10'
 btfss STATUS,Z
 goto exit_int

 clrf Dig1
 incf Dig2,F 	;checks if Dig2 > 6
 movf Dig2,W
 addlw -d'6'
 btfss STATUS,Z
 goto exit_int
 
 clrf Dig2
 incf Dig3,F 	;checks if Dig3 > 10
 movf Dig3,W
 addlw -d'10'
 btfss STATUS,Z
 goto exit_int

 clrf Dig3
 incf Dig4,F 	;checks if Dig3 > 6
 movf Dig4,W
 addlw -d'6'
 btfss STATUS,Z
 goto exit_int

 clrf Dig4

exit_int:

 swapf status_temp,W ;register into W, sets bank to original state
 movwf STATUS      ;move W into STATUS ;register
 swapf w_temp,F    ;swap W_TEMP
 swapf w_temp,W    ;swap W_TEMP into W

 retfie

	END                       ; directive 'end of program'

What could be the problem?

t.i.a.


p.s. btw, I'm posting this thread using Opera browser. I cannot neither send a private message nor post a message (or thread) using firefox 2.0 anymore.
Attached Thumbnails
PIC16f628a , Timer1 and seven segments-ok.jpg   PIC16f628a , Timer1 and seven segments-no_ok.jpg  

Last edited by mabauti; 24th January 2009 at 01:04 AM.
mabauti is offline  
Old 24th January 2009, 03:26 AM   #2
Default

Try changing all the call led7 instructions to movlw 0xfe and see what happens.

Mike
Pommie is online now  
Old 24th January 2009, 04:20 AM   #3
Thumbs down Re:

still the same , a & g don't show up
mabauti is offline  
Old 24th January 2009, 04:44 AM   #4
Default

That is bits 6 and 7 of Port B which happens to be where the timer1 crystal would be connected to. And, I see you have enabled timer 1 oscillator.

Try changing it to,
Code:
		movlw	b'00110100'	;disables timer b0, internal clock b1, enable oscillator b3
		movwf	T1CON		;prescale 1:8 b5-b4
Mike.
Pommie is online now  
Old 24th January 2009, 05:48 AM   #5
Default

Hey, it worked

I tested the program using Oshon PIC simulator, so I trusted on this too much

Thank you a lot Pommie
mabauti is offline  
Reply

Tags
pica, segments, timer1

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
18F248 w/A6276 & Two seven-segments futz Micro Controllers 5 21st July 2008 05:45 AM
7 segments multiplexing colin mac Micro Controllers 8 28th November 2007 07:08 PM
2 Seven Segments + 1 Output Suraj143 Micro Controllers 16 3rd May 2007 07:37 AM
7 segments project hydrid Electronic Projects Design/Ideas/Reviews 4 19th February 2007 11:31 AM
4 Bit Bcd Input To 7 Segments Displays? thanosgen Electronic Projects Design/Ideas/Reviews 9 16th January 2007 12:42 PM



All times are GMT. The time now is 05:00 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker