5 ms·
I think part of the reason for arduino's success among amateurs is better variable and function names. I have quite a lot of (mostly higher-level) programming
by nfriedly 3y ago
I think part of the reason for arduino's success among amateurs is better variable and function names. I have quite a lot of (mostly higher-level) programming experience, but I just have to take your word for it that that's a blink program. The 500 millisecond delay and the endless loop are straightforward, but I have no clue what DDRB or BV(0) refer to and I'm only vaguely aware that PORTB probably refers to GPIO pins.
- buster3000 3y agoDDR* is the register for setting up what the pins on PORT* should be doing. BV is just a bit-twiddling macro.
- Arch-TK 3y agoYeah avr-gcc is pretty thin and it would be nice if the memory mapped registers had clearer names. That being said, there's a balance between being close enough to the hardware to get predictable timings and the necessary flexibility and being abstract enough that the code is easy to understand by people without domain specific knowledge. You can get closer to the latter by providing increasingly thick layers of abstraction. The problem is that making the abstractions perfect (and arduino's are not, probably for this reason) can take a LOT of code. These Atmel chips are pretty tiny and memory constrained compared to what you might be used to. And that is not even to mention the performance overhead these abstractions can incur. Sometimes you also run into fundamental impedance mismatch issues. Situations where you can't present a high level interface to something without having to make unacceptable compromises. All in all, while arduino is convenient for a beginner to get started, the second the beginner starts to get serious about hardware development is the second the issues begin appearing. You can get quite far with arduino but if you want to use a device like the ATTiny85 to its full potential, you're going to struggle.
- nhatcher 3y agoArduino 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); } }