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.

Making use of RB7

Status
Not open for further replies.

Suraj143

Active Member
Here is the data lookup table in my seven segment display. Segment is connected to PORTB in PIC16F628A
Code:
TABLE   addwf        PCL,f
	   retlw        b'00111111'	; display number 0
	   retlw	b'00000110'	; display number 1
	   retlw	b'01011011'	; display number;2
	   retlw	b'01001111'	; display number 3
	   retlw	b'01100110'	; display number 4
	   retlw	b'01101101'	; display number 5
	   retlw	b'01111101'	; display number 6
	   retlw	b'00000111'	; display number 7
	   retlw	b'01111111'	; display number 8
	   retlw	b'01101111'	; display number 9

You can see the last bit (RB7) is all zero’s. I want to make that bit into a separate output.
That means when a number shows in the segment when I set that bit high separately it must active (make high).But now it’s not high it’s low. Because the current display value has drawn that bit also as low. This is the coding I use,

Code:
 bsf	PORTB,7

Can somebody tell me how to make that RB7 as a separate output?

Thanks a lot.
 
You need to combine the value from your table with bit 7 of port b. The easiest way is to copy it before you write to port b.

Code:
	call	TABLE		;Get segment value
	btfsc	PORTB,7		;is bit 7 set
	iorlw	b'10000000'	;yes, set bit 7 of W
	movwf	PORTB		;write it to port

Using the above code enables you to use bsf and bcf PORTB,7 elswhere in your code.

Mike.
 
Wow you have cleary understand my problem.Thanks a lot.Thats what I need.
the "iorlw command" Thanks again.

Mike is best
 
Hi mike, it worked but I had to add a delay in between the BSF & BCF in the output pin (RB7).this means like this.

Code:
	bsf	PORTB,7
		call	DELAY	;call 5 second delay
		bcf	PORTB,7

The output is ON for 5 seconds. But in this period the two seven segments are not working, current value is not showing (Multiplex mode is not working) because it is used by this delay.

If I just BSF (without a Delay) then it will return to segment multiplex mode & again
The iorlw b'10000000' code will be deactivated & output pin all the time low. Because I added your coding near the output (when I need the output).

Can I use your coding in between the multiplex mode? So when the output pin is high the current value in the two segments also showing. Will it work like that?
 
If you want the output to stay on for 5 seconds then you need to have a counter that you decrement whenever the second variable is decremented. You set the counter to 5 when you want the LED to be on and in the decrement second part of your code you test it for non zero. If it isn't zero you decrement it and turn on the LED. If it is zero you leave it alone and turn off the LED.

Mike.
 
Hi Mike a small question to ask from you, I did as you said

Now when the power up the two segments showing “00”

When I press the button it sets the FLAG bit to turn ON the counter as well as turn ON the PORTB,7th bit with your IORLW coding.
(At this time I need to turn on the output as well as display the “00”)

I cannot see the LED ON in the output. I can see only the segments showing “00”. Counter part & multiplex part is ok. The IORLW coding I have placed in the wrong place I think.
Can you please take a look.

Code:
 ;FLAG2,1 - flag bit which helps to turn ON the counter 

;2 segments multpiplex stuff


MULTIPLEX	bcf	PORTA,1		
		movf	SEGMANT1,0	;display the number in segmant 1
		call	TABLE
		movwf	PORTB
		bsf	PORTA,0		;display digit1
		call	DELAY

		bcf	PORTA,0
		movf	SEGMANT2,0	;display the number in segmant 2
		call	TABLE
		movwf	PORTB
		bsf	PORTA,1		;display digit2
		call	DELAY


;make 1s and check iS it 5s

	  	btfss	FLAG2,1		;is couter running?
	  	goto	MAIN		;no,go & check the button				
	  	decfsz  LoopCount,1	;count 50 times round loop
	  	goto	MULTIPLEX	;50*20mS = 1 second
	  	movlw	32H
	  	movwf	LoopCount
	  	incf	Seconds,1	;count seconds
	  	movlw	05H		;has it reached 5 seconds?
	  	xorwf	Seconds,0
	  	btfss	STATUS,2
	  	goto	MULTIPLEX	;no, loop around
		bcf	FLAG2,1		;yes, stop counter
		[B]bcf	PORTB,7	[/B]	;turn OFF the output after 5S
		goto	BEGIN

;check the button is pressed

MAIN		btfsc 	PORTA,2		;test the button (RA2)
	  	goto 	MULTIPLEX	;no then goto MULTIPLEX
	  	bsf	FLAG2,1		;yes then start the counter & display the MULTIPLEX
		goto	SETOUTPUT

;making the RB7 as an output

SETOUTPUT	call	TABLEP
	  	btfsc	PORTB,7
	  	iorlw	b'10000000'
	  	movwf	PORTB
	  	[B]bsf	PORTB,7	[/B]	;turn ON the output  		
	  	goto 	MULTIPLEX

Thanks a lot.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top