Menu

HELP! Trouble translating MCU logic from C (I used MPLAB MCC) to GCB

Phil D
2020-08-17
2020-08-17
  • Phil D

    Phil D - 2020-08-17

    Hi, I am having trouble trying to 'translate' C code to GCBs' equivalent. Below is the specific C code, what would be the best way to write this in GSB? The MCU is the PIC16F1823 using ADC 'AN1'.

    Below is the main body code, I have left off the header and footer code as it is the below logic i am having trouble converting to GCB.

    Is GCB capable of this level of logic (I assume it is, but it is beyond my GCB knowledge :(

    Thanks in advance guys for any help steering me in the right direction with GCB!

    if(st_in>416)      //Check ST signal 
    {
        if(st_in<850) //check if ST signal is t light
        {
            t_out=1;     //turn on t light
            b_out=0;    
        }
    if(t_out)
    {
        v_t=1;
    }
    else
    {
        v_t=0;
    }
        if((st_in>700) && (v_t))  //check if ST signal is b and t light is on
        {
            b_out=1;    //turn on b light
            t_out=1;     
        }
        if ((st_in>700) && (!v_t))  //check if ST signal is b and t light is off
        {
            b_out=1;    //turn on b light
        }
    }
    else        //if no ST signal 
    {
        b_out=0;    //B light off
        t_out=t_in;  
        v_t=0;     //T light on flag reset
    }
    
     
  • Anobium

    Anobium - 2020-08-17

    Not to hard to do this. Rules

    • If statements need to have THEN and END IF.
    • If statements need to have the { } removed
    • Logic statements like && become &
    • Logic conditions like if(t_out) need validation.

    And, the following needs validation
    st_in type. I would assume WORD. From an ADCRead?
    t_out and b_out. Could be bits, byte or a register.bit
    v_t Could be bit, byte or a register.bit
    !v_t and v_t Need to be sure what these meant... and now mean. Are they v_t = 0
    and v_t = 1 respectively?

    #chip 16f690
    
    if (st_in>416) then     'Check ST signal
    
        if (st_in<850) then 'check if ST signal is t light
            t_out=1     'turn on t light
            b_out=0
        end if
    
        if(t_out = 1) then
            v_t=1
        else
            v_t=0
        end if
    
        if( (st_in>700) & (v_t=1) ) then 'check if ST signal is b and t light is on
    
            b_out=1    //turn on b light
            t_out=1
        end if
        if ( (st_in>700) & (!v_t=0) ) then 'check if ST signal is b and t light is off
    
            b_out=1    //turn on b light
        end if
    
    else  'if no ST signal
    
        b_out=0    //B light off
        t_out=t_in
        v_t=0     //T light on flag reset
    end if
    

    EDITED: Changed to code that compiles
    EDIT.... This code should be very short. The code code be relationised to a lot less code!!

     

    Last edit: Anobium 2020-08-17

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.