Menu

code translation

Aaron
2017-01-21
2017-01-21
  • Aaron

    Aaron - 2017-01-21

    pls can anyone help me translate this code to gcb, its in c, most especially the interrupt part, thanks in advance...
    //Target PIC: PIC16F877A
    //Program for phase angle control
    //---------------------------------------------------------------------------------------------------------
    unsigned char FlagReg;
    sbit ZC at FlagReg.B0;

    void interrupt(){
    if (INTCON.INTF){ //INTF flag raised, so external interrupt occured
    ZC = 1;
    INTCON.INTF = 0;
    }
    }

    void main() {
    PORTB = 0;
    TRISB = 0x01; //RB0 input for interrupt
    PORTA = 0;
    ADCON1 = 7; //Disable ADC
    TRISA = 0xFF; //Make all PORTA inputs
    PORTD = 0;
    TRISD = 0; //PORTD all output
    OPTION_REG.INTEDG = 0; //interrupt on falling edge
    INTCON.INTF = 0; //clear interrupt flag
    INTCON.INTE = 1; //enable external interrupt
    INTCON.GIE = 1; //enable global interrupt

     while (1){
           if (ZC){ //zero crossing occurred
              delay_ms(2);
              PORTD.B0 = 1; //Send a pulse
              delay_us(250);
              PORTD.B0 = 0;
              ZC = 0;
           }
     }
    

    }

     
  • JANIS

    JANIS - 2017-01-21

    Hallo!
    You can view my program code example, typing in the search box: Zero cross and firing angle ... My code works well

     
  • Anobium

    Anobium - 2017-01-21

    @Aaron. The JANIS code is very good. You should look to use his code.

    I am posting this so that we do not shy away from the ask - this shows how simple Great Cow BASIC when migrating. This may help and it shows how Great Cow BASIC can simplify the programming experience. I have laid the code out in the same manner so you can compare and contrast.

    But, the code of JANIS is a richer approach and you should review.

    Anobium

    ; Target PIC: PIC16F877A
    ;Program for phase angle control
    '----------------------------------------------------------------------
    
      #chip 16F877A 
    
      #option Explicit
    
      dim ZC as bit
    
      on Interrupt ExtInt0 call ISR    'the definition setups all the interrupt flags for you.
    
      sub ISR    
    
          if INTF=1 then
              ZC=1
              INTF = 0
          end if
    
      end sub
    
      portb = 0
      dir portb.0 in  'RB0 input for interrupt
      porta = 0
      dir porta in    'Make all PORTA inputs
      INTEDG = 0      'interrupt on falling edge
      dir portd out   'PORTD all output
    
    
      do forever
             if  ZC = 1 then 'zero crossing occurred
                wait 2 ms
                PORTD.0 = 1 'Send a pulse, this can be simplified to the Great Cow BASIC pulseout command
                wait 250 us
                PORTD.0 = 0
                ZC = 0
              end if
    
      loop
    

    Edited: I forgot to clear intf..

     

    Last edit: Anobium 2017-01-21
  • Aaron

    Aaron - 2017-01-21

    thanks guys, GCB all the way

     

Log in to post a comment.