Hey, I've been programming higher level laguages writing windows apps in c++/c# for years now, but increasingly I am being put to work at a lower level with 8051 micro-controllers. Having a very minimal background in electronics I have found a lot of things difficult in understanding a data sheet.
In particular I am having trouble understanding when I should set a GPIO port to open-drain or push pull, or when to use weak pullups & high impedance.
Is there any simple explanation you guys can offer for this, or better yet is there a good resource for learning enough about the hardware (in particular this open-drain /push pull stuff), well enough in order to program it?
Thanks for your time!
The most important things here: - The 8051 has a lousy stack, so the Keil compiler will try to convert auto variables to global variables.
- The automatic conversion of auto variables to global variables requires that you do not write recursive code.
- Using function pointers will destroy the compiler/linker ability to build call trees to figure out which functions that may call other functions for the above optimization. So try to avoid function pointers.
- The processor is 8-bit, so don't create int variables if an 8-bit variable is enough.
- The strong point of the processor is one-bit variables, so try to use one-bit variables for your boolean conditions.
- The processor has limited RAM, so make sure that constants are stored in the code space, i.e. in the flash.
Some level of understanding of electronics is required when working with 8051-based MCU's. I would recommend the book 'The Art of Electronics.' Very easy to read, excellent for self-teaching. It might seem like an overkill to you, but you don't have to read all of it - it could be used as a reference. There should be some info on the net, like application notes. Here is one of them: www.maxim-ic.com/.../
Probably unrelated to the question, but as has been pointed out many times in this forum, the 8051 architecture is not good at supporting the C programming language. It has severe limitations. You need to keep this in mind, especially having extensive background in PC programming: a PC has virtually unlimited resources compared to a 8051 CPU.
Regards, - mike