📄 i2c.c
字号:
/*
好利来音响部设计
未经同意不得散布于网络
2005年2月15日
*/
/*
本项目专门为宣传本站的51 PIC AVR 多功能学习开发板而奉献,仅供参考,请勿做商业用途,欢迎转载但要保留本站信息
志博电子专注于8位单片机开发板设计和教学
让人耳目一心的经济又豪华型开发板
性价比最高
仅售378!
欢迎访问我们的网站 www.elecmcu.com
*/
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#include <reg52.h>
#include <absacc.h>
#include "intrins.h"
#include "mylib.h"
#define iicadd 0x10;
sbit da=P3^6;
sbit cl=P3^7;
uchar eq_l;
uchar volume=32;
uchar bas_vol=0x07;
uchar trb_vol=0x07;
uchar code eff[15]={0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8};
extern uchar remkey;
void sta() //启动总线传输
{
da=1;
_nop_();
_nop_();
_nop_();
_nop_();
cl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
da=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
cl=0;
}
void stop() //结束总线传输
{
da=0;
cl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
da=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
da=0;
cl=0;
}
void mack()//发送应答位
{
da=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
cl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
cl=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
da=1;
}
void nmack()//发送非应答位
{
da=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
cl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
cl=0;
da=0;
}
bit cack() //发送状态检测
{
bit a=0;
da=1;
cl=1;
if(da==0)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
cl=0;
return(0);
}
else
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
cl=0;
return(1);
}
}
void wr1(void)//写数据1
{
da=1;
cl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
cl=0;
da=0;
}
void wr0()//写数据0
{
da=0;
cl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
cl=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
wrbyt(uchar byt)//写一个字节的数据到总线上
{
uchar temp=0x00;
uchar count;
for(count=0;count<8;count++)
{
if((byt<<count)&0x80)
wr1();
else
wr0();
}
}
uchar rdbyt() //从总线上读取一个字节的数据
{
uchar a=0,i=0;
for(i=0;i<8;i++)
{
da=1;
cl=1;
if(da==1)
{
a=(a<<1)+1;
cl=0;
}
else if(da==0)
{
a=a<<1;
cl=0;
}
}
return(a);
}
bit wrnbyt(uchar add,uchar start,uchar num,uchar *k) //向24C02(ADD)从字节(START)开始写(NUM)个字节
{
uchar *p=k;
uchar dk;
for(dk=0;dk<num;dk++,p++)
{
sta();
wrbyt(add);
mack();
wrbyt(start);
start=start+1;
mack();
wrbyt(*p);
mack();
stop();
delaytime(5000);
}
return(1);
}
bit rdnbyt(uchar add,uchar start,uchar num,uchar a[]) //从24C02(ADD)字节(START)开始读取(NUM)个字节放到数据缓冲区A[]中
{
uchar *p=a;
uchar dk;
sta();
wrbyt(add);
if(cack())
return(1);
wrbyt(start);
if(cack())
return(1);
sta();
wrbyt(add+1);
if(cack())
return(1);
for(dk=0;dk<num;dk++,p++)
{
*p=rdbyt();
if(dk==num-1)
nmack();
else
mack();
}
stop();
return(0);
}
void wr_pt2313(uchar com)
{
sta();
wrbyt(0x88);
mack();
wrbyt(com);
mack();
stop();
}
void channel(uchar fun)
{
if(fun==dvd_fun)
wr_pt2313(0x5e);
if(fun==radio_fun)
wr_pt2313(0x5d);
if(fun==tape_fun)
wr_pt2313(0x4f);
if(fun==tv_fun)
wr_pt2313(0x50);
}
void sub_vol(uchar dirc)
{
if(dirc)
{
if(volume<31)
volume++;
}
else
{
if(volume>0)
volume--;
}
wr_pt2313((0x3f&(63-volume*2)));
remkey=0x00;
vfd_volume(vol_vfd);
}
void trb_vol_ct(bit dirc)
{
if(dirc)
{
if(trb_vol<14)
trb_vol++;
}
else
{
if(trb_vol>0)
trb_vol--;
}
wr_pt2313((0x7f&(eff[trb_vol])));
remkey=0x00;
vfd_volume(trb_vfd);
}
void bas_vol_ct(bit dirc)
{
if(dirc)
{
if(bas_vol<14)
bas_vol++;
}
else
{
if(bas_vol>0)
bas_vol--;
}
wr_pt2313((0x6f&(eff[bas_vol])));
remkey=0x00;
vfd_volume(bas_vfd);
}
void eqchange()
{
if(eq_l==0)
{
wr_pt2313((0x6f&(eff[8])));
wr_pt2313((0x7f&(eff[8])));
eq_vfd(eq_l);
eq_l=1;
}
else if(eq_l==1)
{
if(band!=tv)
{
wr_pt2313((0x6f&(eff[14])));
wr_pt2313((0x7f&(eff[14])));
}
else
{
wr_pt2313((0x6f&(eff[14])));
wr_pt2313((0x7f&(eff[10])));
}
eq_vfd(eq_l);
eq_l=2;
}
else if(eq_l==2)
{
if(band!=tv)
{
wr_pt2313((0x6f&(eff[4])));
wr_pt2313((0x7f&(eff[14])));
}
else
{
wr_pt2313((0x6f&(eff[4])));
wr_pt2313((0x7f&(eff[10])));
}
eq_vfd(eq_l);
eq_l=3;
}
else if(eq_l==3)
{
wr_pt2313((0x6f&(eff[14])));
wr_pt2313((0x7f&(eff[4])));
eq_vfd(eq_l);
eq_l=0;
}
remkey=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -