#include <reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit scl=P2^1;
sbit sda=P2^0;
sbit P26=P2^6;
uchar count;
uchar code DSY_CODE[]={0x0c,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
void delay5us()
{ ;;}
void delayms(uint ms)
{
uchar t;
while(ms--)
for(t=0;t<120;t++);
}
void init()
{
sda=1;
delay5us();
scl=1;
delay5us();
}
void start()
{
sda=1;scl=1;delay5us();
sda=0;delay5us();scl=0;
}
void stop()
{
sda=0;scl=0;delay5us();
scl=1;delay5us();sda=1;
}
void rack()
{
sda=1;delay5us();scl=1;delay5us();scl=0;
}
void no_ack()
{
sda=1;scl=1;delay5us();
scl=0;sda=0;
}
void write_byte(uchar byte)
{
uchar i;
for(i=0;i<8;i++)
{
byte<<=1;
sda=CY;
_nop_();
scl=1;
delay5us();
scl=0;
}
rack();
}
uchar receive_byte()
{
uchar i,d;
for(i=0;i<8;i++)
{
scl=1;d<<=1;
d|=sda;
scl=0;
}
return d;
}
void write_random_address_byte(uchar add,uchar dat)
{
start();
write_byte(0xa0);
write_byte(add);
write_byte(dat);
stop();
delayms(10);
}
uchar read_current_address_data()
{
uchar dat;
start();
write_byte(0xa1);
dat=receive_byte();
no_ack();
stop();
return dat;
}
uchar random_read(uchar addr)
{
start();
write_byte(0xa0);
write_byte(addr);
stop();
return read_current_address_data();
}
void mian()
{
init();
while(1)
{
if (P26==0)
{
write_random_address_byte(0x00,1);
delayms(100);
count=random_read(0x00);
P1=DSY_CODE[count];
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
{
uchar dat;
start();
write_byte(0xa1);
dat=receive_byte();
no_ack();
stop();
return dat;
}
uchar random_read(uchar addr)
{
start();
write_byte(0xa0);
write_byte(addr);
stop();
return read_current_address_data();
}楼主能否注释一下这几句?RETURN 一个函数?
读这段程序是参考我们教材的,这儿的确错误了 谢谢你啦。
程序可否发出来参考参考?
一周热门 更多>