/********************************************************************* * Flowcode Stepper Motor Component Code * * File: Stepper_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 * -------+----+----------------------------------------------------- * 180707 | BR | Created * | | * | | * | | * | | * * * ********************************************************************/ /********************************************************************* Return & parameter types: void char short char* Pin directions: 0 = OUTPUT 2 = INPUT 3 = BIDIRECTIONAL Macro substitutions: %a = ?? %b = ?? %c = ?? %d = ?? %e = ?? %f = ?? %g = ?? %h = ?? %i = ?? %j = ?? ********************************************************************** [Settings] CLSID={} IsAnalogue=0 MultipleAllowed=0 Description=Stepper Motor Component ********************************************************************** [Port] DesiredPort=0 PortMandatory=0 SamePortAsID=0 [Pins] Count=0 [PinPort] # PORTA = 0 # PORTB = 1 # PORTC = 2 # PORTD = 3 # PORTE = 4 [PinDesiredBit] [PinDirection] # DIR_INPUT = 2 # DIR_OUTPUT = 0 # DIR_BIDIRECTIONAL = 3 [PinMustUsePort] # boolean [SamePortAsPinX] # -1 = any pin # otherwise, the pin number [PinMustUsePin] # boolean [PinValue] # boolean (0 = off, 1 = on) ********************************************************************** [MacroNames] Count=5 1=GetDefines 2=IncrementStep 3=DecrementStep 4=EnableMotor 5=DisableMotor [MacroReturns] 1=void 2=void 3=void 4=void 5=void [MacroIsPrivate] 1=1 2=0 3=0 4=0 5=0 [MacroParameters_GetDefines] Count=0 [MacroParamTypes_GetDefines] [MacroParameters_IncrementStep] Count=0 [MacroParamTypes_IncrementStep] [MacroParameters_DecrementStep] Count=0 [MacroParamTypes_DecrementStep] [MacroParameters_EnableMotor] Count=0 [MacroParamTypes_EnableMotor] [MacroParameters_DisableMotor] Count=0 [MacroParamTypes_DisableMotor] ********************************************************************/ /******************************************************************** * ADDITIONAL CODE ********************************************************************/ /*InitialisationCode_Start*/ /*InitialisationCode_End*/ /*InterruptCode_Start*/ /*InterruptCode_End*/ /******************************************************************** * FUNCTIONS ********************************************************************/ void GetDefines() { /*Macro_GetDefines_Start*/ } //Dummy end of function to allow defines to be added correctly //common defines #define MX_TRIS1 %b //trisb #define MX_PORT1 %a //portb #define MX_PIN1 %c //0 #define MX_TRIS2 %b #define MX_PORT2 %a #define MX_PIN2 %d //1 #define MX_TRIS3 %b #define MX_PORT3 %a #define MX_PIN3 %e //2 #define MX_TRIS4 %b #define MX_PORT4 %a #define MX_PIN4 %f //3 #define MX_STEP_TYPE %g //0 = full step, 1 = half step char step_pattern_full[4] = {0x05, 0x09, 0x0a, 0x06}; char step_pattern_half[8] = {0x05, 0x01, 0x09, 0x08, 0x0a, 0x02, 0x06, 0x04}; char step = 0; // Dummy function to close the defines section off void CUSTOM_Dummy_Function(); void CUSTOM_Dummy_Function() { /*Macro_GetDefines_End*/ } void IncrementStep() { /*Macro_IncrementStep_Start*/ char cur_step; #if MX_STEP_TYPE == 0 { if (step == 3) step = 0; else step = step + 1; cur_step = step_pattern_full[step]; } #else { if (step == 7) step = 0; else step = step + 1; cur_step = step_pattern_half[step]; } #endif if(test_bit(cur_step, 0)) set_bit (MX_PORT1, MX_PIN1); else clear_bit (MX_PORT1, MX_PIN1); if(test_bit(cur_step, 1)) set_bit (MX_PORT2, MX_PIN2); else clear_bit (MX_PORT2, MX_PIN2); if(test_bit(cur_step, 2)) set_bit (MX_PORT3, MX_PIN3); else clear_bit (MX_PORT3, MX_PIN3); if(test_bit(cur_step, 3)) set_bit (MX_PORT4, MX_PIN4); else clear_bit (MX_PORT4, MX_PIN4); /*Macro_IncrementStep_End*/ } void DecrementStep() { /*Macro_DecrementStep_Start*/ char cur_step; #if MX_STEP_TYPE == 0 { if (step == 0) step = 3; else step = step - 1; cur_step = step_pattern_full[step]; } #else { if (step == 0) step = 7; else step = step - 1; cur_step = step_pattern_half[step]; } #endif if(test_bit(cur_step, 0)) set_bit (MX_PORT1, MX_PIN1); else clear_bit (MX_PORT1, MX_PIN1); if(test_bit(cur_step, 1)) set_bit (MX_PORT2, MX_PIN2); else clear_bit (MX_PORT2, MX_PIN2); if(test_bit(cur_step, 2)) set_bit (MX_PORT3, MX_PIN3); else clear_bit (MX_PORT3, MX_PIN3); if(test_bit(cur_step, 3)) set_bit (MX_PORT4, MX_PIN4); else clear_bit (MX_PORT4, MX_PIN4); /*Macro_DecrementStep_End*/ } void EnableMotor() { /*Macro_EnableMotor_Start*/ clear_bit(MX_TRIS1, MX_PIN1); clear_bit(MX_PORT1, MX_PIN1); clear_bit(MX_TRIS2, MX_PIN2); clear_bit(MX_PORT2, MX_PIN2); clear_bit(MX_TRIS3, MX_PIN3); clear_bit(MX_PORT3, MX_PIN3); clear_bit(MX_TRIS4, MX_PIN4); clear_bit(MX_PORT4, MX_PIN4); /*Macro_EnableMotor_End*/ } void DisableMotor() { /*Macro_DisableMotor_Start*/ set_bit(MX_TRIS1, MX_PIN1); clear_bit(MX_PORT1, MX_PIN1); set_bit(MX_TRIS2, MX_PIN2); clear_bit(MX_PORT2, MX_PIN2); set_bit(MX_TRIS3, MX_PIN3); clear_bit(MX_PORT3, MX_PIN3); set_bit(MX_TRIS4, MX_PIN4); clear_bit(MX_PORT4, MX_PIN4); /*Macro_DisableMotor_End*/ }