/*****************************************************
This program was produced by the
CodeWizardAVR V2.04.4a Advanced
Automatic Program Generator
© Copyright 1998-2009 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 23.02.2012
Author  : NeVaDa
Company : my
Comments: 


Chip type               : ATmega8
Program type            : Application
AVR Core Clock frequency: 3.686400 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*****************************************************/

#include <mega8.h>
#include <delay.h>
  unsigned int h;
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here

}

// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
// Place your code here

}

// Standard Input/Output functions
#include <stdio.h>

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=In 
// State7=T State6=T State5=P State4=P State3=P State2=1 State1=1 State0=P 
PORTB=0x3F;
DDRB=0x06;

// Port C initialization
// Func6=In Func5=Out Func4=In Func3=In Func2=In Func1=Out Func0=In 
// State6=P State5=0 State4=P State3=P State2=P State1=0 State0=P 
PORTC=0x5D;
DDRC=0x22;

// Port D initialization
// Func7=In Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In 
// State7=P State6=P State5=0 State4=0 State3=P State2=P State1=P State0=P 
PORTD=0xCF;
DDRD=0x30;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;

                                        // Timer/Counter 1 initialization
                                        // Clock source: System Clock
                                        // Clock value: 3.600 kHz
                                        // Mode: Fast PWM top=03FFh
                                        // OC1A output: Inverted
                                        // OC1B output: Inverted
                                        // Noise Canceler: Off
                                        // Input Capture on Falling Edge
                                        // Timer1 Overflow Interrupt: Off
                                        // Input Capture Interrupt: Off
                                        // Compare A Match Interrupt: Off
                                        // Compare B Match Interrupt: Off
                                        TCCR1A=0xF3;
                                        TCCR1B=0x0D;
                                        TCNT1H=0x00;
                                        TCNT1L=0x00;
                                        ICR1H=0x00;
                                        ICR1L=0x00;
                                        OCR1AH=0x00;
                                        OCR1AL=0x00;
                                        OCR1BH=0x00;
                                        OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Low level
// INT1: On
// INT1 Mode: Low level
GICR|=0xC0;
MCUCR=0x00;
GIFR=0xC0;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: Off
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 19200
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x0B;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// Global enable interrupts
#asm("sei")

while (1)
        {  for (h=0;h<1023;h++) {  
        OCR1B--; 
        delay_ms(1);
        #asm("wdr")  
          };
        // delay_ms(1000);
        for (h=0;h<1023;h++) {  
         OCR1B++; 
         delay_ms(1);
          #asm("wdr")  
           }; 
       

      };
}
