ds3231可以用ds3232代替吗

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ds3231可以用ds3232代替吗相关的知识,希望对你有一定的参考价值。

参考技术A 可以替换,如果反过来,用3232替换3231,则需要看有没有使用SRAM。如果使用了SRAM,就不能代替,如果没有使用,可以代替 参考技术B 可以

单片机+ds1302+仿真程序 用三个按键调时间

51单片机对DS1302的仿真 用三个按键调时间

  • ds1302芯片

  • 1602液晶

  • AT89C51主控

  • 仿真效果
    在这里插入图片描述

  • 程序代码

#include <REGX52.H>
#define uchar unsigned char
#define uint unsigned int
#define data8 P0
sbit rst=P1^0;
sbit sck=P1^1;
sbit sda=P1^2;
sbit rs=P1^3;
sbit rw=P1^4;
sbit e=P1^5;
sbit key1=P2^0;
sbit key2=P2^1;
sbit key3=P2^2;
sbit start= P2^3;
sbit ale=P1^6;
sbit eoc=P1^7;
sbit oe=P2^4;
uchar table1[]="TIME:";
uchar table2[]="DATE:";
uchar table[]="0123456789:-";
uchar code chuzhi[]={0x80,0x34,0x18,0x15,0x04,0x04,0x21,0x00};
uchar code dizhi[]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c,0x80};
uchar code chushi1602[]={0x38,0x0c,0x01};
uchar chuncu[7]={0};
uchar song,temp1,adc;
void delayms(uint xms)
{
	uchar i;uint j;
	for(j=xms;j>0;j--)
		for(i=110;i>0;i--);
}
void ad();
void t0()
{
    TMOD = 0x01;
    TH0 = 0x0FE;
    TL0 = 0x0C;
    EA = 1;
    ET0 = 1;
    TR0 = 1;
}
void zl1602(uchar zlduan)
{
	rs=0;
	rw=0;
	data8=zlduan;
	delayms(1);
	e=1;
	delayms(5);
	e=0;

}  
void sj1602(uchar sjduan)
{
	rs=1;
	rw=0;
	data8=table[sjduan];
	delayms(1);
	e=1;
	delayms(5);
	e=0;

}
void sc1602(uchar sjduan)
{
	rs=1;
	rw=0;
	data8=sjduan;
	delayms(1);
	e=1;
	delayms(5);
	e=0;
}
void cs1602()
{
	uchar i;
	for(i=0;i<3;i++)
	{
		zl1602(chushi1602[i]);	
	}
}


void cs1302()
{
	rst=0;
	sck=0;
	rst=1;
}
void xie1302(uchar temp) //1000 0000 
{
	uchar i;
	for(i=8;i>0;i--)
	{
		sda=temp&0x01;   //0
		sck=0;
		sck=1;
		temp>>=1;	   //0100 0000
	}
}
uchar song1302()
{
	uchar i;
	for(i=0;i<8;i++)
	{
		
		if(sda)
		{
			song|=0x80;
		}
			sck=1;
			sck=0;
		 	song>>=1;
	}
		return(song);
}

void r1302(uchar radd,uchar rdata)
{
	
	cs1302();
	delayms(1);
	rst=1;
	xie1302(radd);
	xie1302(rdata);
	rst=0;
}

void w1302(uchar add)
{
	cs1302();
	delayms(1);
	rst=1;
	xie1302(add);
	temp1=song1302();
	rst=0;
	sck=0;
}
void chushi()
{
	uchar i;
	for(i=0;i<8;i++)
	{
		r1302(dizhi[i],chuzhi[i]);
	}
}

uchar zhuanhuan()
{
	uchar i,dat=0x81;
	for(i=0;i<7;i++)
	{
		w1302(dat);
		chuncu[i]=song;
		dat+=2;	
	}
	return(chuncu);

}

void xianshi()
{
uchar i;
for(i=0;i<5;i++)
{
	zl1602(0x80+i);
	sc1602(table1[i]);
	delayms(2);
	zl1602(0x80+i+0X40);
	sc1602(table2[i]);
	delayms(2);
}
	zl1602(0x8C);
	sj1602(chuncu[0]&0x0f);
	delayms(2);
	zl1602(0x8B);
	sj1602(chuncu[0]>>4);
	delayms(2);

	zl1602(0x89);
	sj1602(chuncu[1]&0x0f);
	delayms(2);
	zl1602(0x88);
	sj1602(chuncu[1]>>4);
	delayms(2);

	zl1602(0x86);
	sj1602(chuncu[2]&0x0f);
	delayms(2);
	zl1602(0x85);
	sj1602(chuncu[2]>>4);
	delayms(2);

	zl1602(0x8e+0x40);
	sj1602(chuncu[3]&0x0f);
	delayms(2);
	zl1602(0x8d+0x40);
	sj1602(chuncu[3]>>4);
	delayms(2);	 

	zl1602(0x8b+0X40);
	sj1602(chuncu[4]&0x0f);
	delayms(2);
	zl1602(0x8a+0x40);
	sj1602(chuncu[4]>>4);
	delayms(2);	 
	zl1602(0x8f);
	sj1602(chuncu[5]);
	delayms(2);	

	zl1602(0x88+0X40);
	sj1602(chuncu[6]&0x0f);
	delayms(2);
	zl1602(0x87+0X40);
	sj1602(chuncu[6]>>4);

	delayms(2);	
	zl1602(0x86+0X40);
	sj1602(0);
	delayms(2);
	zl1602(0x85+0X40);
	sj1602(2);
	delayms(2);	

	zl1602(0x87);
	sj1602(10);
	delayms(2);	
	zl1602(0x8a);
	sj1602(10);
	delayms(2);	
	zl1602(0x89+0X40);
	sj1602(11);
	delayms(2);
	zl1602(0x8c+0X40);
	sj1602(11);
	delayms(2);	
}
void anjian()
{
	uchar temp,mun,mun1,mun2;
	if(key1==0)
	{
		delayms(10);
		if(key1==0)
		{
			temp++;

		}	
	}
	while(!key1);


	if(temp<=7)
	{

		switch(temp)
		{
	case 1:
			if(key2==0)
			{
				delayms(10);
				if(key2==0)
				{
					mun=chuncu[1];
					mun++;
					mun1=chuncu[1]&0x0f;
				if(mun1>=0x09)
				{
					mun=mun&0xf0;
					mun=mun+0x10;
				}

					r1302(0x82,mun);

				}	
			}

				if(key3==0)
			{
				delayms(10);
				if(key3==0)
				{
					mun=chuncu[1];
					mun--;
				mun1=chuncu[1]&0x0f;
				if(mun1<=0x00)
				{
					mun=mun&0xf0+9;	         //退位是15 直接清零+9
				}
					r1302(0x82,mun);
				}	
				mun2=chuncu[1]&0xf0;
				if(mun2>=0x59)
				{
					r1302(0x82,0x00);
				}
			}	break;	



	case 2:
			if(key2==0)
			{
				delayms(10);
				if(key2==0)
				{
					mun=chuncu[2];
					mun++;
					mun1=chuncu[2]&0x0f;
				if(mun1>=0x09)
				{
					mun=mun&0xf0;
					mun=mun+0x10;
				}
					r1302(0x84,mun);
				}	
			}
				if(key3==0)
			{
				delayms(10);
				if(key3==0)
				{
					mun=chuncu[2];
					mun--;
					mun1=chuncu[1]&0x0f;
				if(mun1<0x01)
				{
					mun=mun&0xf0+9;	         //退位是15 直接清零+9
				}
					r1302(0x84,mun);
				}
	
			} break;

	case 3:
			if(key2==0)
			{
				delayms(10);
				if(key2==0)
				{
					mun=chuncu[5];
					mun++;
					r1302(0x8a,mun);
				}	
			}
				if(key3==0)
			{
				delayms(10);
				if(key3==0)
				{
					mun=chuncu[5];
					mun--;
					mun1=chuncu[1]&0x0f;
				if(mun1<=0x00)
				{
					mun=mun&0xf0+9;	         //退位是15 直接清零+9
				}
					r1302(0x8a,mun);
				}
			}  break;

	case 4:
			if(key2==0)
			{
				delayms(10);
				if(key2==0)
				{
					mun=chuncu[3];
					mun++;
				mun1=chuncu[3]&0x0f;
				if(mun1>=0x09)
				{
					mun=mun&0xf0;
					mun=mun+0x10;
				}
					r1302(0x86,mun);
				}
				if(mun&0x0f==0x0a)
				{
					mun +=0x10;
				}	
			}
				if(key3==0)
			{
				delayms(10);
				if(key3==0)
				{
					mun=chuncu[3];
					mun--;
					mun1=chuncu[1]&0x0f;
				if(mun1<=0x00)
				{
					mun=mun&0xf0+9;	         //退位是15 直接清零+9
				}
					r1302(0x86,mun);
				}	
			} break; 

	case 5:
			if(key2==0)
			{
				delayms(10);
				if(key2==0)
				{
					mun=chuncu[4];
					mun++;
				mun1=chuncu[4]&0x0f;
				if(mun1>=0x09)
				{
					mun=mun&0xf0;
					mun=mun+0x10;
				}
					r1302(0x88,mun);
				}	
			}
				if(key3==0)
			{
				delayms(10);
				if(key3==0)
				{
					mun=chuncu[4];
					mun--;
					mun1=chuncu[1]&0x0f;
				if(mun1<=0x00)
				{
					mun=mun玩转 RTC时钟库   DS3231

求TM1637数显+STC89RC+DS3231组成的一款数码电子时钟.

DS12C887,DS1302,DS3231时钟芯片那个精度比较高?

DS12C887与DS3231哪个时间运行得更准确?

DS12C887,DS1302,DS3231时钟芯片哪个精度比较高

基于STM8的IIC协议--实例篇--时钟模块(DS3231)读取