见图:
因为自己写了很多个版本的I2C,结果都是这个STOP SETUP
tiME VIOLATED,然后在网上找了一个程序发现也是这样的错误。请问各位这是什么问题如何解决?
另附上程序:
///?????:89S51
///??:12MHz
#include<reg52.h>
#include "INTRINS.H"
#define uchar unsigned char
#define uint unsigned int
sbit scl = P2^1;
sbit sda = P2^0;
/*********74H573???*********/
sbit dula = P2^7;//??
sbit wela = P2^6;//??
sbit LED = P2^5;//???
uchar tt=0;
uchar i=0,j=0,temp=0,a=0,b=0,c=0;
/*******?????_??********/
uchar code table_duan[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
/*********?????**********/
uchar code table_wei[]={0xfe,0xfd,0xfb,0xf7,0xef};
void delay1(uint x)
{
uint i,j ;
for(i=x;i--;i>0)
for(j=110;j--;j>0);
}
/**************************** ???? **************************/
void display(uchar wee,uchar H_hour,uchar L_hour,uchar H_min,uchar L_min)
{
dula=1;
P0=table_duan[wee];//???5?,??
dula=0;
wela=1;
P0=table_wei[0];
wela=0;
delay1(1);
dula=1;
P0=table_duan[H_hour];//???4?,????
dula=0;
wela=1;
P0=table_wei[1];
wela=0;
delay1(1);
dula=1;
P0=table_duan[L_hour];//???3?,????
dula=0;
wela=1;
P0=table_wei[2];
wela=0;
delay1(1);
dula=1;
P0=table_duan[H_min];//???2?,????
dula=0;
wela=1;
P0=table_wei[3];
wela=0;
delay1(1);
dula=1;
P0=table_duan[L_min];//???1?,????
dula=0;
wela=1;
P0=table_wei[4];
wela=0;
delay1(1);
}
void delay()
{ ;; }
void start() //????
{
sda=1;
delay();
scl=1;
delay();
sda=0;
delay();
}
void stop() //??
{
sda=0;
delay();
scl=1;
delay();
sda=1;
delay();
}
void respons() //??
{
uchar i;
scl=1;
delay();
while((sda==1)&&(i<250))i++;
scl=0;
delay();
}
void init()
{
sda=1;
delay();
scl=1;
delay();
}
void write_byte(uchar date)
{
uchar i,temp;
temp=date;
for(i=0;i<8;i++)
{
temp=temp<<1;
scl=0;
delay();
sda=CY;
delay();
scl=1;
delay();
// scl=0;
// delay();
}
scl=0;
delay();
sda=1;
delay();
}
uchar read_byte()
{
uchar i,k;
scl=0;
delay();
sda=1;
delay();
for(i=0;i<8;i++)
{
scl=1;
delay();
k=(k<<1)|sda;
scl=0;
delay();
}
return k;
}
void write_add(uchar address,uchar date)
{
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
write_byte(date);
respons();
stop();
}
uchar read_add(uchar address)
{
uchar date;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
date=read_byte();
stop();
return date;
}
/*-------------------------------------------------------------
???
??:?????EEPROM AT24C02???????
------------------------------------------------------------*/
void main()
{
TMOD=0x01;//?????0?????1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;//????
ET0=1;//????0??
TR0=0;//?????0
P2=P2&0xc0;
init();
for(i=0; i<255; i++)
{
write_add(i,i);
delay1(1);
}
TR0=1;
while(1)
{
if(j == 255)j=0;
TR0=0;
temp=read_add(j);
TR0=1;
a=temp/100;
b=temp%100/10;
c=temp%100%10;
display(a,b,c,0,0);
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
if(tt == 5)
{
tt = 0;
LED = ~LED;//??????????
j++;
}
}
-
-
一周热门 更多>