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

Assembly Vs C Programming

Hi,

I am using the AT89C5131A MCU. I have an issue related to the HEX code generated by keil.
Actually I was testing the output level(1 or 0) from each 4 ports using a simple HEX code.

IF I write an assembly code and generate its equivalent HEX code ( purpose - as stated above) and burn it to MCU then it works as expected.
But if I write same logic in keil(C program) then use the HEX code generated by it and burn it to MCU then is also works as expected for PORT 1 and PORT 3 only.
There are some fluctuations in PORT 0 and PORT 2 if I use the HEX code generated by Keil(c program) but with the Assembly's HEX code, all ports works fine.
I have checked all settings in Keil, all are correct.

Could anyone please tell me the solution for same.

Thanks in advance!
Mohit

Parents Reply Children
  • Hi Sheldoniq,

    There is nothing in the code that I can't disclose. Its a simple LED blinking code.
    There you go -

    //code
    #include<AT89C5131.h>

    void delay(unsigned int);
    void main(void)
    { P0_0=0; P0_1=0; P0_2=0; P0_3=0; P0_4=0; P0_5=0; P0_6=0; P0_7=0; delay(500); P0_0=1; P0_1=1; P0_2=1; P0_3=1; P0_4=1; P0_5=1; P0_6=1; P0_7=1; delay(500);
    } void delay(unsigned int itime)
    { int i,j; for(i=0;i<itime;i++); for(j=0;j<5000;j++);
    }

    If I burn this code then there are some flaws in Ports P0 and P2 but if I write similar logic in Assembly language then all ports works fine.
    One more thing, the code shown above is for Port P0, if I write same thing for any other port even then this problem persists.
    If you need Assembly code or any other info please let me know.

    Thanks!