// demonstration of "volatile zeroing bug" // // run on an ATmega168 // // note that this bug occurs with and without optimization // #define F_CPU 1000000UL #include #include #include uint8_t a; volatile uint8_t b; void main ( void ) { usart_init(12); a = 0; usart_putc(a); // sends 0x00, as expected b = 1; usart_putc(b); // sends 0x01, as expected b = 0; usart_putc(b); // sends 0x31, a bug b = 1; b--; usart_putc(b); // sends 0x00, as expected while(1); }