- <p>
- /* 24c02.h*/
- sbit SCL = P2^0;
- sbit SDA = P2^1;
- char write = 0;
- /****************延迟函数***************/
- void delay()
- {;;}
- /*************初始化函数**************/
- void init()
- {
- SCL = 1;
- SDA = 1;
- }
- /***************起始信号**************/
- void start()
- {
- SDA = 1;
- delay();
- SCL = 1;
- delay();
- SDA = 0;
- delay();
- }
- /***************终止信号***************/
- void stop()
- {
- SDA = 0;
- delay();
- SCL = 1;
- delay();
- SDA = 1;
- delay();
- }
- /****************应答信号**************/
- void response()
- {
- int i;
- SCL = 1;
- delay();
- while( (SDA = 1)&&( i < 200 )) i++;
- SCL = 0;
- delay();
- }
- /*****************写一个字节***********/
- void write_byte( char date)
- {
- char i,temp;
- temp = date;
- for( i = 0; i < 8; i++)
- {
- temp = temp << 1;
- SCL = 0;
- delay();
- SDA = CY;
- delay();
- SCL = 1;
- delay();
- }
- SDA = 1;
- delay();
- }
- /***************读取一个字节**********/
- char read_byte()
- {
- char i,k;
- SCL = 0;
- delay();
- SDA = 1; //总线释放
- delay();
- for ( i = 0; i < 8; i++ )
- {
- SCL = 1;
- delay();
- k = (k<<1)|SDA;
- SCL = 0;
- delay();
- }
- SDA = 1;
- delay();
- return k;
- }
- /******************24c02 数据的写************/
- void write_add(unsigned char add, unsigned char date)
- {
- start();
- write_byte(0xa0);
- response();
- write_byte(add);
- response();
- write_byte(date);
- response();
- stop();
- }
- /*******************24c02 数据的读***********/
- unsigned char read_add(char add)
- {
- char date;
- start();
- write_byte(0xa0);
- response();
- write_byte(add);
- response();
- start();
- write_byte(0xa1);
- response();
- date = read_byte();
- stop();
- return date;
- }
- /*24c02.h end*/
- /**********************24c02读写函数*********************/
- #include<reg52.h>
- #include<intrins.h>
- #include"24c02.h"</p><p>void delay1(int x);
- unsigned char code DX[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
- unsigned char code WX[2]={0xfe,0xfd};
- int num,num1,i;
- char LD[2];</p><p>void main()
- {
- init();
- num = read_add(2);
- TMOD = 0x10;
- TH0 = (65536 - 50000)/256;
- TL0 = (65536 - 50000)%256;</p><p> ET1 = 1;
- EA = 1;
- TR1 = 1;
- while(1)
- {
-
- if(write == 1)
- {
- write_add(2,num);
- }</p><p>
-
- LD[0] = DX[num%100/10];
- LD[1] = DX[num%10];
-
- for(i = 0;i < 2; i++)
- {
- P0 = LD[i];
- P1 = WX[i];
- delay1(5);
- } </p><p> }
- }</p><p>
- time() interrupt 3
- {
- TH1 = (65536 - 50000)/256;
- TL1 = (65536 - 50000)%256;
- num1++;
- if( num1 == 20 )
- {
- num1 = 0;
- num++;
- write = 1;
-
- }
- }</p><p>void delay1(int x)
- {
- int i,j;
- for( i = x; i > 0; i--)
- for(j = 200; j > 0; j--);
- }</p><p>
- 程序的功能是 在数码管上显示0~99的数字 从24c02中读取数据 每次关闭电源后 打开电源数码管显示的数值接着之前关闭前的数据。。。。。。。
- 为什么次程序不能写入数据? 只能读取初始的 24c02的值 每次重新打开电源都是读取24c02 的值(55)?</p>
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
亲 求指点
写不进去无非就是写时序的问题。自己的程序肯定自己要好好看。
建议好好看看手册。
老鸟们都很忙,新鸟们又不会,所以LZ还是要靠自己。
是我态度不好么???
一周热门 更多>