A large number of inexplicable undefined identifiers appear when keil is compiled

The original code is like this

void main_timer0_init()
{
    TMOD &= 0x01;
    TMOD |= 0x10;
    
    unsigned int initial_value; 
    initial_value= 65536 - (1000 / 90.5);
    TH0 = initial_value >> 8;
    TL0 = initial_value & 0xFF;
    ET0 = 1;
    TR0 = 1; //启动
    EA = 1;
}
// 从第83到95行

I reported such an inexplicable error, even though everything I said was correct.

Check the relevant information to find out:

This error is because in older versions of C language (especially when compiling code for 8051 microcontroller in Keil compiler), variable declaration must be at the beginning of the function or any scope and not after the statement.

Modify the code as follows:

void main_timer0_init()
{
    unsigned int initial_value; 
    TMOD &= 0x01;
    TMOD |= 0x10;
    
    
    initial_value= 65536 - (1000 / 90.5);
    TH0 = initial_value >> 8;
    TL0 = initial_value & 0xFF;
    ET0 = 1;
    TR0 = 1; //启动
    EA = 1;
}

 error disappears

Too bad

Guess you like

Origin blog.csdn.net/Gelercat/article/details/131017611