ISD4003驅動程式(基於51微控制器,硬體除錯通過)

zc850463390zc發表於2012-10-01
#include <reg52.h>
#define uint unsigned int
#define POWERUP  0X2000
#define SETPLAY  0xe000
#define PLAY     0xf000
#define SETREC   0xa000
#define REC      0xb000
#define STOP_WRDN 0X1000
#define STOP     0x3000
#define RINT     0X3000

sbit SS=P2^0;
sbit MOSI=P2^1;
sbit MISO=P2^2;	
sbit SCLK=P2^3;
sbit INT=P2^4;		  
	
sbit  KEY1=P1^1;
sbit KEY2=P1^2;
sbit KEY3=P1^7;
sbit LED1=P2^7;
sbit LED2=P2^6;	
int address[]={0,0,93,93*2,93*3,93*4,93*5,93*6,93*7,93*8,93*9,93*10};  //把ISD4003的整個記憶體地址分為10塊
				                                       //
void delay(int time)
{
	unsigned char i,j,temp;
	temp=(char)((100*12)/12+23);
	for(i=0;i<time;i++)
	{
		for(j=0;j<temp;j++);
	}
}
uint SendOrder(uint order)  //傳送命令函式
{
	uint i,address=0;
	SS=1;
	SS=0;
	for(i=0;i<16;i++)
	{
		SCLK=0;
		if(order&0x0001)MOSI=1;
		else MOSI=0;
		SCLK=1;
		SCLK=1;
		SCLK=0;
		if(MISO)address|=0x8000;
		address>>=1;
		order>>=1;
	}
	SS=1;
	return address;
}
void Play(uint address) //從address出開始播放
{
 SendOrder(POWERUP);
 delay(30);//30ms
 SendOrder(SETPLAY+address);
 SendOrder(PLAY);
}
void Record(uint address) //從address出開始錄音
{
	SendOrder(POWERUP);
	delay(30);//30ms
	SendOrder(POWERUP);
	delay(30);
	delay(30);
	SendOrder(SETREC+address);
	SendOrder(REC);
}
void main()
{
	int i,flag,pflag;
	KEY1=1;
	KEY2=1;
	INT=1;
	flag=0;
	pflag=0;
	while(1)
	{
		if(KEY2==0) //key2鍵用來控制播放
		{
			delay(50);
			if(KEY2==0)
			{
				pflag++; //來控制播放的地址
				SendOrder(STOP_WRDN);
				Play(address[pflag]);
				P0=pflag;
				while(INT);
				SendOrder(STOP_WRDN);
				while(KEY2==0);
			}
		}
		if(KEY1==0)//key1鍵用來控制錄音
		{
			delay(50);
			if(KEY1==0)
			{
				flag++;//用來控制錄音的地址
				SendOrder(STOP_WRDN);
				Record(address[flag]);
				P0=flag;
				while(KEY1==0);
			
			}
		}
		if(KEY3==0)//key3用來控制關閉
		{
			delay(50);
			if(KEY3==0)
			{
				SendOrder(STOP_WRDN);
				LED1=1;
				P0=0XFF;
				while(KEY3==0);
			}
		}	
	}	
}

相關文章