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.

2 Seven Segments + 1 Output

Status
Not open for further replies.

Suraj143

Active Member
Hi I’m doing a small project in PIC16F628A.I’m in the final part. I have got stuck in here.

This is how it works. When power up the two segments showing “00”.

At this time if I press the button the separate RA4 LED should turn ON while the two segments also must show the “00”

But here I can see only the segments showing “00” I cannot see the RA4 LED is ON.
(Here is the code, I have limit the code for easy view)

Code:
;FLAG2,0= button press flag bit
;FLAG2,1= counter ON flag bit
;LoopCount=50
;COUNTER = 5 (COUNTER has set to 5 seconds)

;DISPLAY THE TWO DIGITS

CLFLAG2		bcf	FLAG2,0		;clear the button press flag bit

MULTIPLEX	bcf	PORTA,1
		movf	SEGMANT1,0
		call	TABLEP
		movwf	PORTB
		bsf	PORTA,0		;display digit1
		call	DEL10ms

		bcf	PORTA,0
		movf	SEGMANT2,0
		call	TABLEP
		movwf	PORTB
		bsf	PORTA,1		;display digit2
		call	DEL10ms


;COUNTER PART
	  	btfss	FLAG2,1		;is counter running?
	  	goto	CHECKBUTTON1	;no, do other stuff	
		bsf	PORTA,4		;yes, turn ON the output
		decfsz  LoopCount,1	;count 50 times round loop
	  	goto	MULTIPLEX	;50*20mS = 1 second(total delay 20ms in multiplex mode)
	  	movlw	.50
	  	movwf	LoopCount
		decfsz	COUNTER,1
		goto	MULTIPLEX
		bcf	FLAG2,1		;stop counter
		bcf	PORTA,4		;turn OFF the output after 5 seconds
		goto	BEGIN


;check the button is pressed

CHECKBUTTON1	btfsc 	PORTA,3		;test the set button(RA3)
	  	goto	CHECKBUTTON2
	  	call 	DEL0.9ms	;debounce delay
	  	bsf	FLAG2,1		;enable the counter

CHECKBUTTON2	btfsc 	PORTA,2		;test the count up button (RA2)
	  	goto 	CLFLAG2
	  	countupstuff
I have use a pull-up resistor in RA4. Some times I can see the led lights up very dim mode. The value 470ohms.

Can somebody tell me what’s the mistake in my code?

Thanks a lot
 
hi suraj,

Could you post the code that initialises PORTA ??
 
RA4 is open drain. Show how the LED is connected. Does your code work as expected, if you use another pin to control the LED?
 
Hi Ericgibbs & eng1 Please help me I dont have anybody to ask.I'm in the last part in the program I have stucked here.

Here is the initialise part I have set everything correct.To check whether RA4 working I did a simple program. In that The LED worked well.Now in previous coding I have the problem so please help me.

Code:
                movlw	0x07
		movwf	CMCON
		bsf	STATUS,5
		movlw	b'00000000'
		movwf	TRISB
		movlw	b'01100' ;RA2,RA3 inputs
		movwf	TRISA
		bcf	STATUS,5
Actually this is what I want.When I power up the two segments must show the value "00".when I press the button it must turn ON the RA4 LED also must show the value "00" thats it.I dont need countup stuff.

Now I can see only the value "00".I cannot see the LED turns ON.

A little more about my program when I press the RA3 button it sets a FLAG2,1 bit to turn ON the counter.After that its reaching to MULTIPLEX mode mode & check the FLAG,1 bit is set.If is it set starts the counter.The counter has set to 5.After 5 seconds the LED turns off.

I dont like to use the interrupt for this.Please help me I'm in the last part.

Thanks
 
Last edited:
I imagine that you're using the internal oscillator? If so, RA6 and RA7 are available for general I/O and you could move the LED there, avoiding problems with RA4. The code would require minor changes.
 
hi suraj,
AsRA4 is o/c pin, whats the purpose of the 220R?

Also why don't you try eng1 suggestion?

EDIT: What does that '+' symbol near the LED indicate?
 
Last edited:
I'm using a crystal.I dont have anymore outputs.I'll try to move the LED to another pin & I'll put the input button to RA4 pin.

The LED's + mark is the possitive of the LED.

Can ysomebody see any mistake in my coding?

I'll tell the progress tomorrow.

Please dont leave me.
 
Hi all now its works well.The problem was that damn RA4 pin.

I configured that pin to an input pin & took a nice RA2 pin as an output.

I think RA4 cannot work in speed multiplex mode.

Thanks alot guys I'm really happy now.

I hate RA4 pin.
 
Hi Suraj143,
What you have is a typical RMW (Read Modify Write) issue.
You can find detailed info about this on Microchip or google.

When we work with P16 family, direct Port bit manipulation must be avoided.
Is preferable handle it through an Port image file register like this:

Code:
[FONT="Courier New"]
ra_image    res 1           ; register file to be the PORTA image

; Set PORTA,4
    bsf     ra_image,4      ; make bit 4 = HI
    movf    ra_image,w      ; move to w
    movwf   PORTA           ; PORTA change
    
    ; other code here
    
; Clear PORTA,4
    bcf     ra_image,4
    movf    ra_image,w
    movwf   PORTA
[/FONT]

Of course, all other pins must be manipulated through ra_image.
This methode must be used to change port pins, if not, in some circumstancies the verified effect on bit 4 can appens with others too.
Please, read about RMW.

Regards,
Jolino
 
Last edited:
If there is anyone out there that uses Proton PIC Basic, I have just revised my version of multiplexing with 7 segment displays;

**broken link removed**

The switching is Interrupt driven, so you can do almost anything you want, and the data will be shown/refreshed automatically.

Code:
Device 16F877

Xtal = 4

Dim Number As Word

Dim Temp_Byte As Byte
Dim Temp_Word As Word
Dim Ones As Byte
Dim Tens As Byte

Symbol Display_Ones = PORTA.3
Symbol Display_Tens = PORTA.2

Symbol TMR0_Enable = INTCON.5
Symbol TMR0_Overflow = INTCON.2
Symbol GIE = INTCON.7

Symbol Segment_1 = PORTC.0
Symbol Segment_2 = PORTC.1

ON_INTERRUPT Goto Int_Sub
			
Goto Initialization
			
Int_Sub:

	If TMR0_Overflow = 1 And TMR0_Enable = 1 Then
	   
	   TMR0_Overflow = 0                ' Check if TMR0 Overflow occurred
	   If Segment_1 = 1 Then            '  and alternate displays
	   	  Segment_1 = 0
		  PORTB = Tens
	   	  Segment_2 = 1
	   Else 
	   	  Segment_2 = 0
		  PORTB = Ones
	   	  Segment_1 = 1
	   EndIf
	
	EndIf
	
        GIE = 1	
	
	Context Restore
	
Initialization:

		ALL_DIGITAL = True
		PORTB_PULLUPS = False

		TRISB = %00000000               ' Make PORTB all outputs
		Low Segment_1                   '  and setup segment control Pins
		Low Segment_2

		TMR0_Enable = 0
		
		OPTION_REG.0 = 0                ' Setup TMR0
		OPTION_REG.1 = 0                ' 100 = ~8mS Interrupt
		OPTION_REG.2 = 1                ' 
		OPTION_REG.5 = 0                ' 
		TMR0 = 0
		TMR0_Enable = 1
				
		Ones = 0                        ' Reset variables
		Tens = 0                        '
		
        GIE = 1
		
Main:
	 
	 Number = 0

	 Repeat                                    ' Create a loop
	 	 
		 Temp_Word = Number                ' Move the Number register into Temp_Word
		 
		 Gosub Breakdown                   ' Break down to units (ones and tens)

		 Temp_Byte = Ones                  ' Now convert the ones data into segment
		 Gosub Encode_Segment_Display      '  information
		 Ones = Temp_Byte                  '
		 
		 Temp_Byte = Tens                  ' And the same for Tens
		 Gosub Encode_Segment_Display      ' 
		 Tens = Temp_Byte                  '
		 
		 Inc Number                        ' Increment the Number register
		 
		 DelaymS 500                       ' Small delay to slow down counting
		  
	 Until Number = 100                        ' Loop until number = 100, then reset

	 Goto Main                                 ' Loop forever
	 
Breakdown:

	Temp_Byte = DIG Temp_Word, 1               ' DIG Val, X will return the value of X in the number
	Tens = Temp_Byte                           '  For example DIG 9790, 3 = 9 
	Temp_Byte = DIG Temp_Word, 0               '  and DIG 7845, 0 = 5
	Ones = Temp_Byte                           ' Now we know how many ones/tens in the number
			
	Return                                     ' Leave the routine

Encode_Segment_Display:

	SELECT Temp_Byte
	    CASE 0                                 ' Turn  Temp_Byte into segment display data
	   		 Temp_Byte = %00111111
	    CASE 1			
	   		 Temp_Byte = %00000110
	    CASE 2			
			 Temp_Byte = %01011011
	    CASE 3			
	   		 Temp_Byte = %01001111
	    CASE 4			
	   		 Temp_Byte = %01100110
	    CASE 5			
	   		 Temp_Byte = %01101101 
	    CASE 6			
   			 Temp_Byte = %01111100
	    CASE 7			
 			 Temp_Byte = %00000111
	    CASE 8			
			 Temp_Byte = %01111111
	    CASE 9			
 			 Temp_Byte = %01100111
	    CASE ELSE
	   		 Temp_Byte = %00111111		 
	ENDSELECT
	
	Return
 
Gramo, too bad your program exceeds the Proton 50 line demo limitation. IMO most beginners are not likely to shell out $300 for a compiler till they get a grip on the basics.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top