资源简介
ISD4004语音芯片C语言程序,采用ATmega16单元片机控制,用外部8M晶振.
代码片段和文件信息
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long int
#define RS_0 (PORTC&=~BIT(PC5))
#define RS_1 (PORTC|=BIT(PC5))
//#define RW_0 (PORTC&=~BIT(PC6))
//#define RW_1 (PORTC|=BIT(PC6))
#define E_0 (PORTC&=~BIT(PC6))
#define E_1 (PORTC|=BIT(PC6))
#define LS_0 (PORTC&=~BIT(PC7))
#define LS_1 (PORTC|=BIT(PC7))
#define ds1302_clkburst_reg 0xbe
#define DDR_SPI DDRB
#define DD_MOSI 5
#define DD_SCK 7
#define DD_SS 4
uchar key=0biao=0flagflg=1;
uint yearmonthdayweekhourminutesecond;
//ulong r_shu=0p_shu=0;
long int r_shu=0p_shu=0;
#pragma interrupt_handler zhongduan0:2
#pragma interrupt_handler zhongduan1:3
void zhongduan0()
{
//while(PIND!=0xff);
GICR=0x80;
wr_com(0x01);
delay(5);
wr_com(0x8c);
wr_s(“rec“);
LS_1;
rec(r_shu);
while(1)
{
playshizhong();
if((key_press()==5))
{
while(PIND!=0xff);
LS_0;
stop();
break;
}
}
GICR=0xc0;
}
void zhongduan1()
{
GICR=0x40;
LS_0;
wr_com(0x01);
delay(5);
wr_com(0x8c);
wr_s(“play“);
play(p_shu);
GICR=0xc0;
}
void delay(uint z)
{
uint xy;
for(x=z;x>0;x--)
for(y=1141;y>0;y--);
}
uchar key_press()
{
uchar v;
key=0;
//PIND=0xff;
v=PIND;
switch(v)
{
case 0xfe:v=1;break;
case 0xfd:v=2;break;
case 0xef:v=5;break;
case 0xdf:v=6;break;
case 0xbf:v=7;break;
case 0x7f:v=8;break;
}
if((PINC&0x01)==0)
{
v=9;
delay(20);
}
if((PINC&0x02)==0)
{
v=10;
delay(20);
}
return v;
}
void SPI_MasterInit()
{
DDR_SPI = (1< SPCR = (1< }
//****************************数据传送函数**********************************
void SpiTransmit(unsigned char data)
{
SPDR = (unsigned char)data;
while(!(SPSR&(1< }
void cmdSend(unsigned int Addrunsigned char cmd)
{
PORTB = PORTB&(~(1< NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();//为保证那个500ns
SpiTransmit(Addr); //传地址低位
SpiTransmit(Addr>>8); //传地址高字节
SpiTransmit(cmd); //传命令
PORTB = PORTB|(1< NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();//为保证那个500ns
}
//*************************放音函数**********************
void play(unsigned int addrs)
{
cmdSend(0x00000x20);//Power up
delay(100);
cmdSend(addrs0xe0);//发地址值为addr的Setplay命令
cmdSend(0x00000xf0);//发Play命令
}
void play_fast(unsigned int addrs)
{
cmdSend(0x00000x20);//Power up
delay(100);
cmdSend(addrs0xe8);//从addrs地址快进
cmdSend(0x00000xf8);//发MC命令
}
//************录音函数************************
评论
共有 条评论