C99 Mode – Whatever that is…

So, I’ve never dabbled in C until now while using it with AVR microcontrollers – and while trying to complie a simple for loop:

  for (uint8_t bit = 0x80; bit; bit >>= 1) {

I got this error:

error: 'for' loop initial declaration used outside C99 mode

and to fix it I would move my decloration of the varabile outside of the loop. This seemed stupid to me so a quick Google search turned up this

Back in the old days, when dinosaurs roamed the earth and programmers used punch cards, you were not allowed to declare variables anywhere except at the very beginning of a block.

Solution was to add -std=c99 to the Makefile. My new AVR Makefile now looks like this..

Posted: June 15th, 2011 | Author: | Filed under: Code, Electronics | Tags: , , , , , , | No Comments »

ATtiny software PWM to drive RGB LED

Based on Atmel’s AVR136: Low-Jitter Multi-Channel Software PWM Application note, here’s a 3 channel software-based pulse width modulator to drive a RGB LED. This is a proof of concept and currently there is some in-efficient color cycling code in there, but the goal is to drive these cheap chips using an I2C (two wire serial) bus. Disco dance floor anyone?…

Posted: May 4th, 2011 | Author: | Filed under: Code, Electronics | Tags: , , , , , , , , | No Comments »