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
What then send the code you wrote? It's hard to advise when not disclose how your program looks
I have checked all settings in Keil, all are correct.
No, they're not. You've mis-configured one extremely crucial setting. And your hardware is slightly flawed, too.
To find out what's wrong, I invite you to go back to the chip's data sheet and look up what functions P0 and P2 might have, but P1 and P3 don't, and how those might affect your observed behaviour.
Hi Broeker,
Thanks for reply!
Could you please tell me exactly what I need to do as I am not getting your point? In case if you need source code or any other info please let me know.
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!
as I am not getting your point?
Well, I'll be blunt then. The reason for that behaviour is explained in your microcontroller's data sheet. So go and read that. I won't deprive you of the learning experience of finding out the details for yourself.
I understand. you don't know either.
Actually I suspect he does. I've only scanned the document and I think I can see a number of potential pitfalls, and why Port 0 and Port 2 could present some problems.
If you post source code, use the PRE tags, It'll be a lot easier to read. Consider also if exiting main() is a good plan.
ahh, I now understand P0 and P2. you khew about them all along. please accept my profound apologies for being such an ass.