/Modules/AVR/Text_Examples/SW/TIMER_DEMO1/BIN/timer_demo1_atmega88.hex
0,0 → 1,15
:1000000019C028C027C026C025C024C023C022C0D4
:1000100021C020C01FC01FC01DC01CC01BC01AC0F3
:1000200019C018C017C016C015C014C013C012C024
:1000300011C010C011241FBECFEFD4E0DEBFCDBF72
:1000400011E0A0E0B1E001C01D92A230B107E1F7DC
:100050002CD03FC0D5CF1F920F920FB60F92112414
:100060008F939F9388B190E1892788B9809100018F
:1000700090910101CB9754F480910001909101017E
:100080000196909301018093000108C01092010134
:100090001092000188B190E2892788B99F918F91D1
:1000A0000F900FBE0F901F9018953C9A3D9A83E8D1
:1000B0009EE19093890080938800809181008C60FC
:1000C0008093810080916F00826080936F007894AC
:0600D000FFCFF894FFCF02
:00000001FF
/Modules/AVR/Text_Examples/SW/TIMER_DEMO1/Makefile
0,0 → 1,36
PROGRAM = timer_demo1
 
MCU = atmega88
 
CC = avr-gcc
OBJCOPY = avr-objcopy
CFLAGS += -Wall -g -Os -mmcu=$(MCU)
LDFLAGS +=
 
OBJS = $(PROGRAM).o
 
all: $(PROGRAM)_$(MCU).hex
 
$(PROGRAM)_$(MCU).elf: $(PROGRAM).o
@printf " LD $(subst $(shell pwd)/,,$(@))\n"
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
 
$(PROGRAM)_$(MCU).hex: $(PROGRAM)_$(MCU).elf
@printf " OBJCOPY $(subst $(shell pwd)/,,$(@))\n"
$(OBJCOPY) -O ihex $< $@
 
%.o: %.c
@printf " CC $(subst $(shell pwd)/,,$(@))\n"
$(CC) $(CFLAGS) -o $@ -c $<
 
flash: $(PROGRAM)_$(MCU).hex
@printf " FLASH $(PROGRAM)_$(MCU).hex\n"
avrdude -c stk500v1 -P usb -p m88 -U flash:w:$(PROGRAM)_$(MCU).hex
 
clean:
@printf " CLEAN $(subst $(shell pwd)/,,$(OBJS))\n"
rm -f *.o
@printf " CLEAN $(PROGRAM).elf\n"
rm -f *.elf
@printf " CLEAN $(PROGRAM).hex\n"
rm -f *.hex
/Modules/AVR/Text_Examples/SW/TIMER_DEMO1/timer_demo1.c
0,0 → 1,103
// timer_demo1.c
// -------------
//
// Example file for ATmega88 (and similar AVR chips) demonstrating how to use
// timer interrupt just to blink by LED.
//
// The program uses TIMER1 to generate interrupts and the interrupt routine
// toogles the LED state. Connect LED to ground with apropriate serial resistor
// (value about 330 OHM).
//
// (c) miho 2014 http://www.mlab.cz
//
// History
// 2014 01 29 - First demo
 
 
// System Configuration
#define F_CPU 4000000 // Do not forget to set FUSEs to external XTAL osc with DIV/8 off and connect xtal
 
 
// LED Ports Configuration
#define LED_S_PORT C
#define LED_S_PIN 4
#define LED_M_PORT C
#define LED_M_PIN 5
 
 
// -------------- DO NOT EDIT BELOW THIS LINE --------------
 
 
// Library Headers
#include <avr/interrupt.h>
 
 
// Comaptibility ATmega8 / ATmega88
#ifndef TIMSK
#define TIMSK TIMSK1
#endif
 
 
// Macro for Port (enables to easily define IO signals)
#define GLUE(A,B) A##B
#define DDR(PORT_LETTER) GLUE(DDR, PORT_LETTER) // Makes DDRC from DDR(C)
#define PORT(PORT_LETTER) GLUE(PORT,PORT_LETTER) // Makes PORTC from PORT(C)
#define PIN(PORT_LETTER) GLUE(PIN, PORT_LETTER) // Makes PINC from PIN(C)
 
 
// Global Variable
volatile int Seconds;
 
// Interrupt Routine for TIMER1 Output Compare A
ISR(TIMER1_COMPA_vect)
{
// LED on/off
PORT(LED_S_PORT) ^= (1<<LED_S_PIN);
if (Seconds<59)
{
Seconds++;
}
else
{
Seconds=0;
// Toogle Minute LED
PORT(LED_M_PORT) ^= (1<<LED_M_PIN);
}
}
 
 
// Main
int main()
{
// Enable LED Output
DDR(LED_S_PORT) |= (1<<LED_S_PIN);
DDR(LED_M_PORT) |= (1<<LED_M_PIN);
 
// Set MAX value for Timer1
OCR1A = F_CPU/256/2-1; // 1/2s
 
// Set Timer1 to CTC with presacaller 1/256
// CTC Mmode counts from 0 to value stored in OCR1A
// and generates interrupt every time it goes back to 0
// CS12 CS11 CS10 Prescaller
// 0 0 1 clkI/O/1 (No prescaling)
// 0 1 0 clkI/O/8 (From prescaler)
// 0 1 1 clkI/O/64 (From prescaler)
// 1 0 0 clkI/O/256 (From prescaler)
// 1 0 1 clkI/O/1024 (From prescaler)
TCCR1B |= (1<<CS12) | (1<<WGM12);
 
// Enable Interrupt for Timer1 OCRA
TIMSK |= (1<<OCIE1A);
 
// Enable Global (CPU) Interrupt
sei();
 
// Main Loop
for(;;)
{
// Do any job here
}
 
return 0;
}