test my code

Discussion in 'Programmer's Corner' started by ht systems, Aug 18, 2011.

  1. ht systems

    Thread Starter Member

    Aug 2, 2011
    71
    1
    hello , this is my new code for a flasher led , will u see if there is a problem in it ?
    //************************************************************************************
    //**
    //** File name: C:\Program Files\Flowcode V4\???? ????\Flowcode1.c
    //** Generated by: Flowcode v4.2.3.58
    //** Date: Friday, August 19, 2011 04:31:52
    //** Licence: Professional
    //** Registered to: 2A1RRG
    //**
    //**
    //** http://www.matrixmultimedia.com
    //************************************************************************************

    #define MX_PIC
    //Defines for microcontroller
    #define P16F630
    #define MX_EE
    #define MX_EE_TYPE1
    #define MX_EE_SIZE 128
    //Functions
    #define MX_CLK_SPEED 19660800
    #ifdef _BOOSTC
    #include <system.h>
    #endif
    #ifdef
    HI_TECH_C
    #include <pic.h>
    #endif
    //Configuration data
    #ifdef _BOOSTC
    #pragma DATA 0x2007, 0x3fef
    #endif
    #ifdef
    HI_TECH_C
    __CONFIG(0x3fef);
    #endif
    //Internal functions
    #include "C:\Program Files\Flowcode V4\FCD\internals.h"
    //Macro function declarations

    //Variable declarations

    //Defines:
    /**** Macro Substitutions ****
    portc = LED Port Register
    trisc = LED Data Direction Register
    2 = LED Pin Mask
    1 = LED Active Polarity
    ******************************/



    //LED0: //Macro function declarations
    void FCD_LED0_LEDOn();
    void FCD_LED0_LEDOff();


    //LED0: //Macro implementations

    void FCD_LED0_LEDOn()
    {

    trisc = trisc & ~2;
    //Convert pin to output
    if( 1 ) //Active high polarity
    portc = portc | 2;
    else //Active low polarity
    portc = portc & ~2;
    }
    void FCD_LED0_LEDOff()
    {

    trisc = trisc & ~2;
    //Convert pin to output
    if( 1 ) //Active high polarity
    portc = portc & ~2;
    else //Active low polarity
    portc = portc | 2;
    }
    //Macro implementations
    void main()
    {

    //Initialisation
    cmcon = 0x07;

    //Interrupt initialisation code
    option_reg = 0xC0;

    //Loop
    //Loop: While 1
    while (1)
    {
    //Call Component Macro
    //Call Component Macro: LED(0)::LEDOn
    FCD_LED0_LEDOn();

    //Delay
    //Delay: 1 s
    delay_s(1);

    //Call Component Macro
    //Call Component Macro: LED(0)::LEDOff
    FCD_LED0_LEDOff();

    //Delay
    //Delay: 1 s
    delay_s(1);

    }

    mainendloop:
    goto mainendloop;
    }
    void MX_INTERRUPT_MACRO(void)
    {
    }
     
  2. guitarguy12387

    Active Member

    Apr 10, 2008
    359
    12
    Have you tested it yourself?

    P.S.
     
    Last edited by a moderator: Aug 27, 2011
  3. DumboFixer

    Active Member

    Feb 10, 2009
    219
    34
    Is this actually your code or is it the code produced by the Flowcode program from the flowchart that you (?) wrote ?

    Yes I can see some problems, mainly with code that cannot be executed.
     
  4. ht systems

    Thread Starter Member

    Aug 2, 2011
    71
    1
    im askking about where are the problems?
     
  5. DumboFixer

    Active Member

    Feb 10, 2009
    219
    34
    As was asked, have you tested the code (run it through the Flowcode simulator) ?

    I think a problem lies with the way decision boxes have been used in that you have a constant and not a variable.

    The problem is not with the code but with your flowchart - the code matches, I imagine, the flowchart. Have a closer look at the decision boxes.
     
  6. ht systems

    Thread Starter Member

    Aug 2, 2011
    71
    1
    yes i tested but it didnt work so i thought that the code have a problem but u opened my eyes about the variable , i tested it on flowcode and it worked but in the real its not working .
    i hope that you would tell me why its working on flowcode and not working in the real .
    thank you all so much for helping me :)
     
  7. DumboFixer

    Active Member

    Feb 10, 2009
    219
    34
    If you look at the functions for turning the LED on/off you'll see a piece of code similar to this:
    Code ( (Unknown Language)):
    1. [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]( 1 ) [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//Active high polarity
    2. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]portc = portc | 2;
    3. [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]//Active low polarity
    4. [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]portc = portc & ~2;[/SIZE]


    Can you see the error in this bit of code ?

    hint: what causes the else part to be executed ?


     
  8. ht systems

    Thread Starter Member

    Aug 2, 2011
    71
    1
    So I have to delete the simulation's code or to change it. When I tested in real nothing turned on ( leds ) and I tested the A and it was zero and V was 5 as I put it in the generator.
     
  9. DumboFixer

    Active Member

    Feb 10, 2009
    219
    34
    If you include your flowchart file I may be able to have a look at it and try and point you in the right direction (but you are going to have to do the hard work yourself).
     
  10. ht systems

    Thread Starter Member

    Aug 2, 2011
    71
    1
    here is my flowcode , i hope no problems would happen when you open it
     
  11. DumboFixer

    Active Member

    Feb 10, 2009
    219
    34
    I need the .fcf file - a screen dump doesn't tell me about variables etc.
     
  12. ht systems

    Thread Starter Member

    Aug 2, 2011
    71
    1
    i put all of what you need
     
    • all.zip
      File size:
      36.7 KB
      Views:
      11
  13. DumboFixer

    Active Member

    Feb 10, 2009
    219
    34
    I will have a detailed look at the code when I get a chance. Can you post circuit schematic you ar eusing as it could be a circuit problem.
     
  14. ht systems

    Thread Starter Member

    Aug 2, 2011
    71
    1
    Ok I will wait for your answer and building it on a test board so I don't have a schematic circuit
     
  15. ht systems

    Thread Starter Member

    Aug 2, 2011
    71
    1
    Mr Dumbofixer , im still waiting for your replay sir .
    thank you
     
  16. stahta01

    Member

    Jun 9, 2011
    133
    21
    This is a mistake; create the schematic diagram then build the circuit.

    Tim S.
     
    Last edited: Aug 26, 2011
Loading...