4 ms·
Arduino has done an amazing job at bringing those chips to the open public. The job has been done in many directions, software, hardware, education, marketing,
by nhatcher 3y ago
Arduino has done an amazing job at bringing those chips to the open public. The job has been done in many directions, software, hardware, education, marketing, etc... Arduino programs are definitely easier to read but they do add an overhead. If you run the above program without the delay and put an oscilloscope at the ends of the LED you will actually see the clock frequency of the chip! If you do that with Arduino code you will, at least, see only 10x the clock frequency. I find it amazing that we can see the "software bloat" in the oscilloscope.
While it is true that the digitalWrite Arduino functions are easier to read I think with a bit of effort and having the datasheet by your side (you are programming hardware!) you can get the hang of it pretty quickly. Without the scary bit operators the code above is not that difficult:
#include <avr/io.h>
#include <util/delay.h>
int main() {
DDRB = 0b00000001; // DB0 is an output
setup();
for(;;) {
PORTB = 0b00000001; // on
_delay_ms(500);
PORTB = 0b00000000; // off
_delay_ms(500);
}
}