?? 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 + -