ISD2560录放控制程序
扫描二维码
随时随地手机看文章
#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秒 时间计数一次
uchar num=0; //Timer0中断计数,每计数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()//根据录音结束标志,判断此段放音结束
{
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;
}