Software I2C to access EEPROM 24C16
Description:
This example was written after the
assembler example. So you can easy
compare both in respect of:
-
source code:
Since pure hardware access (less calculations) needed, the source is equal
readable
-
adaption:
Both examples are written to access IDATA space. Changing e.g. to XDATA can
easy be done in C with changing only 1 definition (eechar), but more difficult
in assembler.
The needed delay for I2C timing must be calculated separate for different
crystals and then I2CWAIT must adapted in the C source.
Assembler macros are many more powerful so the calculation was made automatically
during assembling. The Keil assembler can only calculate values up to 65535,
so the cycle count for 1ms, not the full crystal value can be used.
-
code space:
In this case C need about 200% of assembler. Rarely it can be less, but many
times you need more. So if you want to translate a 4kB assembler program
to C use minimal a 8kB (better a 16kB) device.
-
execution speed:
Since additional delays must be inserted, there is no big decreasing seen
on C (the 5ms write cycle complete waiting determine the speed).
Source Files: