打印

关于ds1302的问题请教!并祝大家国庆快乐!

[复制链接]
2900|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
昂首向前|  楼主 | 2007-10-4 18:34 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
ov, se, AD, vr, RS
现在情况是通电后就显示乱码而且有时候重新通电后显示的不一样,硬件图如下:
但有几点需说明下 
1、电容是选择了5PF,因手头上没有6PF电容,有些资料上好象都没接
2、上拉电阻是用4.7K,也是因为现手头上无10K的,有些资料上好象都没接
3、晶振的3脚电压为2.4V,2脚电压为0V,由于没有示波器,所以不能量频率,也就不能判断电路是否起振

软件程序如下:
且做几点补充说明
1、对控制字(写保护控制字)8EH写入了00H;
2、对秒寄存器80H写入了00H;


显示电路,程序是正常的, 测试过,显示是4位一体数码管,中间两点0.5S闪烁一次,现在我不能判断DS1302是否起振,所以也不知道是程序的问题还是硬件的问题,还请各位指点!
 SCLK  BIT P3.2;
                     IO    BIT P3.3;
                     RST   BIT P3.4;
                     HOUR  EQU 62H;
                     MIN   EQU 61H;
                  SECOND  EQU 60H;
            DS1302_ADDR EQU 31H;
             DS1302_DATA EQU 32H;
                     ORG 0000H;
                LJMP START;跳转到标号START处执行
                ORG 0003H;
                RETI     ;
                ORG 000BH;定时器T0中断程序入口
                LJMP INTT0;跳转到T0中断服务程序
                ORG 0013H;
                RETI     ;
                ORG 001BH;定时器T1中断程序入口
                LJMP INTT1;跳转到T1中断服务程序
                ORG 0023H;串行中断入口程序
                RETI     ;
;\\\\\\\\\\\\\\\\\\\\\\\\               ;主程序    
;\\\\\\\\\\\\\\\\\\\\\\\\      START:     MOV P1,#0FFH;
                 MOV SCON,#00H;
                 MOV TMOD,#011H;工作方式1
                 MOV TL0,#0B0H;T0计数用,50MS定时初值,用于秒点闪烁定时
                MOV TH0,#3CH; 
                 MOV TL1,#0B0H; T1闪烁用,50MS定时初值,用于闪烁定时
                MOV TH1,#3CH;
                     SETB EA ;
                     SETB ET0;
                     SETB TR0;
                     MOV R3,#0AH;
                     SETB 00H;清秒点闪烁标志位
                     SETB 01H;清定时模式显示位标志位
                     CLR  P1.5;禁止蜂鸣器开机发声
                     MOV DS1302_ADDR,#8EH;写入控制字地址
                     MOV DS1302_DATA,#00H;允许写1302,8EH最高位为0时允许写操作,为1时允许读操作;
                     LCALL WRITE; 调用写程序    
                MOV DS1302_ADDR,#82H;对分初始化
                MOV DS1302_DATA,#00H;
                     LCALL WRITE; 调用写程序
                     MOV DS1302_ADDR,#84H;对时初始化
                MOV DS1302_DATA,#00H;
                     LCALL WRITE; 调用写程序
                    MOV DS1302_ADDR,#80H;启动DS1302
                MOV DS1302_DATA,#00H;对秒位最高位置0,启动DS1302
                     LCALL WRITE; 调用写程序
                     MOV DS1302_ADDR,#8EH;写入控制字地址
                     MOV DS1302_DATA,#80H;禁止写1302,8EH最高位为0时允许写操作,为1时允许读操作;
                     LCALL WRITE; 调用写程序


        MAIN:    
                  MOV DS1302_ADDR,#81H;读出秒
                  LCALL READ;
                     MOV SECOND,DS1302_DATA;
                     MOV DS1302_ADDR,#83H;读出分
                  LCALL READ;
                     MOV MIN,DS1302_DATA; 
                MOV DS1302_ADDR,#85H;读出时
                  LCALL READ;
                     MOV HOUR,DS1302_DATA;
                     MOV R0,SECOND;
                     LCALL LEAVE;将秒分离成两个数
                     MOV 41H,R1;将秒位分别存到两个内存单元和两个秒显示单元;
                     MOV 71H,41H;
                     MOV 42H,R2;
                     MOV 72H,42H;

                       MOV R0,MIN;
                     LCALL LEAVE;将分分离成两个数
                     MOV 43H,R1;将分位分别寸到两个内存单元和两个分显示单元;
                     MOV 73H,43H;
                     MOV 44H,R2;
                     MOV 74H,44H;
                
                     MOV R0,HOUR;
                     LCALL LEAVE;将时分离成两个数
                     MOV 45H,R1;将时位分别寸到两个内存单元和两个分显示单元;
                     MOV 75H,45H;
                     MOV 46H,R2;
                     MOV 76H,46H;                 
                LCALL DISP;
                ;JNB P1.0,TIME0;判断SET键是否按下
                LJMP MAIN;

;\\\\\\\\\\\\\\\\\\\\\\\\               ;时间调整程序    
;\\\\\\\\\\\\\\\\\\\\\\\\       TIME0:
;\\\\\\\\\\\\\\\\\\\\\\\\               ;调时闪动程序    
;\\\\\\\\\\\\\\\\\\\\\\\\        INTT1:            
;\\\\\\\\\\\\\\\\\\\\\\\\               ;分离程序 
;\\\\\\\\\\\\\\\\\\\\\\\\                
        LEAVE:     MOV A,R0;分离程序
                  ANL A,#0FH;
                     MOV R1,A;
                     MOV A,R0;
                     SWAP A;
                     ANL A,#0FH;
                     MOV R2,A;
                     RET;

;\\\\\\\\\\\\\\\\\\\\\\\\               ;写DS1302    
;\\\\\\\\\\\\\\\\\\\\\\\\                   


     WRITE:     CLR SCLK;
                 NOP;
                 SETB RST;
                     NOP;                
                   MOV A,DS1302_ADDR;
                     MOV R4,#08H;
        WRITE1:     RRC A;从低位到高位
                  NOP;
                     NOP;
                     CLR SCLK;
                     NOP;
                      NOP;
                     NOP;
                     MOV IO,C;CLK上升沿时写入地址到1302
                     NOP;
                     NOP;
                     NOP;
                     SETB SCLK;
                     NOP; 
                     NOP;
                     DJNZ R4,WRITE1;
                     CLR SCLK;
                     NOP;                            
                     MOV A,DS1302_DATA;
                     MOV R4,#08H;
         WRITE2:  RRC A;
                  NOP;
                     CLR SCLK;                
                     NOP;
                      NOP;
                     MOV IO,C;CLK上升沿时写入数据到1302
                     NOP;
                     NOP;
                     NOP;
                     SETB SCLK;
                     NOP; 
                     NOP;
                     DJNZ R4,WRITE2;                    
                     CLR RST;
                     RET;
;\\\\\\\\\\\\\\\\\\\\\\\\               ;读DS1302    
;\\\\\\\\\\\\\\\\\\\\\\\\       READ:    CLR SCLK;
                 NOP;
                     NOP;
                  SETB RST;
                     NOP;                 
                   MOV A,DS1302_ADDR;
                     MOV R4,#08H;
       READ1:    RRC A;从低位到高位                    
                     NOP;                     
                     MOV IO,C;CLK上升沿时写入地址到1302
                     NOP;
                     NOP;
                     NOP;
                     SETB SCLK;
                     NOP; 
                     NOP;
                     NOP;
                     CLR SCLK;添加
                     NOP;
                     NOP;
                     DJNZ R4,READ1;                                                  
                 MOV R4,#08H;                     
         READ2:   CLR SCLK;注意是CLK第8个脉冲的下降沿,不是第9个
                  NOP;
                      NOP;
                     NOP;
                     MOV C,IO;CLK下沿时从1302读出数据
                     NOP;
                     NOP;
                     NOP;
                     NOP;
                     NOP;
                     RRC A;从最低位开始读数据
                     NOP;
                     NOP;
                     NOP;
                     NOP;
                     SETB  SCLK;
                     NOP;                      
                     DJNZ R4, READ2;
                     MOV DS1302_DATA,A;                     
                     CLR RST;
                     RET; 

     INTT0:     PUSH ACC;累加器入栈
                PUSH PSW;状态字入栈 
                CLR ET0;
                CLR TR0;关闭T0
                MOV   A,#0B7H
                ADD   A,TL0
                MOV   TL0,A
                MOV   A,#3CH
                ADDC  A,TH0
                MOV   TH0,A   
                SETB TR0;启动定时器T0
                DJNZ R3,OUT0;中断10次未到继续中断
                     CPL 00H;对秒点闪烁标志位取反
                MOV R3,#0AH;0.5S到重新赋值                
     OUT0:      POP PSW;状态字入栈
                POP ACC;累加器入栈
                     SETB ET0;
                 RETI;中断返回

;\\\\\\\\\\\\\\\\\\\\\\\\               ;显示程序    
;\\\\\\\\\\\\\\\\\\\\\\\\ DISP:          MOV P0,#0FFH;      
         
DISPLAY:        MOV DPTR,#TAP;取断码表地址 
                JNB 00H,NEXT; 
                MOV P0,#07FH; 
                CLR P2.2;     开秒位上面小数点
                   LCALL D1MS;   延时1MS
                   SETB P2.2;     
                MOV P0,#07FH;
                CLR P2.3;     开秒位上面小数点
                 LCALL D1MS;   延时1MS
                 SETB P2.3;     
                AJMP NEXT1;
            

    NEXT:       MOV P0,#0FFH;
                 CLR P2.2;     关秒位上面小数点           
                 LCALL D1MS;   延时1MS
                SETB P2.2;   
                MOV P0,#0FFH;
                 CLR P2.3;     关秒位上面小数点           
                 LCALL D1MS;   延时1MS
                SETB P2.3;   
                    
                
     NEXT1:          MOV A,73H; 分个位显示                
                MOVC A,@A+DPTR;查显示数据对应断码
                MOV P0,A;   送P0口显示          
                CLR P2.3;     开分个位显示器位口
                LCALL D1MS;   延时1MS
                SETB P2.3;    关分个位显示器位口

             
               MOV A,74H;     分十位显示                 
               MOVC A,@A+DPTR;查显示数据对应断码
               MOV P0,A;     送P0口显示          
               CLR P2.2;     开分十位显示器位口
               LCALL D1MS;   延时1MS
               SETB P2.2;    关分十位显示器位口
       
         
               MOV A,75H;  时个位显示(同时秒小数点亮)                      
               MOVC A,@A+DPTR;查显示数据对应断码
               MOV P0,A;   送P0口显示          
               CLR P2.1;     开时个位显示器位口
               LCALL D1MS;   延时1MS
               SETB P2.1;    关时个位显示器位口
          
             
               MOV A,76H;     时十位显示                
               MOVC A,@A+DPTR;查显示数据对应断码
               MOV P0,A;   送P0口显示          
               CLR P2.0;     开时十位显示器位口
               LCALL D1MS;   延时1MS
               SETB P2.0;    关时十位显示器位口        
             
           
               JB 01H,DISPOUT;不是定时值设置模式将不显示模式位,是则显示          
               MOV A,78H;
               MOVC A,@A+DPTR;查显示数据对应断码
               MOV P0,A;   送P0口显示          
               CLR P2.4;     开定时模式位显示器位口
               LCALL D1MS;   延时1MS
               SETB P2.4;    关定时模式位显示器位口   

  DISPOUT:     RET;
     TAP:      DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0FFH;共阳数码管
                 ;  0,   1,   2,   3,  4,  5,  6,  7,  8,  9 , "不亮"
;\\\\\\\\\\\\\\\\\\\\\\\\               ;延时程序    
;\\\\\\\\\\\\\\\\\\\\\\\\     D1MS:     MOV R7,#250;延时1MS 
      DL0:     NOP;
               NOP;         
               DJNZ R7,DL0;
                  RET;
                    END;
       

相关帖子

沙发
ayb_ice| | 2007-10-4 19:46 | 只看该作者

这东东很简单

使用特权

评论回复
板凳
dai_weis| | 2007-10-4 19:47 | 只看该作者

程序太长,我有C语言版本

可以参考一下,主要是启动标志写入没有,如果没有那么要写入
DS1302的数据手册要看MAX-IC最新的,要不然没有地址和数据操作部分。
程序地址:
http://dai_weis.21ic.org/user1/2750/archives/2006/33503.html
相关链接:http://dai_weis.21ic.org/user1/2750/archives/2006/33503.html

使用特权

评论回复
地板
dai_weis| | 2007-10-4 19:50 | 只看该作者

LZ的问题我没有看全,抱歉

先不要管DS1302,写一段代码看看能否让屏幕正常工作,
如果可以那么再加入DS1302程序,取一个读秒就可以,让秒显示,如果可以了再解决时钟和秒点闪烁问题

使用特权

评论回复
5
昂首向前|  楼主 | 2007-10-5 09:11 | 只看该作者

谢谢dai_wei

照你说的方法先用一段程序试过显示正常,再读秒就一直显示乱码,是不是没起振,我买的DS1302只要3块钱,是不是买到假的了?

使用特权

评论回复
6
昂首向前|  楼主 | 2007-10-5 09:40 | 只看该作者

呵呵,谢谢,搞定了

问题搞定了,秒开始走时了,我把充电字节禁止充电,然后重新上电,用万用表量了下2,3脚电压,2脚为0.6V,3脚为0.2V,这两脚的电压应该是表明DS1302起振了,之前不正常时2脚为0V,3脚为2.4V,但是还是不知道为什么一下就起振了,奇怪!难道是在不接电池的情况下一定要把充电字节禁止充电?

使用特权

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

本版积分规则

26

主题

109

帖子

1

粉丝