下面是程序
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit LE1=P2^0;
sbit LE2=P2^1;
sbit scl=P2^6;
sbit sda=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x0d,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay() //延时函数
{;;}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void init() //总线初始化
{
sda=1;
scl=1;
}
void start () //启动信号
{
sda=1;
delay();
scl=1;
delay();
sda=0;
delay();
}
void respons() //应答信号
{
sda=1;
delay();
scl=1;
delay();
sda=0;
delay();
}
void stop() //停止信号
{
sda=0;
delay();
scl=1;
delay();
sda=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();
sda=1;
delay();
}
uchar read_byte() //读数据
{
uchar i,k;
scl=0;
delay();
sda=1;
for(i=0;i<8;i++)
{
scl=1;
delay();
k=(k<<1)|sda;
scl=0;
delay();
}
delay();
return k;
}
void main()
{
uint z,a;
LE1=1;
P0=0x0;
LE1=0;
delayms(1000);
for(z=0;z<16;z++)
{
init();
LE2=1;
start();
write_byte(0xa0);
respons();
write_byte(4);
respons();
write_byte(table[z]);
respons();
stop();
delayms(100);
start();
write_byte(0xa0);
respons();
write_byte(4);
respons();
start();
write_byte(0xa1);
respons();
a=read_byte();
stop();
P0=a;
LE2=0;
delayms(1000);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
我不太了解,你知道我这程序哪里不妥吗?
一周热门 更多>