void init_port();
void init_timer();
volatile long DELAY,DELAY1;
volatile long time[]={1,100,500,1000,2000,4000,5000,6000,7000,8000,9000,10000,11000,12000,13000,14000,15000,16000,17000,18000};
volatile long time1[]={19999,19900,19500,19000,18000,16000,15000,14000,13000,12000,11000,10000,9000,8000,7000,6000,5000,4000,3000,2000};
volatile char j=0,count=0;
void setup() {
volatile long i;
init_port();
init_timer();
DELAY=time[0];
DELAY1=time1[0];
volatile char *portf_data = (volatile char *)0x31;
while(1)
{
*portf_data=0x01;
for(i=0;i<DELAY;i++);
*portf_data=0x00;
for(i=0;i<DELAY1;i++);
}
}
void init_timer()
{
volatile char *Timer1_TCCR1A = 0x80;
volatile char *Timer1_TCCR1B = 0x81;
volatile short *Timer1_TCNT1 = 0x84;
volatile short *Timer1_OCR1A = 0x88;
volatile char *Timer1_TIMSK1 = 0x6F;
*Timer1_TCCR1A = 0;
*Timer1_TCCR1B = 0;
*Timer1_TCNT1 = 0;
*Timer1_OCR1A = 65535; //compare match register 16MHZ/256
*Timer1_TCCR1B =(1 << WGM12) | (1<<CS12) | (1<<CS10); //CTC mode & 1024 prescaler
*Timer1_TIMSK1 = 0x02; // enable timer compare interrupt
}
void init_port()
{
volatile char *portf_dir = (volatile char *)0x30;
*portf_dir = 0x01;
}
ISR(TIMER1_COMPA_vect)
{
if(j==19)
{
count=1;
}
if(j==0)
{
count=0;
}
if(count==0)
{
DELAY=time[j];
DELAY1=time1[j];
j++;
}
if(count==1)
{
j--;
DELAY=time[j];
DELAY1=time1[j];
}
}
void loop() {
// put your main code here, to run repeatedly:
}