单片机数字时钟1302数码管显示程序
#include<REGX52.H>#defineuintunsignedint#defineucharunsignedcharunsignedlongintsecond...
#include <REGX52.H>
#define uint unsigned int
#define uchar unsigned char
unsigned long int second;
uchar date,sec,pSecDa;
uchar gettime[7];
uchar ucCurtime[];
sbit T_CLK=P2^1;
sbit T_IO=P2^0;
sbit T_RST=P2^5;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
void inputbyte(uchar date);
void delay(uint z);
uchar Outbyte();
void DS1302_W1302(uchar ucaddr,date);
uchar DS1302_R1302(uchar ucaddr);
void DS1302_set1302(uchar *pSecDa);
uchar DS1302_get1302(uchar ucCurtime[]);
void display(uchar *ucCurtime);
void main()
{
//DS1302_set1302(pSecDa);
while(1)
{wela=1;
P0=0x24;
wela=0;
//delay(1);
dula=1;
P0=0xbf;
dula=0;
//delay(1);
DS1302_get1302(ucCurtime);
display(ucCurtime);
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void inputbyte(uchar date)
{
uchar i,temp;
temp=date;
T_CLK=0;
for(i=8;i>0;i--)
{
T_IO=temp&0x01;
T_CLK=1;
delay(1);
T_CLK=0;
delay(1);
temp=temp>>1;
}
}
uchar Outbyte()
{
uchar i,temp;
temp=0x00;
for(i=8;i>0;i--)
{
T_CLK=0;
if(T_IO!=0) temp|=(1<<i);
T_CLK=1;
}
return(temp);
}
void DS1302_W1302(uchar ucaddr,date)
{
T_RST=0;
T_CLK=0;
T_RST=1;
inputbyte(ucaddr);
inputbyte(date);
T_CLK=1;
T_RST=0;
}
uchar DS1302_R1302(uchar ucaddr)
{
uchar date;
T_RST=0;
T_CLK=0;
T_RST=1;
inputbyte(ucaddr);
date=Outbyte();
T_CLK=1;
T_RST=0;
return(date);
}void DS1302_set1302(uchar *pSecDa)
{
uchar i;
uchar ucaddr=0x80;
DS1302_W1302(0x8e,0x00); //写操作
for(i=7;i>0;i++)
{
DS1302_W1302(ucaddr,*pSecDa);
ucaddr+=2;
pSecDa++;
}
DS1302_W1302(0x8e,0x80);
}
uchar DS1302_get1302(uchar ucCurtime[])
{
uchar i,j;
uchar addr=0x81;
for(i=0;i<7;i++)
{
ucCurtime[i]=DS1302_R1302(addr);
sec=ucCurtime[i];
j=sec>>4;
j*=10;
sec=sec&0x0f;
sec+=j;
ucCurtime[i]=sec; /
addr+=2;
}
}
void display(uchar *ucCurtime)
{
dula=0;
wela=1;
P0=0x80;
wela=0;
dula=1;
P0=table[ucCurtime[0]%10];
dula=0;
delay(1);
P0=0xff;
dula=0;
wela=1;
P0=0x40;
wela=0;
dula=1;
P0=table[ucCurtime[0]/10];
dula=0;
delay(1);
P0=0xff;
dula=0;
wela=1;
P0=0x10;
wela=0;
dula=1;
P0=table[ucCurtime[1]%10];
dula=0;
delay(1);
P0=0xff;
dula=0;
wela=1;
P0=0x08;
wela=0;
dula=1;
P0=table[ucCurtime[1]/10];
dula=0;
delay(1);
P0=0xff;
dula=0;
wela=1;
P0=0x02;
wela=0;
dula=1;
P0=table[ucCurtime[2]%10];
dula=0;
delay(1);
P0=0xff;
dula=0;
wela=1;
P0=0x01;
wela=0;
dula=1;
P0=table[ucCurtime[2]/10];
dula=0;
delay(1);
P0=0xff;
}
请大侠看看有什么错误,数码管光闪不出结果,自己编的纠结死了。 展开
#define uint unsigned int
#define uchar unsigned char
unsigned long int second;
uchar date,sec,pSecDa;
uchar gettime[7];
uchar ucCurtime[];
sbit T_CLK=P2^1;
sbit T_IO=P2^0;
sbit T_RST=P2^5;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
void inputbyte(uchar date);
void delay(uint z);
uchar Outbyte();
void DS1302_W1302(uchar ucaddr,date);
uchar DS1302_R1302(uchar ucaddr);
void DS1302_set1302(uchar *pSecDa);
uchar DS1302_get1302(uchar ucCurtime[]);
void display(uchar *ucCurtime);
void main()
{
//DS1302_set1302(pSecDa);
while(1)
{wela=1;
P0=0x24;
wela=0;
//delay(1);
dula=1;
P0=0xbf;
dula=0;
//delay(1);
DS1302_get1302(ucCurtime);
display(ucCurtime);
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void inputbyte(uchar date)
{
uchar i,temp;
temp=date;
T_CLK=0;
for(i=8;i>0;i--)
{
T_IO=temp&0x01;
T_CLK=1;
delay(1);
T_CLK=0;
delay(1);
temp=temp>>1;
}
}
uchar Outbyte()
{
uchar i,temp;
temp=0x00;
for(i=8;i>0;i--)
{
T_CLK=0;
if(T_IO!=0) temp|=(1<<i);
T_CLK=1;
}
return(temp);
}
void DS1302_W1302(uchar ucaddr,date)
{
T_RST=0;
T_CLK=0;
T_RST=1;
inputbyte(ucaddr);
inputbyte(date);
T_CLK=1;
T_RST=0;
}
uchar DS1302_R1302(uchar ucaddr)
{
uchar date;
T_RST=0;
T_CLK=0;
T_RST=1;
inputbyte(ucaddr);
date=Outbyte();
T_CLK=1;
T_RST=0;
return(date);
}void DS1302_set1302(uchar *pSecDa)
{
uchar i;
uchar ucaddr=0x80;
DS1302_W1302(0x8e,0x00); //写操作
for(i=7;i>0;i++)
{
DS1302_W1302(ucaddr,*pSecDa);
ucaddr+=2;
pSecDa++;
}
DS1302_W1302(0x8e,0x80);
}
uchar DS1302_get1302(uchar ucCurtime[])
{
uchar i,j;
uchar addr=0x81;
for(i=0;i<7;i++)
{
ucCurtime[i]=DS1302_R1302(addr);
sec=ucCurtime[i];
j=sec>>4;
j*=10;
sec=sec&0x0f;
sec+=j;
ucCurtime[i]=sec; /
addr+=2;
}
}
void display(uchar *ucCurtime)
{
dula=0;
wela=1;
P0=0x80;
wela=0;
dula=1;
P0=table[ucCurtime[0]%10];
dula=0;
delay(1);
P0=0xff;
dula=0;
wela=1;
P0=0x40;
wela=0;
dula=1;
P0=table[ucCurtime[0]/10];
dula=0;
delay(1);
P0=0xff;
dula=0;
wela=1;
P0=0x10;
wela=0;
dula=1;
P0=table[ucCurtime[1]%10];
dula=0;
delay(1);
P0=0xff;
dula=0;
wela=1;
P0=0x08;
wela=0;
dula=1;
P0=table[ucCurtime[1]/10];
dula=0;
delay(1);
P0=0xff;
dula=0;
wela=1;
P0=0x02;
wela=0;
dula=1;
P0=table[ucCurtime[2]%10];
dula=0;
delay(1);
P0=0xff;
dula=0;
wela=1;
P0=0x01;
wela=0;
dula=1;
P0=table[ucCurtime[2]/10];
dula=0;
delay(1);
P0=0xff;
}
请大侠看看有什么错误,数码管光闪不出结果,自己编的纠结死了。 展开
3个回答
深圳市兴威帆电子技术有限公司
2023-08-24 广告
2023-08-24 广告
作为深圳市兴威帆电子技术有限公司的工作人员,我建议选择实时时钟模块时,可以考虑以下几个因素:1. 精度和稳定性:实时时钟模块需要保持高精度和稳定性,以确保系统时间的准确性。2. 兼容性:需要确保实时时钟模块与您的硬件平台和操作系统兼容。3....
点击进入详情页
本回答由深圳市兴威帆电子技术有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询