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

Bug report.

Long Integer Multiple Error.
Sample Program: Target Setting: MCU is C8051F120F, Use On-chip Arithmetic Accelerator.

Source:

#include <C8051F120.H>
#include <stdio.h>

unsigned long Freq;

void DetectFreq()
{
        unsigned long N;
        unsigned char M;
    SFRPAGE   = CONFIG_PAGE;
        M= PLL0MUL;
        switch (CLKSEL&0x03) {
                case 00:        //Internal XTAL
                case 03:
                                        Freq=25690112;//24.5L*1024L*1024L
                                        switch(OSCICN&0x03){
                                                case 0x00: Freq/=8; break;
                                                case 0x01: Freq/=4; break;
                                                case 0x02: Freq/=2; break;
                                        }
                                        break;

                case 01:        // External XTAL
                                        Freq=25L*1024L*1024L;
                                        switch (OSCXCN&0x70) {
                                                case 0x03:
                                                case 0x05:
                                                case 0x07: Freq=Freq/2; break;
                                        }
                                        break;
                case 02:        //PLL
                                        if (PLL0CN&0x04) { // External XTAL
                                                Freq=26214400L;  //25L*1024L*1024L
                                                N=Freq;
                                                Freq*=PLL0MUL;
                                                Freq/=PLL0DIV;
                                                switch (OSCXCN&0x70) {
                                                        case 0x03:
                                                        case 0x05:
                                                        case 0x07: Freq=Freq/2; break;
                                                }

                                        }
                                        else{
                                                //Freq=25690112L;
                                                Freq=24500000L;//25690112L;
                                                N=Freq;
                                                Freq*=PLL0MUL;
                                                //FreqMul(PLL0MUL);
                                                Freq/=PLL0DIV;
                                                switch(OSCICN&0x03){
                                                        case 0x00: Freq/=8; break;
                                                        case 0x01: Freq/=4; break;
                                                        case 0x02: Freq/=2; break;
                                                }
                                        }
                                        break;
        }
        SFRPAGE   = LEGACY_PAGE;
        printf("%lu * %u = ", N, M);
        printf("%lu\n", Freq);

        Freq=25690112L;
        printf("%lu * %u = ", Freq, 4);
        Freq*=4;
        printf("%lu\n", Freq);

}

void InitSerial()
{
        SFRPAGE =LEGACY_PAGE;
    SCON0  = 0x50;                      /* SCON: mode 1, 8-bit UART, enable rcvr      */
    TMOD |= 0x20;               /* TMOD: timer 1, mode 2, 8-bit reload        */
    TH1   = 221;                /* TH1:  reload value for 1200 baud @ 16MHz   */
    TR1   = 1;                  /* TR1:  timer 1 run                          */
    TI0    = 1;                  /* TI:   set TI to send first char of UART    */
}

// Peripheral specific initialization functions,
// Called from the Init_Device() function
void Reset_Sources_Init()
{
    WDTCN     = 0xDE;
    WDTCN     = 0xAD;
}

void EMI_Init()
{
    SFRPAGE   = EMI0_PAGE;
    EMI0CF    = 0x1F;
    //EMI0TC    = 0x4F;
           EMI0TC    = 0xCF;

}

void Port_IO_Init()
{
    SFRPAGE   = CONFIG_PAGE;
    P4MDOUT   = 0xFF;
    P5MDOUT   = 0xFF;
    P6MDOUT   = 0xFF;
    P7MDOUT   = 0xFF;
    XBR0      = 0x07;
    XBR1      = 0x94;
    XBR2      = 0x40;
}

void Oscillator_Init()
{
    data int i = 0;
    SFRPAGE   = CONFIG_PAGE;
    CCH0CN    &= ~0x20;
    SFRPAGE   = LEGACY_PAGE;
    FLSCL     = 0xB0;
    SFRPAGE   = CONFIG_PAGE;
    CCH0CN    |= 0x20;
    PLL0CN    |= 0x01;
    PLL0DIV   = 0x01;
    PLL0FLT   = 0x01;
    PLL0MUL   = 0x04;
    for (i = 0; i < 15; i++);  // Wait 5us for initialization
    PLL0CN    |= 0x02;
    //while ((PLL0CN & 0x10) == 0);
    CLKSEL    = 0x02;
    OSCICN    = 0x83;
}

// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
    Reset_Sources_Init();
    EMI_Init();
    Port_IO_Init();
    Oscillator_Init();
}

void main()
{
        Init_Device();
        InitSerial();
    printf ("Hello World\n");   /* Print "Hello World" */
        DetectFreq();
        printf("%lu", Freq);
        while(1);
}


======================end of source=========================
Run Result:

Hello World
24500000 * 1024 = 4294926936
25690112 * 1024 = 1568
1568

conclusion:

1.There are mistake of Long Integer Mutiple where open the on-chip arithmetic accelerator.
2.printf also make a mistake of Printing a one-byte-integer.

0