/********************************************************************* * Flowcode Seven Segment Display Component Code * * File: PIC_7seg.c * * (c) 2009 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 * 140309 | BR | Added Common Cathode / Common Anode Operation. * 210409 | BR | Added Clear Digit Function * 130509 | BR | Added % definitions to DefinesCode section * 030909 | BR | Added BoostC and HiTECH definitions * 110111 | SK | ClearDigit now only affects the common pin. Now matches component simulation. ********************************************************************/ /********************************************************************* Return & parameter types: void char short char* Pin directions: 0 = OUTPUT 2 = INPUT 3 = BIDIRECTIONAL ********************************************************************** [Settings] CLSID={CBC38511-A335-4CDD-BBAC-AE067B64AAE2} IsAnalogue=0 MultipleAllowed=1 Description=Seven Segment Display Flowcode Component ********************************************************************** [MacroNames] Count=2 1=ShowDigit 2=ClearDigit [MacroReturns] 1=void 2=void [MacroIsPrivate] 1=0 2=0 [MacroParameters_ShowDigit] Count=2 1=Value 2=DecimalPoint [MacroParamTypes_ShowDigit] 1=char 2=char [MacroParameters_ClearDigit] Count=0 [MacroParamTypes_ClearDigit] ********************************************************************/ /******************************************************************** * ADDITIONAL CODE ********************************************************************/ /*DefinesCode_Start*/ /**** Macro Substitutions **** %a = Segment Port %b = Common Port %c = Pattern 0 %d = Pattern 1 %e = Pattern 2 %f = Pattern 3 %g = Pattern 4 %h = Pattern 5 %i = Pattern 6 %j = Pattern 7 %k = Pattern 8 %l = Pattern 9 %m = Pattern DP %n = Common Mask %o = Common Mask Inverted %p = Segment Mask Inverted %q = Common Anode Display Type ******************************/ /*DefinesCode_End*/ /*InitialisationCode_Start*/ /*InitialisationCode_End*/ /*InterruptCode_Start*/ /*InterruptCode_End*/ /******************************************************************** * FUNCTIONS ********************************************************************/ void ShowDigit(char Value, char DecimalPoint) { /*Macro_ShowDigit_Start*/ #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_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 //set pattern array for the display #ifdef _BOOSTC rom char* cSegmentArray = {%c, %d, %e, %f, %g, %h, %i, %j, %k, %l, 136, 160, 131, 198, 167, 161, 134, 132, 142, 194, 137, 139, 207, 239, 225, 138, 199, 170, 171, 163, 140, 152, 175, 146, 135, 193, 227, 213, 226, 155, 145, 164, 191, 247, 156,}; #endif #ifdef HI_TECH_C const char cSegmentArray[] = {%c, %d, %e, %f, %g, %h, %i, %j, %k, %l, 136, 160, 131, 198, 167, 161, 134, 132, 142, 194, 137, 139, 207, 239, 225, 138, 199, 170, 171, 163, 140, 152, 175, 146, 135, 193, 227, 213, 226, 155, 145, 164, 191, 247, 156,}; #endif //get pattern for digit char cSegmentValue = cSegmentArray[Value % 45]; 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 /*Macro_ShowDigit_End*/ } void ClearDigit (void) { /*Macro_ClearDigit_Start*/ #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_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 #define MX_7SEG_COM_ANODE_%q //clear the digit #ifdef MX_7SEG_COM_ANODE_1 //common anode MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & %o); #else //common cathode MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | %n); #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 /*Macro_ClearDigit_End*/ }