|
点击浏览该文件
请尊重原创,引用本文发表者,请注明出处.
作者:彬
联系电话:15914326550
qq:243280383 870035775
邮箱: 870035775@QQ.COM
博客: http://blog.sina.com.cn/vision243280383
基于单片机的多通道切换双音道音量控制 16级别 (2008-09-15 10:50:51)
作品简介:该作品支持三路音量信号的输入,经遥控控制切换后输出.音量被分为16个级别的音量大小,通过遥控器能控制音量在这16个级别之中切换,从而控制音量大小.
作品作用:可以同时把收音机 电脑 MP3 等三路音频信号同时输入机器中,使用手上的遥控器就能在这三路音频信号中切换,并且控制音量大小
下面共享16级别单声道原代码:
#include <reg51.h> #include <intrins.h> #define uchar unsigned char //晶震4M sbit channel_bit=P2^7; //数码管小数点作为显示音量与通道的区别 //a-h 接p2^0-p2^7 uchar code DB[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xc6,0x9c,0x86,0x8e}; //0~15数据 void DelayMs(unsigned int number) //延时函数延时1 MS ??????????????????????? { unsigned char temp; for(;number!=0;number--) { for(temp=488;temp!=0;temp--) ; } }
uchar Key() //键盘扫描子程序 { uchar KValue; P3|=0xff; //将P1口的接键盘的位置1 KValue=P3; KValue|=0x00; //将未接键的位置1 if(KValue==0xff) // return(0); //返回 DelayMs(20); //延时10ms,去键抖 KValue=P3; KValue|=0x00; //将未接键的位置1 if(KValue==0xff) //位均为1,无键按下 return(0); //返回 //如尚未返回,说明一定有1或更多位被按下 //去掉了等待按键释放的检验因为希望能一直按住按键 能连续的控制音量 return(KValue); //返回按键值 }
Keyplay(uchar key) // 按键值 处理函数 { uchar password; if (( key&0x80)==0) // 按键值位3时的处理 password=3; if (( key&0x40)==0) // 按键值位2时的处理 password=2; if (( key&0x20)==0) password=1; if (( key&0x10)==0) // 按键值位0时的处理 password=0; return password; //返回输入的按键值 } void Voi_4067(uchar voi) { uchar i ,j ; i=voi|0xf0;j=voi&0x0f; P1=P1&i; P1=P1|j; } void main () { uchar i=4,channel=1,cound=0, key; P1=0xff; Voi_4067(7); P2=DB[i]; while(1) { key=Key(); if(key) { switch ( Keyplay(key) ) { case 0: i++ ;if(i>15) i=15; P2=DB[i]; //显示音量 Voi_4067(i); //升音 DelayMs(300);cound=1; break; case 1: i--; if(i>15) {i=0;P0=0;} P2=DB[i]; Voi_4067(i); //降音 DelayMs(300);cound=0; break;
case 2: channel++; if(channel>3) channel=3; P0=channel; P2=DB[channel];channel_bit=0; DelayMs(300); break; case 3: channel--; cound=0; if(channel>7) channel=0; P0=channel; P2=DB[channel];channel_bit=0; DelayMs(300);break; } if(cound==1) //静音组合键(要在按键2 后紧跟着 有按键3 才有效 )进行 静音操作 { if( Keyplay(key)==2 ) { cound=0;P0=0; } //P0用于控制音频通道 0通道没有音频接入为静音 } } } }
|