#include <avr/sleep.h>
/*
- * This demonstrate how to use the avr_mcu_section.h file
+ * This demonstrates how to use the avr_mcu_section.h file.
* The macro adds a section to the ELF file with useful
- * information for the simulator
+ * information for the simulator.
*/
#include "avr_mcu_section.h"
AVR_MCU(F_CPU, "atmega88");
{ AVR_MCU_VCD_SYMBOL("TCNT1H"), .what = (void*)&TCNT1H, },
{ AVR_MCU_VCD_SYMBOL("tick"), .mask = (1 << 0), .what = (void*)&PORTB, },
{ AVR_MCU_VCD_SYMBOL("reset_timer"), .mask = (1 << 1), .what = (void*)&PORTB, },
+ { AVR_MCU_VCD_SYMBOL("OC2A"), .mask = (1 << 3), .what = (void*)&PORTB, },
};
volatile uint16_t tcnt;
// timer prescaler to 64
TCCR1B |= (0<<CS12 | 1<<CS11 | 1<<CS10);
- DDRB = 3;
+ DDRB = 0x0B;
//
// now enable a tick counter
// using an asynchronous mode
//
ASSR |= (1 << AS2); // use "external" 32.7k crystal source
- TCCR2A = (1 << WGM21); // use CLK/8 prescale value, clear timer/counter on compareA match
- TCCR2B = (2 << CS20); // prescaler
- OCR2A = 63; // 64 hz
- TIMSK2 |= (1 << OCIE2A);
+ // use CLK/8 prescale value, clear timer/counter on compareA match
+ // toggle OC2A pin too
+ TCCR2A = (1 << WGM21) | (1 << COM2A0);
+ TCCR2B = (2 << CS20); // prescaler
+ OCR2A = 63; // 64 hz
+ TIMSK2 |= (1 << OCIE2A);
sei();
int count = 0;
- while (count++ < 100) {
- // we read TCNT1, which should contain some sort of incrementing value
- tcnt = TCNT1; // read it
- if (tcnt > 10000) {
- TCNT1 = 500; // reset it arbitrarily
- PORTB ^= 2; // mark it in the waveform file
- }
+ while (count++ < 100) {
+ // we read TCNT1, which should contain some sort of incrementing value
+ tcnt = TCNT1; // read it
+ if (tcnt > 10000) {
+ TCNT1 = 500; // reset it arbitrarily
+ PORTB ^= 2; // mark it in the waveform file
+ }
sleep_cpu(); // this will sleep until a new timer2 tick interrupt occurs
}
// sleeping with interrupt off is interpreted by simavr as "exit please"