单片机源程序如下:
- #include "wt588s16s.h"
- #include "delay.h"
- /**************************************************************************************************
- * @fn Initialize_wt588s16s_pins
- *
- * @brief 初始化芯片引脚,BUSY、DATA
- *
- * @param none
- *
- * @return None
- **************************************************************************************************/
- void Initialize_wt588s16s_pins(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd(WT588S16S_DATA_PERIPH,ENABLE);
- RCC_APB2PeriphClockCmd(WT588S16S_BUSY_PERIPH,ENABLE);
- GPIO_InitStructure.GPIO_Pin = WT588S16S_DATA;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(WT588S16S_DATA_GPIO, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = WT588S16S_BUSY;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(WT588S16S_BUSY_GPIO, &GPIO_InitStructure);
-
- GPIO_SetBits(WT588S16S_DATA_GPIO, WT588S16S_DATA);
- }
- /**************************************************************************************************
- * @fn Line_send_one_byte
- *
- * @brief 发送一个字节数据
- *
- * @param none
- *
- * @return None
- **************************************************************************************************/
- void Line_send_one_byte(unsigned char data)
- {
- unsigned char i;
- unsigned char data_temp = 0;
- for( i=0; i<8; i++){
- GPIO_SetBits(WT588S16S_DATA_GPIO, WT588S16S_DATA); //拉高发送数据
-
- data_temp = (data>>i)&0x01;
-
- if(data_temp == 0){
- delay_us(200); //200us
- GPIO_ResetBits(WT588S16S_DATA_GPIO, WT588S16S_DATA);
- delay_us(600); //600us
- }else{
- delay_us(600); //600us
- GPIO_ResetBits(WT588S16S_DATA_GPIO, WT588S16S_DATA);
- delay_us(200); //200us
- }
- }
- }
- /**************************************************************************************************
- * @fn Line_send_stop
- *
- * @brief 发送结束标志
- *
- * @param none
- *
- * @return None
- **************************************************************************************************/
- void Line_send_stop(void)
- {
- //地址数据连接符
- GPIO_SetBits(WT588S16S_DATA_GPIO, WT588S16S_DATA);
- delay_us(2000); //2MS
- GPIO_ResetBits(WT588S16S_DATA_GPIO, WT588S16S_DATA);
- delay_us(5000); //5MS
- }
- /**************************************************************************************************
- * @fn WT588S_play_music
- *
- * @brief 播放音乐
- *
- * @param data:控制命令
- *
- * @return None
- **************************************************************************************************/
- void WT588S_play_music(unsigned short data)
- {
- unsigned char data_temp_1,data_temp_2;
-
- data_temp_2 = (unsigned char)(data>>8);
- data_temp_1 = (unsigned char)(data&0x00ff);
-
- Line_send_stop();
- Line_send_one_byte(data_temp_1);
- Line_send_stop();
- Line_send_one_byte(data_temp_2);
- }
复制代码
所有程序51hei提供下载:
wt588s16s.zip
(1.33 KB, 下载次数: 32)
|