没断一次电,下一次启动,就记录一次
单片机源程序如下:
- #include <reg52.h>
- #include "at24c02.h"
- typedef unsigned char uchar;
- typedef unsigned int uint;
- void delay(unsigned int);
- void display();
- void keyscan();
- sbit LSA=P2^2;
- sbit LSB=P2^3;
- sbit LSC=P2^4;
- sbit K1=P3^2;
- uchar code smg[18]={0x3f,0x06,0x5b,0x4f,0x66,0x6d
- ,0x7d,0x07,0x7f,0x6f,0x77
- ,0x7c,0x39,0x5e,0x79,0x71,0x00,0x40}; //共阴
- uchar shuju[4];
- void main()
- {
- uchar num=0;
- IT0=1;
- EX0=1;
- EA=1;
- num=at24c02_read(1);
- num++;
- at24c02_wtite(1,num);
- shuju[0]=0X40;
- shuju[1]=smg[num/100];
- shuju[2]=smg[num/10%10];
- shuju[3]=smg[num%10];
- while(1)
- {
- display();
- }
- }
- void delay(unsigned int j)
- {
- while(j--);
- }
- void display()
- {
- unsigned char i;
- for(i=0;i<4;i++)
- {
- switch(i)
- {
- case 0:LSA=0;LSB=0;LSC=1;break;
- case 1:LSA=1;LSB=0;LSC=1;break;
- case 2:LSA=0;LSB=1;LSC=1;break;
- case 3:LSA=1;LSB=1;LSC=1;break;
- }
- P0=shuju[i];
- delay(100); //50000能看到流水式显示
- P0=0x00;
- }
- }
- void Int0() interrupt 0
- {
- uchar a=0,b=-1;
- delay(1000);
- if(K1==0)
- at24c02_wtite(1,b);
- }
复制代码
所有代码51hei提供下载:
EEPROM断电记录.zip
(39.34 KB, 下载次数: 36)
|