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

initialize variable with binary value?

hi all
it may seem very easy but i can't initialize
my code constants with binary value in c51
ver 3.20 franklin DOS version i want to:
code char bin_code[3]={
0b1100110011,0b1111110011,0b1100111011};

but compiler doasn't accept.
any one can help me?

Parents Reply Children
  • Looks like hitech c compiler accepts binary as well as decimal, octal, hex etc... I haven't tried it in Keil C but here is a code snippet from a working program using PIC microcontroller:

    /******************************************************************************
    * Name        : initialize                                                    *
    * Description : This function initializes the PIC to the following :          *
    *               1. PORTA as output                                            *
    *               2. PORTB as Input                                             *
    *               3. Clears interrupt flags and sets timer0 to int every 1msec  *
    *               4. Stops the motor.                                           *
    *               5. sets the RB0 Interrupt to falling edge.                    *
    *               6. sets the timeOut variable to set speed required.           *
    *               7. Clears the 1 msec flag                                     *
    *               8. Enables both RB0 and Timer interrupts.                     *
    * Input        : None                                                         *
    * Outout       : None                                                         *
    ******************************************************************************/
    void initialize()
    {
        TRISA          = 0;           // SET PORTA AS OUTPUT
        PORTA          = 0;           // STOP MOTOR
        flag1Msec      = 0;           // initialise 1 msec flag
        engOkFlag      = 1;           // initialise engage ok flag
        overSpdReg     = 0;           // set speed trigger to 30km/hr
        OPTION         = 0b00010111;  // Prescaler /256 inc timer every 128usec
        TMR0           = 248;         // 128 usec x 8 = 1.024 msec
        INTCON         = 0B00110000;  // ENABLE INTERRUPTS AND CLR FLAGS
        clockA         = 0;
        clockB         = 0;
        debouncedState = 1;
        oldSwitchState = 0;
        startTiming    = 0;
        GIE            = 1;
        overSpdCntr    = 0;           // initialise speed counter
        underSpdCntr   = 0;
        systemState    = 0;           // initialize state to state0
    }