实验4 IIC通讯与EEPROM接口

2019-07-14 03:33发布

1.       C语言编程,利用定时器产生一个0~99秒变化的秒表,并且显示在数码管上,每过一秒将这个变化写入实验板上AT24C02,当关闭实验板电源,并再次打开实验板电源时,单片机从AT24C02中将原来写入的数据读出来,接着继续变化在数码管上。

  #include #define uchar unsigned char #define uint unsigned int   //=========全局变量区============================================ bit  write=0;           //24C02的标志; sbit sda=P2^0;                         sbit scl=P2^1; sbit high=P2^4; sbit mid=P2^3; sbit low=P2^2; uint code NumTable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//数字的编码   uchar sec,tcnt; uchar code table[]={     0x3f,0x06,0x5b,0x4f,     0x66,0x6d,0x7d,0x07,     0x7f,0x6f,0x77,0x7c,     0x39,0x5e,0x79,0x71     }; //=========全局变量区结束============================================ /** 步骤 接线方式: 1P0接数码管J12,实现段选 2、译码器和数码管位选输入短接,J15+J16 3、本实验使用的晶振是12.000 **/   //========函数区============================================ void delay() {;;} void delay1ms(uint z) {     uint x,y;     for(x=z;x>0;x--)        for(y=110;y>0;y--); } /**     延时 **/ void delay_1ms(uint x){     uint i=x;     uint j;     for(;i>0;--i){        for(j=110;j>0;--j);     } } /**     在数码管上显示对应的值 **/ void display(uchar Num) {     P0=NumTable[Num];     delay_1ms(1);     P0=0;      //送完段选信号后,进行消影的处理 }   /**     控制数码管显示后3位,并分解计数值 **/ void DisplayNumByOrder(uint Value){        low=0; mid=0; high=0;  display(0