📄 iic_bit.c
字号:
templ=(uchar)(add%256);
if(!STE)
return;
SEN=0;
if(!STE)
{
SEN=1;
SCL=1;
SDA=1;
return;
}
start(); //开始信号
outbyte(IIC_WRITE|(temph<<1)); //写命令
nack(1); //等待应答
outbyte(templ); //写地址
nack(1);
outbyte(wbyte); //写数据
nack(1); //等待应答
stop(); //停止信号
SCL=1;
SDA=1;
SEN=1;
}
//=====================================================
//FUNCTION:RANDOM READ.'add' IS THE ADDRESS WANT TO READ
uchar readbyte (uint add)//add为读地址
{
uchar temp,temph,templ;
temph=(uchar)(add/256);
templ=(uchar)(add%256);
if(!STE)
return 0XFF;
SEN=0;
if(!STE)
{
SCL=1;
SDA=1;
SEN=1;
return 0XFF;
}
start(); //开始信号
outbyte(IIC_WRITE|(temph<<1)); //写命令
nack(1); //等待应答
outbyte(templ); //写地址
nack(1);
start(); //开始信号
outbyte(IIC_READ|(temph<<1)); //读命令
nack(1); //等待应答
temp=inbyte(); //读数据
nack(0); //无应答
stop(); //停止信号
SEN=1;
SCL=1;
SDA=1;
return(temp);
}
//=================================================
//连写函数
//add为读起始地址,ptr数据保存指针,writelen为写入数据长度
uchar writebyteseq(uint add,uchar *ptr,uint writelen)
{
//uchar temp;
uchar temph,templ;
uint i;
temph=(uchar)(add/256);
templ=(uchar)(add%256);
if(!STE)
return 0XFF;
SEN=0;
if(!STE)
{
SCL=1;
SDA=1;
SEN=1;
return 0XFF;
}
start();
outbyte(IIC_WRITE|(temph<<1));
nack(1);
outbyte(templ);
nack(1);
for(i=0;i<writelen;i++)
{
outbyte(*(ptr+i));
nack(1);
}
stop();
SCL=1;
SDA=1;
SEN=1;
return 0;
}
//=================================================
//连读函数
//add为读起始地址,ptr数据保存指针,writelen为读出数据长度
uchar readbyteseq(uint add,uchar *ptr,uint readlen)
{
xdata uchar temph,templ;
uint i;
EA=0;
temph=(uchar)(add/256);
templ=(uchar)(add%256);
if(!STE)
{
SCL=1;
SDA=1;
SEN=1;
return 0XFF;
}
SEN=0;
if(!STE)
{
SCL=1;
SDA=1;
SEN=1;
return 0XFF;
}
start();
outbyte(IIC_WRITE|(temph<<1));
nack(1);
outbyte(templ);
nack(1);
start();
outbyte(IIC_READ|(temph<<1));
nack(1);
for(i=0;i<readlen-1;i++)
{
*(ptr+i)=inbyte();
ack();
}
*(ptr+readlen-1)=inbyte();
nack(0);
stop();
SCL=1;
SDA=1;
SEN=1;
return 0;
}
//=======================================================
//THIS IS A TEST OPERATION
delay(void)
{
xdata uchar i;
for(i=0;i<100;i++)
;
}
//=======================================================
//THIS IS A TEST OPERATION
delay10ms()
{
xdata uint a,b;
for(a=0;a<200;a++)
for(b=0;b<20;b++)
;
}
xdata uchar recc[1028];
xdata uchar re_time[8];
xdata uchar set[50];
xdata uchar write_c[1024]={0,0,3,4,5,6,7,8,9,10,11};
xdata uchar read_c[1024]={0,0,3,4,5,6,7,8,9,10,11};
void display();
uchar *pp;
uchar dd=0;
uchar chan=0;
main()
{
uint i=0;
uint k=0;
uint b=0;
uchar len=0;
/*
while(1)
{
write_c[0]=i+2;
write_c[1023]=i+3;
while(writebyteseq(1024,write_c,1024));
delay10ms();
while(readbyteseq(1024,read_c,1024) );
if((read_c[0]==i+2)&&(read_c[1023]==i+3))
k++;
else
b++;
i++;
delay10ms();
if(i>100)
while(1);
}
*/
set[0]=0x62;
set[1]=0x62;
set[2]=0x62;
set[3]=0x62; //前四字节为清空指令码
set[4]=0x02;
set[5]=0xd0; //清空的列数 最大720列
set[6]=0x01;
set[7]=0xe0; //清空的行数 最大480列
set[8]=0x00;
set[9]=000; //从X 位置开始清空
set[10]=0x00;
set[11]=000; //从Y位置开始清空
set[12]=0xff; //清空后填充的颜色 0XFF 为白色
set[13]=0x02; //清空方式 0X02重新打开图象缓冲 0X01 一般清屏幕
delay10ms();
while(writebyteseq(0,set,16));
while(1)
{
set[0]=0x67;
set[1]=0x67;
set[2]=0x67;
set[3]=0x67; //前四个字节为写图象缓冲指令码
set[4]=0x00;
set[5]=24; //要写图象的宽度
set[6]=0x00;
set[7]=240; //要写图象的高度
set[8]=0x01;
set[9]=50; //图象显示在缓冲区的X 位置
set[10]=0x00;
set[11]=180; //图象显示在缓冲区的Y 位置
set[12]=0x01;
set[13]=0x00; //数据传输状态标志
delay10ms();
while(writebyteseq(0,set,18));
len=(test_y_z[0]*test_y_z[1]/(1024*(8/set[12]))+1);
do
{
delay10ms();
while(!STE);
readbyteseq(0,set,18);
}while(set[13]!=0xaa);
//不断检测状态标志位置是否有完成标志 0XAA 如果是0XAA证明MAX5399已经将指定的数据读到
if(chan==0x00)
{
chan=0xff;
pp=test_y_z;
}
else
{
chan=0;
pp=test_y_z;
}
for(i=0;i<len;i++)
{
while(!STE);
while(writebyteseq(1024,pp,1024));
set[13]=0x00; //将读取完成状态反送给MIX5399
while(writebyteseq(0,set,16));
pp=pp+1024;
do
{
while(readbyteseq(0,set,18));
}
while(set[13]!=0xaa);
}
delay10ms();
}
}
void display()
{
uchar i=0;
for (i = 0; i < 6; i++)
{ //循环显示6位数据
switch (i)
{
case 0:
P0=0Xdf;
P1=P1|0X03;
break;
case 1:
P0=0XBF;
P1=P1|0X03;
break;
case 2:
P0=0X7F;
P1=P1|0X03;
break;
case 3:
P0=0XFF;
P1=0xfe;
break;
case 4:
P0=0XFF;
P1=0XFd;
break;
case 5:
P0=0Xef;
P1=0xff;
break;
}
dis[5]=(getclk[2]>>4); //显示接收到的百位
dis[0]=(getclk[2]&0x0f); //显示接收到的十位
dis[1]=(getclk[1]>>4); //显示接收到的百位
dis[2]=(getclk[1]&0x0f); //显示接收到的十位
dis[3]=(getclk[0]>>4); //显示接收到的百位
dis[4]=(getclk[0]&0x0f); //显示接收到的十位
//dis[4]=gh%10; //显示接收到的个位
if((i==1)||(i==3))
P2=seg[dis[i]]&0xdf; //送数据到显示位
else
P2=seg[dis[i]];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -