?? 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 + -