change 7 seg from common anode to common cathode ??

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
bader357
Posts: 5
Joined: Sun Nov 02, 2008 2:55 pm
Contact:

change 7 seg from common anode to common cathode ??

Post by bader357 »

What I must change on the "7 segment component code" C-program to change from common anode to common cathode.

Code: Select all

/*********************************************************************
 *                    Flowcode LED7SEG1 Component Code
 *
 * File: LED7SEG1_Code.c
 *
 * (c) 2007 Matrix Multimedia Ltd.
 * http://www.matrixmultimedia.com
 *
 * Software License Agreement
 *
 * The software supplied herewith by Matrix Multimedia Ltd (the
 * “Company”) for its Flowcode graphical programming language is
 * intended and supplied to you, the Company’s customer, for use
 * solely and exclusively on the Company's products. The software
 * is owned by the Company, and is protected under applicable
 * copyright laws. All rights are reserved. Any use in violation
 * of the foregoing restrictions may subject the user to criminal
 * sanctions under applicable laws, as well as to civil liability
 * for the breach of the terms and conditions of this licence.
 *
 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
 * Changelog:
 *
 *  date  | by | description
 * -------+----+-----------------------------------------------------
 * 120607 | BR | Created
 * 160707 | ST | Modified to work with CTL file
 *        |    |
 *        |    |
 *        |    |
 *
 *
 *
 ********************************************************************/

/*********************************************************************

 Return & parameter types:
   void
   char
   short
   char*

 Pin directions:
   0 = OUTPUT
   2 = INPUT
   3 = BIDIRECTIONAL

    %a = SegmentPort
    %b = CommonPort
    %c = Pattern0
    %d = Pattern1
    %e = Pattern2
    %f = Pattern3
    %g = Pattern4
    %h = Pattern5
    %i = Pattern6
    %j = Pattern7
    %k = Pattern8
    %l = Pattern9
    %m = PatternDP
    %n = CommonMask
    %o = CommonMask_Inv
    %p = SegmentMask_Inv
    %q = CommonAnode



**********************************************************************

[Settings]
CLSID={C5A410B9-AFEA-4f62-B6D1-78B244980168}

**********************************************************************

[MacroNames]
Count=1
1=ShowDigit

[MacroReturns]
1=void

[MacroIsPrivate]
1=0

[MacroParameters_ShowDigit]
Count=2
1=Value
2=DecimalPoint

[MacroParamTypes_ShowDigit]
1=char
2=char

 ********************************************************************/

/********************************************************************
 * ADDITIONAL CODE
 ********************************************************************/

/*InitialisationCode_Start*/
/*InitialisationCode_End*/

/*InterruptCode_Start*/
/*InterruptCode_End*/



/********************************************************************
 * FUNCTIONS
 ********************************************************************/

void ShowDigit(char Value, char DecimalPoint)
{
/*Macro_ShowDigit_Start*/
    #if (%a == 0)
      #define MX_7SEG1_SEGMENT_PORT  porta
      #define MX_7SEG1_SEGMENT_TRIS  trisa
    #endif
    #if (%a == 1)
      #define MX_7SEG1_SEGMENT_PORT  portb
      #define MX_7SEG1_SEGMENT_TRIS  trisb
    #endif
    #if (%a == 2)
      #define MX_7SEG1_SEGMENT_PORT  portc
      #define MX_7SEG1_SEGMENT_TRIS  trisc
    #endif
    #if (%a == 3)
      #define MX_7SEG1_SEGMENT_PORT  portd
      #define MX_7SEG1_SEGMENT_TRIS  trisd
    #endif
    #if (%a == 4)
      #define MX_7SEG1_SEGMENT_PORT  porte
      #define MX_7SEG1_SEGMENT_TRIS  trise
    #endif

    #if (%b == 0)
      #define MX_7SEG1_COMMON_PORT   porta
      #define MX_7SEG1_COMMON_TRIS   trisa
    #endif
    #if (%b == 1)
      #define MX_7SEG1_COMMON_PORT   portb
      #define MX_7SEG1_COMMON_TRIS   trisb
    #endif
    #if (%b == 2)
      #define MX_7SEG1_COMMON_PORT   portc
      #define MX_7SEG1_COMMON_TRIS   trisc
    #endif
    #if (%b == 3)
      #define MX_7SEG1_COMMON_PORT   portd
      #define MX_7SEG1_COMMON_TRIS   trisd
    #endif
    #if (%b == 4)
      #define MX_7SEG1_COMMON_PORT   porte
      #define MX_7SEG1_COMMON_TRIS   trise
    #endif

    //set pattern array for the display
	rom char* cSegmentArray = {%c, %d, %e, %f, %g, %h, %i, %j, %k, %l};

	//get pattern for digit
	char cSegmentValue = cSegmentArray[Value % 10];
	if (DecimalPoint) cSegmentValue &= %m;

	//set up ports
	MX_7SEG1_COMMON_TRIS = MX_7SEG1_COMMON_TRIS & %o;
	MX_7SEG1_SEGMENT_TRIS = MX_7SEG1_SEGMENT_TRIS & %p;
	//MX_7SEG1_COMMON_PORT = MX_7SEG1_COMMON_PORT & %o;

	//display the digit
    #if (%q == 1)
		//common anode
		MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & %p) | cSegmentValue;
		MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | %n);
	#else
		//common cathode
		MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT | ~%p) & (~cSegmentValue);
		MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & %o);
	#endif

	//undefine symbols
    #undef MX_7SEG1_SEGMENT_PORT
    #undef MX_7SEG1_SEGMENT_TRIS
    #undef MX_7SEG1_COMMON_PORT
    #undef MX_7SEG1_COMMON_TRIS

/*Macro_ShowDigit_End*/
}

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: change 7 seg from common anode to common cathode ??

Post by Benj »

Hello Badger

You should just have to edit this line.

Code: Select all

//display the digit
#if (%q == 1)
and set it to this

Code: Select all

//display the digit
#if (0 == 1)
It looks like the C code file has already been updated to allow for common cathode displays but the actual components have not yet been updated to reflect the C code changes.

Let me know how you get on.

bader357
Posts: 5
Joined: Sun Nov 02, 2008 2:55 pm
Contact:

Re: change 7 seg from common anode to common cathode ??

Post by bader357 »

Benj wrote:Hello Badger

You should just have to edit this line.

Code: Select all

//display the digit
#if (%q == 1)
and set it to this

Code: Select all

//display the digit
#if (0 == 1)
It looks like the C code file has already been updated to allow for common cathode displays but the actual components have not yet been updated to reflect the C code changes.

Let me know how you get on.
Hello Benj, thanks for the tip. I want to try in next day and tell you the results.

George_B
Posts: 128
Joined: Wed Jul 04, 2012 11:21 pm
Location: Greece
Has thanked: 51 times
Been thanked: 19 times
Contact:

Re: change 7 seg from common anode to common cathode ??

Post by George_B »

Hi to all, i know this is an old thread but i have a question about.


I am using single 7-seg components in my program. The device is the 18F8622

I need five single 7-seg components in my program. I am getting the error messages below when i compile to HEX.

Que_Informator.c(1740:2): error: unknown identifier 'MX_7SEG1_SEGMENT_TRIS'
Que_Informator.c(1740:2): error: invalid operand 'MX_7SEG1_SEGMENT_TRIS'
Que_Informator.c(1740:24): error: failed to generate expression
Que_Informator.c(1748:2): error: unknown identifier 'MX_7SEG1_SEGMENT_PORT'
Que_Informator.c(1748:2): error: invalid operand 'MX_7SEG1_SEGMENT_PORT'
Que_Informator.c(1748:24): error: failed to generate expression
Que_Informator.c success

failure

Return code = 1


I just realized that my program works OK if i use only three 7-seg displays but NOT if i add more than three 7-seg components.
Is there anything that i should know about and i don't ?

Regards
George

George_B
Posts: 128
Joined: Wed Jul 04, 2012 11:21 pm
Location: Greece
Has thanked: 51 times
Been thanked: 19 times
Contact:

Re: change 7 seg from common anode to common cathode ??

Post by George_B »

I will answer to my question above since i found out what the problem was so anybody with this issue can read this solution.

The problem was that in the "ShowDigit" custon code (right click on the 7seg component and select custon code) ,where only the port a, b ,c,d,e was defined.
For my project i have connected my fourth and fifth display to port 'f' and port 'h' which are not defined in this custom code and this is the reason of the error above.
If you want to add more than 3 single 7 seg displays to your project, you have to add the definitions for those extra displays as shown below in RED bold text:



#define MX_7SEG_SEG_PORT_%a
#define MX_7SEG_COM_PORT_%b

#ifdef MX_7SEG_SEG_PORT_0 //Segment Port Definitions
#define MX_7SEG1_SEGMENT_PORT porta
#define MX_7SEG1_SEGMENT_TRIS trisa
#endif

#ifdef MX_7SEG_SEG_PORT_1
#define MX_7SEG1_SEGMENT_PORT portb
#define MX_7SEG1_SEGMENT_TRIS trisb
#endif

#ifdef MX_7SEG_SEG_PORT_2
#define MX_7SEG1_SEGMENT_PORT portc
#define MX_7SEG1_SEGMENT_TRIS trisc
#endif

#ifdef MX_7SEG_SEG_PORT_3
#define MX_7SEG1_SEGMENT_PORT portd
#define MX_7SEG1_SEGMENT_TRIS trisd
#endif

#ifdef MX_7SEG_SEG_PORT_4
#define MX_7SEG1_SEGMENT_PORT porte
#define MX_7SEG1_SEGMENT_TRIS trise
#endif

#ifdef MX_7SEG_SEG_PORT_5
#define MX_7SEG1_SEGMENT_PORT portf
#define MX_7SEG1_SEGMENT_TRIS trisf
#endif

#ifdef MX_7SEG_SEG_PORT_6
#define MX_7SEG1_SEGMENT_PORT portg
#define MX_7SEG1_SEGMENT_TRIS trisg
#endif

#ifdef MX_7SEG_SEG_PORT_7
#define MX_7SEG1_SEGMENT_PORT porth
#define MX_7SEG1_SEGMENT_TRIS trish
#endif


#ifdef MX_7SEG_COM_PORT_0 //Common Port Definitions
#define MX_7SEG1_COMMON_PORT porta
#define MX_7SEG1_COMMON_TRIS trisa
#endif

#ifdef MX_7SEG_COM_PORT_1
#define MX_7SEG1_COMMON_PORT portb
#define MX_7SEG1_COMMON_TRIS trisb
#endif

#ifdef MX_7SEG_COM_PORT_2
#define MX_7SEG1_COMMON_PORT portc
#define MX_7SEG1_COMMON_TRIS trisc
#endif

#ifdef MX_7SEG_COM_PORT_3
#define MX_7SEG1_COMMON_PORT portd
#define MX_7SEG1_COMMON_TRIS trisd
#endif

#ifdef MX_7SEG_COM_PORT_4
#define MX_7SEG1_COMMON_PORT porte
#define MX_7SEG1_COMMON_TRIS trise
#endif

#ifdef MX_7SEG_COM_PORT_5
#define MX_7SEG1_COMMON_PORT portf
#define MX_7SEG1_COMMON_TRIS trisf
#endif

#ifdef MX_7SEG_COM_PORT_6
#define MX_7SEG1_COMMON_PORT portg
#define MX_7SEG1_COMMON_TRIS trisg
#endif

#ifdef MX_7SEG_COM_PORT_7
#define MX_7SEG1_COMMON_PORT porth
#define MX_7SEG1_COMMON_TRIS trish
#endif


//set pattern array for the display
#ifdef _BOOSTC
rom char* cSegmentArray = {%c, %d, %e, %f, %g, %h, %i, %j, %k, %l};
#endif
#ifdef HI_TECH_C
const char cSegmentArray[] = {%c, %d, %e, %f, %g, %h, %i, %j, %k, %l};
#endif

//get pattern for digit
char cSegmentValue = cSegmentArray[Value % 10];
if (DecimalPoint)
cSegmentValue = cSegmentValue & %m;

//set up ports
MX_7SEG1_COMMON_TRIS = MX_7SEG1_COMMON_TRIS & %o;
MX_7SEG1_SEGMENT_TRIS = MX_7SEG1_SEGMENT_TRIS & %p;

#define MX_7SEG_COM_ANODE_%q

//display the digit
#ifdef MX_7SEG_COM_ANODE_1

//common anode
MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & %p) | cSegmentValue;
MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | %n);

#else

//common cathode
MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & %p) | ~cSegmentValue;
MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & %o);

#endif

//undefine symbols
#undef MX_7SEG1_SEGMENT_PORT
#undef MX_7SEG1_SEGMENT_TRIS
#undef MX_7SEG1_COMMON_PORT
#undef MX_7SEG1_COMMON_TRIS
#undef MX_7SEG_SEG_PORT_%a
#undef MX_7SEG_COM_PORT_%b
#undef MX_7SEG_COM_ANODE_%q


The above solution worked for me, i hope this helps.

George

Post Reply