Full Version : Snoooze LED with PWM Atmega16 (CVC)
avr >>BEGINNER PROJECTS >>Snoooze LED with PWM Atmega16 (CVC)


AVR_Admin- 04-16-2006
Snoooooze LED

This is to produce a Fast PWM to turn on off LED in analog manner.
Target Device Atmega16, STK500, CLK= 3.686MHz, PortB connected to LEDs.


CODE
#include <Mega16.h>
#include <Delay.h>
//-----------------------------------------
void setcounter0(unsigned char d)
{
TIMSK=0x00;        //Fast PWM Mode
TCCR0=0x7B;
OCR0=d;
TCNT0=0x00;
}
//------------------------------------------

unsigned char i=0x00;
unsigned char j=0x00;
//-----------------------
void main (void)
{
//----------------------
DDRA=0x00;
DDRB=0x08;
DDRC=0x00;
DDRD=0x00;
//-----------------------
setcounter0(i);

//TIMSK=0x00;        //normal mode
//TCCR0=0x15;
//OCR0=0xFF;
//TCNT0=0x00;
//----------------------
done:
for (i=0x01; i<0xff; i++)
   {
    setcounter0(i);
    delay_ms(5);
   }
   
for (j=0xFE; j>0x01; j--)
   {
    setcounter0(j);
    delay_ms(5);
   }
goto done;

}



Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.