Docstoc

flashlight_timer-c

Document Sample
flashlight_timer-c Powered By Docstoc
					                                                             Electronic Department EEPIS-ITS
                                                                    Embedded Research Group




Flashlight with AVRStudio




  Copyright © by Akhmad hendriawan
  hendri@eepis-its.edu
  Seluruh dokumen ini dapat digunakan, dimodifikasi dan disebarkan
  secara bebas untuk tujuan bukan komersial (nonprofit), dengan syarat
  tidak menghapus atau merubah atribut penulis dan pernyataan
  copyright   yang     disertakan   dalam   setiap   dokumen.   Tidak
  diperbolehkan melakukan penulisan ulang, kecuali mendapatkan ijin
  terlebih dahulu dari penulis
                                                                       Electronic Department EEPIS-ITS
                                                                              Embedded Research Group

1. Create new project. In project type field select Avr GCC. In Project name field type flashtimer .
   In initial file type Flashtimer. Select next
                                                                    Electronic Department EEPIS-ITS
                                                                           Embedded Research Group

2. In debug Platform field select AVR Simulator. In select Device select Atmega8
                                                      Electronic Department EEPIS-ITS
                                                             Embedded Research Group

    3. Double Click flashtimer.c




  4. type this code
//* DESCRIPTION
//*
//* Tutorial program for the AVR Assembler and Simulator.
//* The program cointains a simple routine which flashing LED using
//* timer 1 interrupt with interval time 500ms
//* note:
//* - in interupt overflow flag reset by hardware
//* - prescaller 64 so clk is 64 / 4 Mhz = 16 us
//* - flashing led 1 second with dcyle 50%, so interval time
//*   is 500ms
//* - counter 500000us/16us = 31250
//* - because timer is up so timer-value= -31250 or 0x85EE
//*
//* WARNING: The program contains intentional errors for
//* tutorial purposes.
//************************************************************************
#include <avr/io.h>
#include <avr/interrupt.h>

ISR(TIMER1_OVF_vect)
{
//presscaller
   TCNT1=0x85EE;
   PORTD^=(1<<PD3);

}

static void avr_init(void);
int main (void)
{
  avr_init();
                                                             Electronic Department EEPIS-ITS
                                                                    Embedded Research Group


    while(1)
    {

    }
}

static void avr_init(void)
{
   unsigned char temp;
// counter
   TCNT1=0x85EE;
// use portD as output
   DDRD=0xFF;
//enable timer 1 interrupt
   TIMSK= (1<<TOIE1);
//prescaller
   TCCR1B=(1<<CS10)|(1<<CS11);
    //return;
   sei();
}


    5. In main menu, Select Project  Configuration Option
                                                 Electronic Department EEPIS-ITS
                                                        Embedded Research Group

6. in frequency field type 4000000




7. from main menu select build  Build and Run
                                            Electronic Department EEPIS-ITS
                                                   Embedded Research Group

   8. In Main menu select DebugStep Into




   9. See the result in i/o tab view




Last revised on october 27, 2007


reference:
    1. Atmel AVR datasheet
    2. www.avrfreaks.net
                         Electronic Department EEPIS-ITS
                                Embedded Research Group

3. www.avrtutor.com
4. www.xdesignlabs.com
5. Atmel AvrStudio

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:13
posted:2/22/2010
language:Indonesian
pages:8