I compile my project in arduino IDE & then use "Export Compiled Binary" to get the hex file without bootloader. Then I program the chips using USBASP programmer so that I can set the fuse & lock bits manually.
Now to get rid of the crystal & reduce the power consumption I want to use the internal 8MHz oscillator with CKDIV8 bit set. So that the microcontroller will operate on 1MHz.
What changes are required in the code so that all the delays will be adjusted correctly. I am also using some external libraries such as LiquidCrystal, EEPROM etc. I have read about F_CPU, but I have not understood its use. Please explain..
F_CPU is clock frequency. In your case, it will be 1MHz. The program has no possibility to detect the frequency, so it must be hard coded. The program should have be compiled for correct F_CPU value otherwise things which require timing will not work properly or will not work at all.
F_CPU is macro definition and in IDE it is defined via boards.txt file. There are also definitions for fuses. You have to define your board or edit an existing one. The 1MHz is OK from the APP view and it is usable.
F_CPU is used globally so the best place seems to be the boards.txt, then you can use it anywhere in code.
Both.
OK
It is just constant value used in equation or during conditional compilation. For an example, it is used for millisecond calculation like: How many clock tics are in one millisecond? The answer depends on F_CPU value.
That means if I change following line from boards.txt
uno.build.f_cpu=16000000L
to
uno.build.f_cpu=1000000L
then all the code which is using f_cpu constant will get the new value & timings will still be perfect. delay(1000) will give 1 sec delay??? But if any library that I have included is not using the f_cpu constant it will not behave correctly??
Yes, exactly it means that the delays etc. will perfect fit. It is matter of the bottom level of code/library which is part of an environment. User doesn't care. Any library that is not using F_CPU probably not need this information. However, F_CPU is used on global level during compilation for all files.
Imagine the situation with the use of already compiled object for different F_CPU with the current project. It would be a problem in this case.
Don't forget to modify the fuses together with the F_CPU for the board!