#include
#include
#include
#pragma interrupt_handler timer0_ovf:10
#pragma interrupt_handler int1_isr:3
#define DDR_address DDRA=0xfe
#define DDR_contrue DDRB|=BIT(PB0)|BIT(PB1)|BIT(PB2)
#define address PORTA
#define CE_H PORTB|=BIT(PB0)
#define CE_L PORTB&=~BIT(PB0)
#define PD_H PORTB|=BIT(PB1)
#define PD_L PORTB&=~BIT(PB1)
#define PLAY PORTB|=BIT(PB2)
#define RECORD PORTB&=~BIT(PB2)
uchar count=0;//每0.8秒 時間計數(shù)一次
uchar num=0; //Timer0中斷計數(shù),每計數(shù)100個為0.8秒
uchar play_addr=0;//放音地址
uchar record_addr=0;//錄音地址
uchar record_time=1;
void delay_isd2560()
{
uchar a,b;
for (a=0;a<100;a++)
for (b=0;b<100;b++)
;
}
void timer0_ovf()
{
TCNT0=5;
num++;
if (num>95)//num取值要略小于100,防止錄音時間超出分段地址時間(0.8秒)。
{
num=0;
count++;
record_addr++;//地址每加一次,錄音時間增加0.8秒
}
if (count>=((int)(record_time*10)/8))
{
stop();
TIMSK=0x00;
count=0;
num=0;
LCMDisplayString(4,3,"錄音停止");
}
}
void int1_isr()//根據(jù)錄音結(jié)束標志,判斷此段放音結(jié)束
{
stop();
LCMDisplayString(4,4,"放音停止");
}
void isd2560_init()
{
MCUCR|=0x08;
GICR|=0x80;
TIMSK=0x00;
TIFR=0;
TCCR0=0x04;
TCNT0=5;
SREG=0x80;
DDR_address;
DDR_contrue;
DDRD&=~BIT(PD3);
CE_H;
PD_H;
}
void record()
{
MCUCR&=~0x08;
address=record_addr<<1;
delay_isd2560();
RECORD;
PD_L;
CE_L;
TIMSK=0x01;
TCNT0=5;
num=0;
count=0;
}
void play()
{
MCUCR|=0x08;
TIMSK=0x00;
address=play_addr<<1;
delay_isd2560();
PLAY;
PD_L;
delay_isd2560();
CE_L;
delay_isd2560();
CE_H;
}
void stop()
{
TIMSK=0x00;
CE_H;
PD_H;
}