/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.4 Standard
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 2011-09-08
Author  : 
Company : 
Comments: ½ºÅ×ÇÎ ¸ðÅÍ ÁÖ¼® Ãß°¡ 2011.09.08


Chip type           : ATmega128
Program type        : Application
Clock frequency     : 16.000000 MHz
Memory model        : Small
External RAM size   : 0
Data Stack size     : 1024
PORT0 A
PORT1 _A
PORT2 B
PORT3 _B
*****************************************************/

#include <mega128.h>
#include <delay.h>
#define A PORTC.0
#define _A PORTC.1
#define B PORTC.2
#define _B PORTC.3


char cw[4]={0x01,0x04,0x02,0x08};

char ccw[4]={0x08,0x02,0x04,0x01};
bit Flag;
int Dir;
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Place your code here
 static int cnt=0;
    cnt++;
    if(cnt==2)//Å¬·° ½ÅÈ£ º¯¼ö 
    {
      Flag=1;
      cnt=0;
    } 
    Dir++;//¹æÇâ Á¦¾î º¯¼ö 
    if(Dir==2000)
    Dir=0;   
    TCNT0+=0x06;
}

// Declare your global variables here

void main(void)
{
int i=0;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTC=0x00;
DDRC=0xff;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
ASSR=0x00;
TCCR0=0x04;
TCNT0=0x06;
OCR0=0x00;

TIMSK=0x01;
// Global enable interrupts
#asm("sei")

while (1)
      {
         if(Flag)
         {
         
         if(0<Dir&&Dir<1000) //¼ø¹æÇâ 
         {
         PORTC=ccw[i];
         }
         if(1000<Dir&&Dir<2000)//¿ª¹æÇâ 
         {
         PORTC=cw[i];
         }
         i++;
         Flag=0;
         }
         if(i==4)
         {
          i=0;
         }
      
      };
}
