Page 1 of 1

Pins from various ports for 7 segment display

Posted: Mon Jul 30, 2012 8:23 pm
by yousafzai
Hi

I am using demo Flowcode for PIC V5.2. I am using pic16f676 to drive three 7 segment digits. My problem is that pic16f676 has two ports each of six pins. That mean if i assign portc.0 to segment A , then i am left with segment G and Segment dot as unconnected. If i try to connect these pins to PortA then all pins of from Segment A to Segment F also change to PORTA. Is there any solution for this?


Best Regards
yosuafzai

Re: Pins from various ports for 7 segment display

Posted: Mon Jul 30, 2012 10:02 pm
by Enamul
HI,
It has solution but it will take time as we have to change
C:\Program Files (x86)\Flowcode\v5\Components\FC5_PIC_7seg.c

Enamul

Edit: I have changed the file to have that effect but still can't sort out it...seems it's an ocx issue..

Re: Pins from various ports for 7 segment display

Posted: Tue Jul 31, 2012 12:38 am
by yousafzai
Any clue how to change this file?




Best Regards

yousafzai

Re: Pins from various ports for 7 segment display

Posted: Wed Aug 15, 2012 2:08 pm
by Enamul
Hi,
I have manged to do it for you in c code..but everything in c code in supplementary code..even the connection of 7segment as FC is not allowing you to use different port for different segment although this PIC 16f676 doesn't have 8 bit in any port..a pain!!

I have mentioned the connection I have used..you can change that according to your requirement in the supplementary code..which is in FCV5 in Build>project options>General options..

I have used common anode as display type but you can change that in the beginning of code..1 for common anode and 0 for common cathode

Code: Select all

#define MX_7SEG_COM_TYPE		1
I have shown how to display digit using c code like..

Code: Select all

ShowDigit(3,0);
Here 3 is the digit to display and 0 for DP..if you want dp to on; put 1 here.

Although I haven't used clear digit macro but it's implemented, you can use that easily to clear 7segment...By just adding the following code in a c code box..

Code: Select all

ClearDigit();
I have tested the program in Real PIC and so it should work in hardware.. :)
Enamul
7Seg.fcf
(13.6 KiB) Downloaded 481 times
7Seg.hex
(1.47 KiB) Downloaded 426 times
7seg.png
(34.96 KiB) Downloaded 9422 times

Re: Pins from various ports for 7 segment display

Posted: Wed Aug 15, 2012 4:50 pm
by Benj
Hello,

Yes unfortunately this is a limitation of the VB OCX file. You can work around by hardcoding the connections using the customise code and editing the connection definitions in the defines function or you can do how Enamul has shown which is to rip out the 7 seg code and instead place a hard coded version into the supplementary code slot.

Re: Pins from various ports for 7 segment display

Posted: Wed Aug 15, 2012 5:03 pm
by Enamul
Hi Ben,
I was looking this issue when you are in leave about changing c component of 7segment to customize the connection. I have edited the c code like LCD which enables us to use different port for different pin. But no success in getting the option in changing pin wise port. :( Can you please tell me how to edit the connection definitions in the defines function?
Thanks,
Enamul

Re: Pins from various ports for 7 segment display

Posted: Wed Aug 15, 2012 5:19 pm
by Benj
Hello,

Ok In the defines section for a single 7-seg display we have this code.

Code: Select all

#define %a_SEG_PORT	port%b
#define %a_SEG_TRIS		tris%b
#define %a_COM_PORT	port%c
#define %a_COM_TRIS	tris%c
#define %a_SEG_PIN0		%d
#define %a_SEG_PIN1		%e
#define %a_SEG_PIN2		%f
#define %a_SEG_PIN3		%g
#define %a_SEG_PIN4		%h
#define %a_SEG_PIN5		%i
#define %a_SEG_PIN6		%j
#define %a_SEG_PIN7		%k
#define %a_COM_PIN		%l
#define %a_COM_TYPE	%m
It looks like a single port is expected so we can create a new define to hold the second port and hard code the other defines so they work with the properties passed from Flowcode.

Code: Select all

#define %a_SEG_PORT	porta
#define %a_SEG_TRIS		trisa
#define %a_SEG_PORT2	portc
#define %a_SEG_TRIS2	trisc
#define %a_COM_PORT	portc
#define %a_COM_TRIS	trisc
#define %a_SEG_PIN0		0
#define %a_SEG_PIN1		1
#define %a_SEG_PIN2		2
#define %a_SEG_PIN3		3
#define %a_SEG_PIN4		4
#define %a_SEG_PIN5		5
#define %a_SEG_PIN6		0
#define %a_SEG_PIN7		1
#define %a_COM_PIN		2
#define %a_COM_TYPE	%m
Because only one port definition was used previously we need to switch to the new definition when referencing a pin on the new port, in this case pins 6 and 7.

Show digit code.

Code: Select all

		if (cSegmentValue & 0x40)
		{
			FC_CAL_Bit_High_DDR(%a_SEG_PORT2, %a_SEG_TRIS2, %a_SEG_PIN6);
		}
		else
		{
			FC_CAL_Bit_Low_DDR(%a_SEG_PORT2, %a_SEG_TRIS2, %a_SEG_PIN6);
		}

		if (cSegmentValue & 0x80)
		{
			FC_CAL_Bit_High_DDR(%a_SEG_PORT2, %a_SEG_TRIS2, %a_SEG_PIN7);
		}
		else
		{
			FC_CAL_Bit_Low_DDR(%a_SEG_PORT2, %a_SEG_TRIS2, %a_SEG_PIN7);
		}

Re: Pins from various ports for 7 segment display

Posted: Wed Aug 15, 2012 5:59 pm
by Enamul
Hi,
In my modified one I have done similar thing which I was thinking for any pic..that's why I have modified for upto 5 ports. But it seems that the component code a bit changed in FCV5.4 although mine one was for FCV5.2.
Enamul

Edit:
ok..I got it..still you can't change port in FC connection window but as it is done hard core..so it will work in hardware and I can see the changes in c code..and good thing is that it simulates in FC. Also I think will work in demo version of FCv5
Thanks al lot Ben. You are real boss. :)
@yosuafzai
you can back up your c component code for 7 seg and put the attached one in the component folder in FCV5. Now you can put 7seg component in panel and use normally 7segment don't need to connect the component as it is done in c code..

Re: Pins from various ports for 7 segment display

Posted: Wed Aug 15, 2012 8:11 pm
by yousafzai
Hi Enamul
Thanks a lot. I really appreciate your effort. I will test the code both in FC and in real hardware and will let you know. :D


Best Regards
yousafzai

Re: Pins from various ports for 7 segment display

Posted: Sun Aug 19, 2012 3:17 am
by yousafzai
Hi Enamul
It works great. I have studied the file that you sent me for single segment and have modified for 4 seg which also works fine.


Thanks a lot for the nice (and timely) help.


Regards

Re: Pins from various ports for 7 segment display

Posted: Sun Aug 19, 2012 11:24 am
by Enamul
Hi,
Thanks for the head into the code. I am certain others will get help from it.

Re: Pins from various ports for 7 segment display

Posted: Fri Jul 11, 2014 12:39 pm
by prasha920
hi,
same issue of using multiple port lines for driving 7 segment display..

yes got that in FCv5,
can someone please help me with it for FCV4.5