21ic问答首页 - 为什么数码管显示小时的有一位不亮
为什么数码管显示小时的有一位不亮 赏100家园币
wl200309082023-10-18
#include "stc15.h"
#include "intrins.h"
#include "ds1302.h"
unsigned char code write[7]={0x80,0x82,0x84,0x86,0x88,0x8A,0x8C} ;
unsigned char code read[7]={0x81,0x83,0x85,0x87,0x89,0x8B,0x8D};
unsigned char nowtime[7]={0x00,0x07,0x17,0x12,0x10,0x04,0x23};
unsigned char time[8];
unsigned char code SMG_NoDot[18] =
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,
0xbf,0x7f};
void selevcehc573(unsigned char channel)
{
switch(channel)
{
case 4:
P2=(P2&0x1f)|0x80;
break;
case 5:
P2=(P2&0x1f)|0xa0;
break;
case 6:
P2=(P2&0x1f)|0xc0;
break;
case 7:
P2=(P2&0x1f)|0xe0;
break;
}
}
void Timer0_Init(void) //1毫秒@12.000MHz
{
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x18; //设置定时初始值
TH0 = 0xFC; //设置定时初始值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0 = 1; //使能定时器0中断
EA=1;
}
void writeds1302()
{
unsigned char i;
Write_Ds1302_Byte(0x8e,0x00);
for(i=0;i<8;i++)
{
Write_Ds1302_Byte(write,nowtime);
}
Write_Ds1302_Byte(0x8e,0x80);
}
void readds1302()
{
unsigned char i;
for(i=0;i<8;i++)
{
nowtime=Read_Ds1302_Byte( read)/16*10+ Read_Ds1302_Byte(read)%16;
}
}
void smg()
{
static char i;
selevcehc573(6);
P0=0x01<<i;
selevcehc573(7);
P0=SMG_NoDot[ time];
i=(i+1)%8;
}
void smg1()
{
time[0]=nowtime[2]/10;
time[1]=nowtime[2]%10;
time[2]=16;
time[3]=nowtime[1]/10;
time[4]=nowtime[1]%10;
time[5]=16;
time[6]=nowtime[0]/10;
time[7]=nowtime[0]%10;
}
void main()
{
Timer0_Init();
writeds1302();
while(1)
{
readds1302();
}
}
void Timer0_Isr(void) interrupt 1
{
static int g;
g++;
smg();
smg1();
}
#include "intrins.h"
#include "ds1302.h"
unsigned char code write[7]={0x80,0x82,0x84,0x86,0x88,0x8A,0x8C} ;
unsigned char code read[7]={0x81,0x83,0x85,0x87,0x89,0x8B,0x8D};
unsigned char nowtime[7]={0x00,0x07,0x17,0x12,0x10,0x04,0x23};
unsigned char time[8];
unsigned char code SMG_NoDot[18] =
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,
0xbf,0x7f};
void selevcehc573(unsigned char channel)
{
switch(channel)
{
case 4:
P2=(P2&0x1f)|0x80;
break;
case 5:
P2=(P2&0x1f)|0xa0;
break;
case 6:
P2=(P2&0x1f)|0xc0;
break;
case 7:
P2=(P2&0x1f)|0xe0;
break;
}
}
void Timer0_Init(void) //1毫秒@12.000MHz
{
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x18; //设置定时初始值
TH0 = 0xFC; //设置定时初始值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0 = 1; //使能定时器0中断
EA=1;
}
void writeds1302()
{
unsigned char i;
Write_Ds1302_Byte(0x8e,0x00);
for(i=0;i<8;i++)
{
Write_Ds1302_Byte(write,nowtime);
}
Write_Ds1302_Byte(0x8e,0x80);
}
void readds1302()
{
unsigned char i;
for(i=0;i<8;i++)
{
nowtime=Read_Ds1302_Byte( read)/16*10+ Read_Ds1302_Byte(read)%16;
}
}
void smg()
{
static char i;
selevcehc573(6);
P0=0x01<<i;
selevcehc573(7);
P0=SMG_NoDot[ time];
i=(i+1)%8;
}
void smg1()
{
time[0]=nowtime[2]/10;
time[1]=nowtime[2]%10;
time[2]=16;
time[3]=nowtime[1]/10;
time[4]=nowtime[1]%10;
time[5]=16;
time[6]=nowtime[0]/10;
time[7]=nowtime[0]%10;
}
void main()
{
Timer0_Init();
writeds1302();
while(1)
{
readds1302();
}
}
void Timer0_Isr(void) interrupt 1
{
static int g;
g++;
smg();
smg1();
}
赞0
评论
2023-10-20
赞0
评论
2023-10-19
赞0
评论
2023-10-19
赞0
评论
2023-10-19
您需要登录后才可以回复 登录 | 注册