This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

i would like to know the c++ code to generate increasing pwm

i would like to know the c++ code to generate 1 increasing pwm on one pin of 89c2051 when signal comes at 3.4 of 89c2051 and decreasing pwm on the same pin of 89c2051 when signal comes at 3.5 [in of 89c2051.

Parents
  • You're in luck, they're both static functions in the IBSHY C++ compiler for the 8051.

    Here is the code you would use:

    void main(void)
    {
      PWM::Init();
    
      for (;;)
      {
        if (PORTS::IsPortPinTrue(3,4))
        {
          PWM:Increase();
        }
    
        if (PORTS::IsPortPinTrue(3,5))
        {
          PWM:Decrease();
        }
      }
    }
    

    But as you're no doubt aware, the IBSHY C++ compiler has not yet been released, so you'll have to use the beta version. Just Google for it and you may find it.

Reply
  • You're in luck, they're both static functions in the IBSHY C++ compiler for the 8051.

    Here is the code you would use:

    void main(void)
    {
      PWM::Init();
    
      for (;;)
      {
        if (PORTS::IsPortPinTrue(3,4))
        {
          PWM:Increase();
        }
    
        if (PORTS::IsPortPinTrue(3,5))
        {
          PWM:Decrease();
        }
      }
    }
    

    But as you're no doubt aware, the IBSHY C++ compiler has not yet been released, so you'll have to use the beta version. Just Google for it and you may find it.

Children
  • And if porting the code to another compiler, just look out for the number of colon, since all compilers aren't as forgiving.

    By the way - the IBSHY C++ compiler has an excellent runtime library.

  • "... just look out for the number of colon ..."

    Yes, I noticed that just after I did the post.

    No problem, I've already updated the compiler to allow any number of them and act as the programmer intended.

    It now has the same action for the problematic "=" and "==". So long as you enable the -AsProgrammerIntends switch it will do what you want.

    I'm also considering the -ChangeAllMagicNumbers switch to enable translation of nasty magic numbers to readable constants.

  • "I'm also considering the -ChangeAllMagicNumbers switch to enable translation of nasty magic numbers to readable constants."

    What we always have wanted.

    enum {
        ONE = 1,
        TWELVE = 12
    };
    
    enum {
        UNSIGNED_ONE_SHIFTED_LEFT_12_STEPS = (unsigned)ONE << TWELVE
    };
    
    enum {
        MAGIC_BIT_TO_TURN_ON_POWER_TO_ADC0 = UNSIGNED_ONE_SHIFTED_LEFT_12_STEPS
    };
    
    A |= MAGIC_BIT_TO_TURN_ON_POWER_TO_ADC0;