📄 iicok.c
字号:
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;
/*
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]=0x68; //清空后填充的颜色 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]=80; //要写图象的宽度
set[6]=0x00;
set[7]=80; //要写图象的高度
set[8]=0x00;
set[9]=100; //图象显示在缓冲区的X 位置
set[10]=0x00;
set[11]=100; //图象显示在缓冲区的Y 位置
set[12]=0x04;
set[13]=0x00; //数据传输状态标志
delay10ms();
while(writebyteseq(0,set,18));
//格式 四字节指令码+四字节起始地址+1字节保留空字节+1字节读取标志字节
do
{
delay10ms();
while(!STE);
readbyteseq(0,set,18);
}while(set[13]!=0xaa); //不断检测状态标志位置是否有完成标志 0XAA 如果是0XAA证明MAX5399已经将指定的数据读到
pp=test_y_w;
for(i=0;i<(test_y_w[0]*test_y_w[1]/(1024*2)+1);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 + -