#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define ShortPress 30 //短时间按下
#define LongPress 200 //长时间按下
#define MUTE_CTROL 0x3f //静音控制数据
#define AT24c02_ADD 0xa0 //AT24C02地址
#define SC7313_ADD 0x88 //SC7313地址
#define VOL_SAVE_ADD 1 //音量参数断电保存地址
#define BASS_SAVE_ADD 8 //低音参数断电保存地址
#define TREBLE_SAVE_ADD 16 //高音参数断电保存地址
#define LINE_SAVE_ADD 24 //输入选择参数断电保存地址
sbit sda=P2^4;
sbit scl=P2^5;
sbit led=P3^7;
sbit a=P3^4;
sbit b=P3^3;
sbit sw=P3^2;
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
bit flag;
uint time;
static uchar long_press_count=0,vol=0,bass=7,treble=7;
static char left=0,right=0;
static uchar input_flag=0;
uchar code num[]={0x03,0x05,0x19,0x19,0x19,0x19,0x05,0x03, //右声道符号
0x18,0x14,0x13,0x13,0x13,0x13,0x14,0x18}; //左声道符号
uchar code tone[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08}; //bass&treble查表,分别对应低音和高音的衰减
/* 0x88= 10001000 ,由tone[]与0x88求和来计算bass&treble增益
0x00 0000 -14dB
0x01 0001 -12dB
0x02 0010 -10dB
0x03 0011 -8dB
0x04 0100 -6dB
0x05 0101 -4dB
0x06 0110 -2dB
0x07 0111 0dB 1111 0x0f
0x0e 1110 2dB
0x0d 1101 4dB
0x0c 1100 6dB
0x0b 1011 8dB
0x0a 1010 10dB
0x09 1001 12dB
0x08 1000 14dB
*/
//微秒级延时
void delay()
{ ;; }
//1MS延时
void delay_ms(uint i)
{
uint x,y;
for(x=i;i>0;i--)
for(y=123;y>0;y--);
}
//开始信号
void start()
{
sda=1;
delay();
scl=1;
delay();
sda=0;
delay();
}
//停止信号
void stop()
{
sda=0;
delay();
scl=1;
delay();
sda=1;
delay();
}
//应答
小鹿的玫瑰花教学设计
bit respons()
{
scl=1;
delay();
while(sda==1);
scl=0;
delay();
funny
return(1);
}
/
/向LCD写命令
void write_com(uchar com)
{
P1=com;
rs=0;
en=1;
delay_ms(1);
en=0;
delay_ms(1);
}
//向LCD写数据
void write_data(uchar dat)
{
P1=dat;
rs=1;
en=0;
delay_ms(1);
en=1;
delay_ms(1);
en=0;
}
//自定义字符集
void Lcd_ram()
{
uint i,j,k=0,temp=0x40;
for(i=0;i<2;i++)
{
for(j=0;j<8;j++)
{
write_com(temp+j);
delay_ms(2);
write_data(num[k]);
k++;
}
temp=temp+8;
}
}
//初始化
void init()
{
sda=1;
delay();
scl=1;
delay();
EX1=1;
IT1=1;
EA=1;
TMOD=0x01;
TL0=(65536-1000)%256;
TH0=(65536-1000)/256;
ET0=1;
TR0=0;
rw=0; //设置为写状态
write_com(0x38); //设置16*2显示,5*7点阵,8位数据接口
write_com(0x0c); //开显示,不显示光标,光标不闪烁
write_com(0x06); //写一个字符后,地址指针自动加1,不整屏移动
Lcd_ram(); //写特殊字符
write_com(0x01); //清屏,数据指针清0
}
//向LCD的某个地址写入1个BYTE数据
void write_1602(uchar com,dat)
{
write_com(com);
write_data(dat);
}
//从某个开始地址向LCD写入字符串
void display(add,uchar *str)
{
write_com(add);
delay_ms(3);
while(*str!='\0')
{
write_data(*str++);
}
*str = 0;
}
//向IIC设备写入1BYTE的数据
void write_i2c(uchar dat)
{
uchar i,temp;
temp=dat;
for(i=0;i<8;i++)
{
temp=temp<<1;
scl=0;
delay();
sda=CY;
delay();
scl=1;
delay();
}
scl=0;
delay();
sda=1;
delay();
}
//从IIC设备读取数据
uchar read_i2c()
{
uchar i,k;
scl=0;
delay();
sda=1;
delay();
for(i=0;i<8;i++)
{
scl=1;
delay();
k=(k<<1)|sda;
scl=0;
delay();
}
return k;
}
//向24c02的某个地址写入1byte数据
void write_24c02(uchar address,uchar dat)
{
start();
write_i2c(AT24c02_ADD);
while(!respons());
write_i2c(address);
while(!respons());
write_i2c(dat);
while(!respons());
cdkey是什么意思stop();
}
//从24c02的某个地址读取1byte数据
曲轴箱
uchar read_24c02(uchar address)
{
uchar dat;
start();
write_i2c(AT24c02_ADD);
while(!respons());
write_i2c(address);
while(!respons());
start();
write_i2c(0xa1);
while(!respons());
dat=read_i2c();
stop();
return dat;
}
//向SC7313写入1BYTE数据
void write_7313(uchar dat)
{
start();
write_i2c(SC7313_ADD);
while(!respons());
write_i2c(dat);
while(!respons());
stop();
北国之春日语版
}
//判断长按&短按,松手&定时检测
void key_press()
{
static bit f=0;
if(!sw)
{
delay_ms(10);
if(!sw)
{
TR0=1;
while(!sw&&!(time>LongPress));
TR0=0;
if(time>LongPress)
{
long_press_count++;
if(long_press_count==7)long_press_count=0;
switch(long_press_count)
{
ca 0:
{
write_com(0x01);
display(0x83,"VOLUME");
display(0x81+0x40,"Volume Ctr Sys");
write_1602(0x8B,(30-(vol/2))/10+0x30);
write_1602(0x8C,(30-(vol/2))%10+0x30);
break;
}
ca 1:
{
write_com(1);
write_1602(0x86,'L');
write_1602(0x89,'R');
write_1602(0x85,0x01);
write_1602(0x8A,0x00);
display(0x81+0x40,"Volume Ctr Sys");
if(left<0)
saildisplay(0x81,"00");
el
{
write_1602(0x81,(left)/3/10+0x30);
write_1602(0x82,(left)/3%10+0x30);
}
if(right<0)
display(0x8D,"00");
el
{
write_1602(0x8D,(right)/3/10+0x30);
wonderland是什么意思
write_1602(0x8E,(right)/3%10+0x30);
}
break;
}
ca 2:
{
write_com(1);
display(0x84,"BASS");
display(0x81+0x40,"Volume Ctr Sys");
if(bass<7)
{
write_1602(0x8A,'-');
write_1602(0x8B,(7-bass)+0x30);
}
el if(bass>7)
{
write_1602(0x8A,'+');
write_1602(0x8B,(bass-7)%10+0x30);
}
el
display(0x8A,"00");
break;
}
ca 3:
{
write_com(1);
display(0x83,"TREBLE");
display(0x81+0x40,"Volume Ctr Sys");
if(treble<7)
{
write_1602(0x8B,'-');
write_1602(0x8C,(7-treble)+0x30);
}
el if(treble>7)
{
write_1602(0x8B,'+');
write_1602(0x8C,(treble-7)%10+0x30);
}
el
display(0x8B,"00");
break;
}vibe x
ca 4:
{
write_com(1);
display(0x83,"INPUT");
if(input_flag == 0)
{
display(0x8B,"PC");
display(0x80+0x41,"Lin1 +11.25dB");
}
el if(input_flag == 1)
{
display(0x8A,"MP3");
display(0x80+0x44,"Lin2 0dB");
}
el if(input_flag == 2)
{
display(0x8A,"DAC");
display(0x80+0x42,"Lin3 +3.75dB");
}
el
display(0x8A,"ERROR!");
pretty
break;
}
新东方邮件系统
ca 5:
{
write_com(1);
display(0x84,"LED");
display(0x81+0x40,"Volume Ctr Sys");
if(led)
display(0x89,"OFF");
el
display(0x8A,"ON");
break;
}
ca 6:
{
write_com(1);
display(0x80,"Design:TerryLi");
display(0x80+0X40,"QQ:182507197");
}
}
while(!sw);
}
el if((time>ShortPress)&&(time<LongPress))
{
if(!long_press_count)
{
f=!f;
if(f)
{
write_7313(MUTE_CTROL);
write_com(1);
display(0x86,"MUTE");
display(0x81+0x40,"Volume Ctr Sys");
}
el
{
write_7313(vol);
write_com(1);
display(0x83,"VOLUME");
display(0x81+0x40,"Volume Ctr Sys");