Hi everyone,
I want to remove the timers setting code from being auto programmed into my microcontroller, because it's not right for my application and to reduce program size (I'm working on ATmega8A and the flash memory is almost full)
how to do that ? how and where to control any pre-written code that happens before the visible setup() code
Be aware that after doing this you can't use delay() millis() micros() analogWrite() tone() ... servos... and many other things.
And I don't think you'll free more than few hundreds bytes.
Much more can be achieved simply by optimising the code.
And if the code gets bigger - just take a more powerful board
I'm not using any of these codes, I think I don't need more powerful chip, this should do the mission.
yes these bytes are very valuable in my case.
Then you should dive into the avr-libs sources. There is no easy way to turn off the timers
PS Think about the time you spend on all of this. I think it's worth it to take atmega328 or 168
I believe that if the program begins with main() (skipping setup() and loop()), init() is not called in the intialization phase.
This compiles to 138 bytes for an Uno, most of which is probably interrupt vectors, etc.
int main() {}
Here is the assembly listing of the .hex load file
Disassembly of section .sec1:
00000000 <.sec1>:
0: 0c 94 34 00 jmp 0x68 ; 0x68
4: 0c 94 3e 00 jmp 0x7c ; 0x7c
8: 0c 94 3e 00 jmp 0x7c ; 0x7c
c: 0c 94 3e 00 jmp 0x7c ; 0x7c
10: 0c 94 3e 00 jmp 0x7c ; 0x7c
14: 0c 94 3e 00 jmp 0x7c ; 0x7c
18: 0c 94 3e 00 jmp 0x7c ; 0x7c
1c: 0c 94 3e 00 jmp 0x7c ; 0x7c
20: 0c 94 3e 00 jmp 0x7c ; 0x7c
24: 0c 94 3e 00 jmp 0x7c ; 0x7c
28: 0c 94 3e 00 jmp 0x7c ; 0x7c
2c: 0c 94 3e 00 jmp 0x7c ; 0x7c
30: 0c 94 3e 00 jmp 0x7c ; 0x7c
34: 0c 94 3e 00 jmp 0x7c ; 0x7c
38: 0c 94 3e 00 jmp 0x7c ; 0x7c
3c: 0c 94 3e 00 jmp 0x7c ; 0x7c
40: 0c 94 3e 00 jmp 0x7c ; 0x7c
44: 0c 94 3e 00 jmp 0x7c ; 0x7c
48: 0c 94 3e 00 jmp 0x7c ; 0x7c
4c: 0c 94 3e 00 jmp 0x7c ; 0x7c
50: 0c 94 3e 00 jmp 0x7c ; 0x7c
54: 0c 94 3e 00 jmp 0x7c ; 0x7c
58: 0c 94 3e 00 jmp 0x7c ; 0x7c
5c: 0c 94 3e 00 jmp 0x7c ; 0x7c
60: 0c 94 3e 00 jmp 0x7c ; 0x7c
64: 0c 94 3e 00 jmp 0x7c ; 0x7c
68: 11 24 eor r1, r1
6a: 1f be out 0x3f, r1 ; 63
6c: cf ef ldi r28, 0xFF ; 255
6e: d8 e0 ldi r29, 0x08 ; 8
70: de bf out 0x3e, r29 ; 62
72: cd bf out 0x3d, r28 ; 61
74: 0e 94 40 00 call 0x80 ; 0x80
78: 0c 94 43 00 jmp 0x86 ; 0x86
7c: 0c 94 00 00 jmp 0 ; 0x0
80: 90 e0 ldi r25, 0x00 ; 0
82: 80 e0 ldi r24, 0x00 ; 0
84: 08 95 ret
86: f8 94 cli
88: ff cf rjmp .-2 ; 0x88
If you get a cheap ISP device like a "USBasp" or "USBtinyISP" you can upload your sketches with the programmer and free up the bootloader space. They cost less than $20 on Amazon or eBay.
that's really good! but I faced a problem.. I have multi .ino files in my project, when I used main() instead of setup() and loop() some files were not seen by each other, how to do with this issue ?
Wild guedd that you got compiler or linker errors. Post them using code tags.
Post your code (all of it or and exsmple that demonstrates the problem) so somebody can advise.
if you using main() instead of setup() loop() - you should use traditional C++ .cpp and .h file model with #includes instead of many .ino files
I don't think the use of 'main()' instead of setup() and loop() will override the way the IDE compiles and links your source files. It should do nothing except preventing the initialization of the Arduino core. Did you put your 'main()' into a .c file instead of a .cpp file? Remember that a .c file can't reference any external .cpp functions without some extra hoops.
As an experiment, I changed the setup() and loop() of a fairly complex sketch from:
void setup()
{
... // setup() contents
}
void loop()
{
... // loop() contents
}
to:
int main()
{
... // setup() contents
while (1)
{
... // loop() contents
}
}
The compiled code was 352 bytes smaller and used 9 bytes less static memory space.
you're right, I forgot to activate innterrupts manually so I thought there was problem accessing the files.
Thank you all <3
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.