打印

为什么数码管显示小时的有一位不亮

[复制链接]
9562|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wl20030908|  楼主 | 2023-10-18 19:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#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();
}

使用特权

评论回复

相关帖子

沙发
Unarty| | 2023-10-19 11:59 | 只看该作者

为什么数码管显示小时的有一位不亮

Write_Ds1302_Byte(write,nowtime); 这里是不是要有偏移? Write_Ds1302_Byte(write,nowtime);

使用特权

评论回复
板凳
Unarty| | 2023-10-19 12:00 | 只看该作者

为什么数码管显示小时的有一位不亮

Write_Ds1302_Byte(write,nowtime);

使用特权

评论回复
地板
Unarty| | 2023-10-19 12:01 | 只看该作者

为什么数码管显示小时的有一位不亮

发现在是21IC平台的问题

使用特权

评论回复
5
一叶倾城wwq| | 2023-10-20 11:09 | 只看该作者
先一位一位的点亮看看

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

5

帖子

0

粉丝