|
#include<reg51.h>
#include"intrins.h" // _nop_();
#define uint unsigned int
#define uchar unsigned char
sbit scl=P2^1;
sbit sda=P2^0;
bit write=0;
uint num,num1;
uchar ge,shi;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay_ms(uint Z)
{
uint x,y;
for(x=Z;x>0;x--)
for(y=110;y>0;y--);
}
/*****ÅäÖÃIICD¾Æ¬**********/
void delay()
{
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
}
void start()//¿aê¼
{
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();
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;
}
/************êyÂë1üÏÔê¾oˉêy*********************/
void display(uchar shi,uchar ge)
{
P1=0xdf;
P0=table[shi];
delay_ms(5);
P1=0xef;
P0=table[ge];
delay_ms(5);
}
/*********Ö÷oˉêy************************/
void main()
{
init();
num1=read_add(2);
if(num1>100)
num1=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
EA=1;
TR0=1;
while(1)
{
display(num1/10,num1%10);
if(write==1)
{
write=0;
write_add(2,num1);
}
}
}
/*******ÖD¶Ïoˉêy*****************************/
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
if(num==20)
{
num=0;
num1++;
write=1;
if(num1==100)
num1=0;
}
}
|
评分
-
查看全部评分
|