| QUOTE |
| How to Program the AVR with avr-gcc and AVRLib Physical Interaction Design for Music - CCRMA 2004 - Anatomy of a C program for AVR - C syntax - Comments - Variables - Arrays - Conditionals - Looping - while Loops - for Loops - Functions - Scope - AVR-Specific Commands - AVR Registers - The DDRx Register - The PORTx Register - The PINx Register - Other Registers - AVRLib - rprintf - Program Memory Directives - Makefiles Anatomy of a C program for AVR CCRMA Physical Interaction Design 2004 |
| QUOTE ("Cliff Lawson @ May 2006") |
Just a note for anyone reading those tutorials that they use deprecated macros such as outp() and cbi() etc. To make the programs work in the modern version of avr-gcc/avr-libc you will either need to: 1) # include <compat/deprecated.h> or 2) remove the deprecated macros so that: outp(port, val) simply becomes port = val x = inp(port) simply becomes x = port sbi(port, bit) becomes port |= (1<<bit) cbi(port, bit) becomes port &= ~(1<<bit) |
| CODE |
| //*************************************** //*************************************** // AVRLIB-DEMO // For avrlib and avrmini development board. // // File: button.c // Author: Michael Gurevich // Date: Sept. 22, 2002 // Modified: June 9, 2004 |
| CODE |
| #include <avr/io.h> #include <avr/signal.h> #include "global.h" #include "timer.h" |
| CODE |
| #define DEBOUNCE_THRESHOLD 1000 |
| CODE |
int main(void) { // set led pins (low 4 bits) as outputs, // set button pins (high 4 bits) as inputs outb(DDRD, 0x0F); // Turn off LEDs by setting the low 4 bits outb(PORTD, 0x0F); // loop forever while(1) { // call the checkButton function checkButton(); } return 0; } |
| CODE |
| static u16 buttonDownCounter; if (! bit_is_set(PIND,4)) { if (buttonDownCounter++ == DEBOUNCE_THRESHOLD) { cbi(PORTD,0); } } else { //button is not pressed buttonDownCounter = 0; sbi(PORTD,0); } } |