没那么多时间去搞扩展功能了,就只是把基本功能完成,其它扩展功能就等以后再添加吧。
对于LM4811芯片,每次时钟的上升沿,声音提高或者降低3dB;UP/DOWN引脚为高电平时,每次上升沿,增加3dB,反之为低电平时,每次上升沿,降低3dB,下面是代码:
//音量增加函数
void Vol_Add(void)
{
LM4811_UpDown = 1;
LM4811_CLK = 0;
Delay_Us(100);
LM4811_CLK = 1;
Delay_Us(100);
LM4811_CLK = 0;
}
//音量减少函数
void Vol_Sub(void)
{
LM4811_UpDown = 0;
LM4811_CLK = 0;
Delay_Us(100);
LM4811_CLK = 1;
Delay_Us(100);
LM4811_CLK = 0;
}
主函数部分:
void main(void)
{
unsigned char System_Vol = 11; //系统音量
unsigned char Shadow_Vol = 0; //影子音量
unsigned char IR_EN = 0;
unsigned char Key_Val = 0;
unsigned int System_Time = 0; //系统运行一遍,变量加1
UART_Init();
GPIO_Config();
Timer0_Init();
INT0_Init();
LED = 0;
while(1)
{
if(irreceok) //接收完成
{
irpros(); //解码
irreceok = 0;
}
else
if(irprosok) //解码完成
{
irprosok = 0; //显示或者发送码制
LED = !LED;
IR_EN = 1;
}
else
IR_EN = 0;
Key_Val = Read_KeyVal(); //读取按键值
//静音
if((IR_EN && (ircode[2] == 0x0A || ircode[2] == 0x01)) || (Key_Val & 0x01))
{
SendData(System_Vol);
if(System_Vol != 0)
{
Shadow_Vol = System_Vol; //将系统音量值存入影子音量
System_Vol = 0;
}
else
{
System_Vol = Shadow_Vol; //将影子音量恢复到系统音量值
Shadow_Vol = 0;
}
}
else //音量+
if((IR_EN && (ircode[2] == 0x06 || ircode[2] == 0x0E)) || (Key_Val & 0x02))
{
SendData(System_Vol);
if(System_Vol < 15)
{
System_Vol ++;
Vol_Add();
}
System_Time = 0;
}
else //音量—
if((IR_EN && (ircode[2] == 0x04 || ircode[2] == 0x09)) || (Key_Val & 0x04))
{
if(System_Vol > 0)
{
System_Vol--;
Vol_Sub();
}
SendData(System_Vol);
System_Time = 0;
}
if(System_Vol == 0 || CHECK == 0) //静音以及插座退出
{
MUTE = 1;
if(System_Time % 10 == 0)
{
LED = !LED;
}
}
else //返回非静音状态
{
MUTE = 0;
if(System_Vol == 15)
{
if(System_Time % 20 == 0)
{
LED = !LED;
}
}
else
if(System_Time % 70 == 0)
{
LED = !LED;
}
}
Delay_Ms(10);
System_Time++;
}
}