void xianshi()
{
uchar i,j;
xs(tempdata[1],4,4);
xs(tempdata[0],6,6);
for(i = 0;i<8;i++)
{
w_shuzi(i,0,table1[i]);
j = 8+i;
w_shuzi(i,0,table1[j]);
}
}
void w_shuzi(uchar x,uchar y,uchar zz)
{
uchar i,z;
z = zz;
LCD_add(x*6,y);
for(i = 0;i<6;i++)
LCD_write_dat(shuzi[z*12+i]);
LCD_add(x*6,y+1);
for(i = 6;i<12;i++)
LCD_write_dat(shuzi[z*12+i]);
}
当这个函数进行传递时 w_shuzi(i,0,table1[i]); 是正常如i=0;table1[0] = 0;zz = 0x00;
但当w_shuzi(i,0,table1[j]);确不能正常传递函数。i = 0j=8;table1[8] = 0;zz = 0xff;
这是什么原因?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
table1[16]是在另外一个c文件定义的
#include<reg52.h>
#include<intrins.h>
#include"ds1624r.h"
uchar table1[16],count;
uchar tempdata[2];
extern h_tem,l_tem;
sbit SDA = P1^6;
sbit SCL = P1^5;
void init()
{
SCL=1;
delay();
SDA=1;
delay();
/*SCL=0;
delay();
i_stop();*/
}
void delay(void)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
void i_start(void) // iic开始传输
{
SDA=1;
delay();
SCL=1;
delay();
SDA=0;
delay();
SCL=0;
delay();
}
void i_send(uchar i_com)
{
uchar i;
for(i=0;i<8;i++)
{
SDA=(i_com&0x80);
i_com=i_com<<1 ;
SCL=1;
delay();
SCL=0;
delay();
}
SDA=1;
SCL=1;
}
void i_stop(void) // iic停止传输
{
SDA=0;
delay();
SCL=1;
delay();
SDA=1;
delay();
SCL=0;
delay();
}
void start_temp()
{
i_start();
delay();
i_send(0x90);
ack();
i_send(0xee);
ack();
i_stop();
}
void respons()
{
SDA=0;
SCL=1;
delay();
SCL=0;
delay();
SDA=1;
delay();
SCL=1; //
delay(); //
}
void read_temp()
{
i_start();
i_send(0x90);
ack();
i_send(0xaa);
ack();
i_start();
i_send(0x91);
ack();
count = 0;
tempdata[1]=receive_temp();
respons();
count = 8;
tempdata[0]=receive_temp();
i_stop();
}
uchar receive_temp()
{
bit sample=0;
uchar i_data=0;
uchar i;
for(i=0;i<8;i++)
{
SCL=1;
delay();
sample=SDA;
_nop_();
_nop_();
_nop_();
SCL=0;
delay();
table1[count++]=sample;
i_data*=2;
if(sample==1) i_data++;
delay();
}
return(i_data) ;
}
void ack()
{
uchar x=0;
SCL=1;
delay();
while((SDA==1)&&(x<50))x++;
SCL=0;
delay();
}
一周热门 更多>