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

If statement do not work (?) Newbie Question

Dear friends,

I am writing a small code for an 89LPC935 and KEIL uVision3 + MCB900 board, and all goes good untill i try to enter the If .. else statement :((

Take a look and give me some tip if available >>>

If (Keyb_input == 0x0B); // Keyboard "Play" press
    {
        Debug++;         // Increment Debug register
        P2 = Debug;      // Debug keypad press to Port2
                                }

Notes:
(*) The Keyb_input is declared at the begining of the program as unsigned char data Keyb_input

(*) Error messages are >> missing function prototype requires ANSI-style prototype

Parents Reply Children
  • Dear friend , i am sorry to bother you again but something is wrong t my code even if i discard the semicolon from the If statement :(((

    Here is the total C code (Thank god it is small :( )

    
    // Author: Timothy Kondos
    // Date: 24.06.2008
    //
    
    #include <REG935.H>
    
    sbit Status_led = P0^0;                                                 // Initialize P0.0 as the status led
    unsigned char data overflow_count;                      // Define system interrupt as a variable
    unsigned char data Keyb_input    ;                      // Keyboard input register(8bit)
    unsigned int  Counter_us         ;                      // Microsecond counter(16bit)-ISR usage
    unsigned char data Debug         ;                      // Special user register (8bit)-Debug usage
    
    Delay_20ms(void)
            {
                    Counter_us = 0;                                                 // Reset Counter_us 16bit register
                            while (Counter_us <= 400)                    // Wait until 20ms elapsed
                                    {
                                    }
            }
    
    void timer0_ISR (void) interrupt 1
            {
                    Status_led = 1;                                                 // Open Status led
                    Counter_us++;                                                   // Increment microsecond counter(16bit)
                    Keyb_input = P0;                                // Read keyboard
                    Keyb_input = Keyb_input & 0xF0;                     // Isolate upper nibble/Ignore lower nibble
                    while((ADCON1 & 0x08) == 0);                        // Wait for end of conversion
                            {
                            }
                    ADCON1 &= 0xF7;                                                     // Clear EOC flag
                    Status_led = 0;                                                 // Close status led
            }
    
    main (void)
    {
    
    //Port0 configuration
      P0M1 = 0xF0;                                                          //Initialise P0 as I/O
      P0M2 = 0x01;
    //Port2 configuration
      P2M1 = 0x00;                                                          //Initialise P2 as I/O(All Quasi Bidirectional)
      P2M2 = 0x00;
    
    //Timer0 module configuration
      TMOD = 0x02;                                                          // Initialise Timer module in Mode2
      TAMOD= 0x00;                                                          // Initialise Timer module in Mode2
      TL0  = 0x48;                                                          // Initialise TL0(temp reload) value
      TH0  = 0x48;                                                          // Initialise TH0(auto reload) value
      IEN0 = 0x82;                                                          // Enable interrupts on timer0/Enable global interrupts
      TCON = 0x10;                                                          // Start timer0
    
    //Configure the ADC     module 1 configuration
      ADINS    = 0x40;                                              // Select AD12 as ADC input (P0.3)
      ADCON1   = 0x24;                                                              // AD1 enabled/Single Step/Trigered on timer overflow
      ADMODA   = 0x20;                                                              // Single step on channel 1 of A/D
      ADMODB   = 0x60;                                                              // ADC clock is set to 3.3MHZ(fCLK/8)
      Debug    = 0;                                                                 // Reset debug register
    
    while (1)                                                                               // Loop forever ("Super loop")
                    {
                            while (Keyb_input == 0xF0)                  // Reloop and read keyboard again (No keyboard suspected activity)
                                    {
                                      Delay_20ms();                             // Call the Delay function
                                    }
    
                              If (Keyb_input == 0x0B)           // Keyboard "Play" press
                                    {
                                      Debug++;                                      // Increment Debug register
                                      P2 = Debug;                       // Debug keypad press to Port2
                                    }
    
    
                    }
    }
    
    

    Same error message as before .. If statement denies to be compiled.

    Just compile it and the error comes :(

    What could be wrong (?)

    Thank very much for your time
    Timothy

  • Dear coding friends,

    I didnt thought "C" programming was so strict grammar sensitive. Anyway, it worked , just replacing the capital "I" to if statement. All ok now ,

    Thanks again all:))
    Special thanks to Ulf Saß

  • My dearest friend,

    You should also look at the code relating to 'counter_us'.

    1 - It should be volatile, since it is being sampled repeatedly by your Delay_20ms function and is being updated by an ISR. The optimizer (probably) will do things that I suspect you currently do not consider.

    2 - In the same vein, the variable is a 16 bit integer; i.e., stored in two bytes (on an 8051) so while the delay loop is half way through accessing it, the ISR may come in and changing the value.

    You might get your code to compile, but without considering these points, you might find the operation isn't always as you intend; i.e., buggy.

    Kindest regards,

    Happy Happening.

  • I didnt thought "C" programming was so strict grammar sensitive.

    You need to get a good book that provides an introduction to C. The fact that C is case-sensitive is usually mentioned near the very beginning of such books.

    IF, If, iF and if are four completely different things to a C compiler.