📄 zy17240.c
字号:
#include<reg932.h>
#include "ZY17240.H"
/*********************************************************************************************************
**函数名称:Delay_us
**函数功能:N ms软件延时
**入口参数:x 延时参数x
**********************************************************************************************************/
void Delay_ums(uint x)
{
while(x--);
}
/********************************************************************************************************
**函数名称:SPI_RW_byte
**函数功能:通过MOSI管脚发送字节同时读回MISO管脚字节
**入口参数:com 发送到ZY17240的命令字节
**********************************************************************************************************/
uchar SPI_RW_byte(uchar com)
{
uchar i,temp;
temp=0;
for(i=0;i<8;i++)
{
ZY17240_SCLK=0;
Delay_ums(0);
ZY17240_MOSI= (bit)(com&0x01);
com>>= 1;
temp>>= 1;
if(ZY17240_MISO)
{
temp|=0x80;
}
else
{
temp&=0x7f;
}
ZY17240_SCLK= 1;
Delay_ums(0);
}
ZY17240_MOSI = 1;
return(temp);
}
/****************************************************************************************************************
**函数名称:CLR_Int
**函数功能:清除中断标志
**入口参数:无
*****************************************************************************************************************/
void CLR_Int()
{
uchar temp;
do
{
ZY17240_SS=0;
temp=SPI_RW_byte(0x04); //发送清除中断命令并读回SR0的低字节
SPI_RW_byte(0x00);
ZY17240_SS=1;
Delay_ums(0);
}while(temp&0x01); //判断CMD_ERR位是否为1
}
/***************************************************************************************************************
**函数名称:Wait_Ready
**函数功能: 发送完一条SPI命令后等待从机准备好接收下一条指令
**入口参数:无
****************************************************************************************************************/
void Wait_Ready( )
{
uchar temp;
do
{
ZY17240_SS=0;
SPI_RW_byte(0x15); //发送读状态寄存器命令,同时激活LED显示
SPI_RW_byte(0x00);
temp=SPI_RW_byte(0x00); //读回SR1的低字节( D0-RDY)
ZY17240_SS=1;
}while(!(temp&0x01)); //判断RDY是否为1
}
/*************************************************************************************************************
**函数名称:Wait_Finish
**函数功能:等待操作完成
**入口参数:无
***************************************************************************************************************/
void Wait_Finish( )
{
uchar temp1;
do
{
ZY17240_SS=0;
temp1=SPI_RW_byte(0x15); //发送读状态寄存器命令,同时读回SR0低字节
SPI_RW_byte(0x00);
SPI_RW_byte(0x00);
ZY17240_SS=1;
Delay_ums(0);
Delay_ums(0);
}while(!(temp1&0x10)); //判断INT位是否为1
CLR_Int(); //清除中断标志
Wait_Ready( ); //等待从机准备好接收新命令
}
/**************************************************************************************************************
**函数名称:Send_17240Com
**函数功能:发送两个字节的命令
**入口参数:com 要发送到ZY17240的命令字节
***************************************************************************************************************/
void Send_17240Com(uchar com)
{
uchar temp;
do
{
ZY17240_SS=0;
temp=SPI_RW_byte(com); //读回SR0的低字节
SPI_RW_byte(0x00);
ZY17240_SS=1;
Delay_ums(0);
}while(temp&0x01); //判断CMD_ERR位是否为1
}
/***************************************************************************************************************
**函数名称:WR_APC
**函数功能:装载APC寄存器
**入口参数:com1,com2 装载在APC寄存器的数据
****************************************************************************************************************/
void WR_APC(uchar dat1,uchar dat2)
{
uchar temp;
do
{
ZY17240_SS=0;
temp=SPI_RW_byte(0x65); //发送装载APC寄存器命令并读回SR0的第一个字节
SPI_RW_byte(dat1); //装载D7:D0
SPI_RW_byte(dat2); //装载D11:D8
ZY17240_SS=1;
Delay_ums(0);
}while(temp&0x01); //判断CMD_ERR位是否为1
}
/***************************************************************************************************************
**函数名称:SET_Ctr
**函数功能:发送选段控制命令
**入口参数:com,s_adr,e_adr 命令,起始地址,结束地址
****************************************************************************************************************/
void SET_Ctr(uchar com,uchar s_adr,uchar e_adr)
{
uchar temp;
do
{
ZY17240_SS=0;
temp=SPI_RW_byte(com); //发送选段操作命令并读回SR0的第一个字节
SPI_RW_byte(0x00);
SPI_RW_byte(s_adr); //发送起始地址
SPI_RW_byte(0x00);
SPI_RW_byte(e_adr); //发送结束地址
SPI_RW_byte(0x00);
SPI_RW_byte(0x00);
ZY17240_SS=1;
Delay_ums(0);
}while(temp&0x01); //判断CMD_ERR位是否为1
Wait_Finish( );
}
/*****************************************************************************************************************
**函数名称:ZY17240_Init
**函数功能:ZY17240初始化
**入口参数:无
*******************************************************************************************************************/
void ZY17240_Init( )
{
uchar i;
Send_17240Com(PU); //发送上电命令
for(i=0;i<100;i++)
{ //延时50ms
Delay_ums(255);
}
}
/* void main( )
{
P0M1=0X00; //设置I/O口输出模式为准双向口
P0M2=0X00;
P1M1=0X00;
P1M2=0X00;
ZY17240_Init( ); //初始化语音模块
WR_APC(0x40,0x04); //装载APC寄存器
SET_Ctr(SET_PLAY,0x46,0x4E); //选短播放
SET_Ctr(SET_PLAY,0x10,0x13);
}
// SET_Ctr(SET_PLAY,0x10,0x12);
SET_Ctr(SET_PLAY,0x13,0x15);
SET_Ctr(SET_PLAY,0x2D,0x2F);
SET_Ctr(SET_PLAY,0x34,0x3B);
SET_Ctr(SET_PLAY,0x1D,0x1F);
SET_Ctr(SET_PLAY,0x34,0x36);
SET_Ctr(SET_PLAY,0x3C,0x43);
// while(1)
// {
// SET_Ctr(SET_PLAY,0x4F,0x57);
// }
//while(1);
// P2M2=0XC0;
// P2M1=0XC0;
//ZLG7289_Init( );
//Send_Data(0XC8,0X00);
// while(1);
} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -