Visst kan jag det. En del kommentarer är fel, jag har hackat om demo.c utan att ändra i kommentarer osv.
Detta är vad som händer: main anropar second. second loopar tusen gånger, varannan gån anropas odd, varannan even. Både odd och even inkrementerar apa med ett. Det är alltså ett rent nonsensprogram för att testa lite.
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <
joerg@FreeBSD.ORG> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Joerg Wunsch
* ----------------------------------------------------------------------------
*
* Simple AVR demonstration. Controls a LED that can be directly
* connected from OC1/OC1A to GND. The brightness of the LED is
* controlled with the PWM. After each period of the PWM, the PWM
* value is either incremented or decremented, that's all.
*
* $Id: demo.c,v 1.4 2004/07/21 21:03:07 joerg_wunsch Exp $
*/
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#if defined(__AVR_AT90S2313__)
# define OC1 PB3
# define OCR OCR1
# define DDROC DDRB
#elif defined(__AVR_AT90S2333__) || defined(__AVR_AT90S4433__)
# define OC1 PB1
# define DDROC DDRB
# define OCR OCR1
#elif defined(__AVR_AT90S4414__) || defined(__AVR_AT90S8515__) || \
defined(__AVR_AT90S4434__) || defined(__AVR_AT90S8535__) || \
defined(__AVR_ATmega163__)
# define OC1 PD5
# define DDROC DDRD
# define OCR OCR1A
#elif defined(__AVR_ATmega8__)
# define OC1 PB1
# define DDROC DDRB
# define OCR OCR1A
# define PWM10 WGM10
# define PWM11 WGM11
#elif defined(__AVR_ATmega32__)
# define OC1 PD5
# define DDROC DDRD
# define OCR OCR1A
# define PWM10 WGM10
# define PWM11 WGM11
#elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
# define OC1 PB5
# define DDROC DDRB
# define OCR OCR1A
# define PWM10 WGM10
# define PWM11 WGM11
#else
# error "Don't know what kind of MCU you are compiling for"
#endif
#if defined(COM11)
# define XCOM11 COM11
#elif defined(COM1A1)
# define XCOM11 COM1A1
#else
# error "need either COM1A1 or COM11"
#endif
volatile int16_t apa;
void even()
{
apa++;
}
void odd()
{
apa++;
}
void
second (void)
{
int i = 100;
for(i = 0; i < 1000; i++){
if(0 == i % 2)
even();
else
odd();
}
/* loop forever, the interrupts are doing the rest */
for (;;) /* Note [6] */
;
return (0);
}
int
main (void)
{
second();
}