Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C51 add adjust alarm clock

Status
Not open for further replies.

sherryliu

Member level 1
Joined
Jan 17, 2011
Messages
32
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,535
Hi all
I have a develop board of C51,7 segment show clock,I want to add alarm clock code,who can help me wrap it,Thanks in advance!
 

Attachments

  • 数码管显示时钟.rar
    34.8 KB · Views: 53

If you do not specify exactly what is the issue, no one will be able to help you; unless you are idling expecting someone to do it for you.
 

Thank for your replying,my develop board 7 segment clock show hardware depend 74hc138&74hc573,I want add alarm clock,I don't how to configuration by the exist hardware,Pls give me a idea.
 

No clue, you have not added your schematic diagram.
A project file is useless for those who have not Proteus.
 

All of files in my attached,Pls download it,include source code&Proteus file.
 

QQ Photo20170329143755.jpg

The schematic of adjustable clock,Pls help added code of keyscan.THX!
 

I will do the favor for you of copying the source codes of the attachment to the body of the message, since few here will have patience to download-save-open your program in a text editor, while it could be done straight from the browser. Now you can indicate EXACTLY where the issue is; I mean, what have you done at which line and didn't work as expected ?

MAIN.C

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*******************************************************************************
*                 
*                              ÆÕÖпƼ¼
--------------------------------------------------------------------------------
* ʵ Ñé Ãû       : DS1302ʱÖÓÏÔʾÊÔÑé
* ʵÑé˵Ã÷       : ÊýÂë¹ÜÏÔʾʱÖÓÐÅÏ¢
* Á¬½Ó·½Ê½       : ¼ûÁ¬½Óͼ
* ×¢    Òâ       : 
*******************************************************************************/
 
#include<reg51.h>
#include"ds1302.h"
 
 
//--¶¨ÒåʹÓõÄIO--//
#define GPIO_DIG P0
 
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
 
 
//--¶¨ÒåÈ«¾Ö±äÁ¿--//
unsigned char code DIG_CODE[17]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//0¡¢1¡¢2¡¢3¡¢4¡¢5¡¢6¡¢7¡¢8¡¢9¡¢A¡¢b¡¢C¡¢d¡¢E¡¢FµÄÏÔʾÂë
unsigned char DisplayData[8];
//ÓÃÀ´´æ·ÅÒªÏÔʾµÄ8λÊýµÄÖµ
 
//--ÉùÃ÷È«¾Ö±äÁ¿--//
void DigDisplay();
void DelayMS(unsigned int ms);
/*******************************************************************************
* º¯ Êý Ãû         : main
* º¯Êý¹¦ÄÜ         : Ö÷º¯Êý
* Êä    Èë         : ÎÞ
* Êä    ³ö         : ÎÞ
*******************************************************************************/
 
void main()
{
   Ds1302Init();
   while(1)
   {   
      Ds1302ReadTime();
      DisplayData[0] = DIG_CODE[TIME[2]/16];            //ʱ
      DisplayData[1] = DIG_CODE[TIME[2]&0x0f];             
      DisplayData[2] = 0x40;
      DisplayData[3] = DIG_CODE[TIME[1]/16];            //·Ö
      DisplayData[4] = DIG_CODE[TIME[1]&0x0f];   
      DisplayData[5] = 0x40;
      DisplayData[6] = DIG_CODE[TIME[0]/16];            //Ãë
      DisplayData[7] = DIG_CODE[TIME[0]&0x0f];
      DigDisplay();   
   }
   
}
 
/*******************************************************************************
* º¯ Êý Ãû         : DigDisplay
* º¯Êý¹¦ÄÜ         : ʹÓÃÊýÂë¹ÜÏÔʾ
* Êä    Èë         : ÎÞ
* Êä    ³ö         : ÎÞ
*******************************************************************************/
void DigDisplay()
{
   unsigned char i;
   unsigned int j;
   for(i=0;i<8;i++)
   {
 
      switch(i)    //λѡ£¬Ñ¡ÔñµãÁÁµÄÊýÂë¹Ü£¬
      {
         case(0):
            LSA=0;LSB=0;LSC=0; break;//ÏÔʾµÚ0λ
         case(1):
            LSA=1;LSB=0;LSC=0; break;//ÏÔʾµÚ1λ
         case(2):
            LSA=0;LSB=1;LSC=0; break;//ÏÔʾµÚ2λ
         case(3):
            LSA=1;LSB=1;LSC=0; break;//ÏÔʾµÚ3λ
         case(4):
            LSA=0;LSB=0;LSC=1; break;//ÏÔʾµÚ4λ
         case(5):
            LSA=1;LSB=0;LSC=1; break;//ÏÔʾµÚ5λ
         case(6):
            LSA=0;LSB=1;LSC=1; break;//ÏÔʾµÚ6λ
         case(7):
            LSA=1;LSB=1;LSC=1; break;//ÏÔʾµÚ7λ   
      }
      GPIO_DIG=DisplayData[i];//·¢ËͶÎÂë
//   DelayMS(50);
 
      j=50;                   //ɨÃè¼ä¸ôʱ¼äÉ趨
      while(j--);   
      GPIO_DIG=0x00;//ÏûÒþ
   }   
 
}
 
void DelayMS(unsigned int ms)
{
        unsigned char i;
        while(ms--)
        for(i=0;i<120;i++);
}




DS1302.C

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include"ds1302.h"
 
//---DS1302дÈëºÍ¶Áȡʱ·ÖÃëµÄµØÖ·ÃüÁî---//
//---Ãë·ÖʱÈÕÔÂÖÜÄê ×îµÍλ¶Áдλ;-------//
uchar code READ_RTC_ADDR[7] = {0x81, 0x83, 0x85, 0x87, 0x89, 0x8b, 0x8d}; 
uchar code WRITE_RTC_ADDR[7] = {0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c};
 
//---DS1302ʱÖÓ³õʼ»¯2013Äê1ÔÂ1ÈÕÐÇÆÚ¶þ12µã00·Ö00Ãë¡£---//
//---´æ´¢Ë³ÐòÊÇÃë·ÖʱÈÕÔÂÖÜÄê,´æ´¢¸ñʽÊÇÓÃBCDÂë---//
uchar TIME[7] = {0, 0, 0x12, 0x01, 0x01, 0x02, 0x13};
 
/*******************************************************************************
* º¯ Êý Ãû         : Ds1302Write
* º¯Êý¹¦ÄÜ         : ÏòDS1302ÃüÁµØÖ·+Êý¾Ý£©
* Êä    Èë         : addr,dat
* Êä    ³ö         : ÎÞ
*******************************************************************************/
 
void Ds1302Write(uchar addr, uchar dat)
{
   uchar n;
   RST = 0;
   _nop_();
 
   SCLK = 0;//ÏȽ«SCLKÖõ͵çƽ¡£
   _nop_();
   RST = 1; //È»ºó½«RST(CE)Öøߵçƽ¡£
   _nop_();
 
   for (n=0; n<8; n++)//¿ªÊ¼´«ËÍ°ËλµØÖ·ÃüÁî
   {
      DSIO = addr & 0x01;//Êý¾Ý´ÓµÍλ¿ªÊ¼´«ËÍ
      addr >>= 1;
      SCLK = 1;//Êý¾ÝÔÚÉÏÉýÑØʱ£¬DS1302¶ÁÈ¡Êý¾Ý
      _nop_();
      SCLK = 0;
      _nop_();
   }
   for (n=0; n<8; n++)//дÈë8λÊý¾Ý
   {
      DSIO = dat & 0x01;
      dat >>= 1;
      SCLK = 1;//Êý¾ÝÔÚÉÏÉýÑØʱ£¬DS1302¶ÁÈ¡Êý¾Ý
      _nop_();
      SCLK = 0;
      _nop_();   
   }   
       
   RST = 0;//´«ËÍÊý¾Ý½áÊø
   _nop_();
}
 
/*******************************************************************************
* º¯ Êý Ãû         : Ds1302Read
* º¯Êý¹¦ÄÜ         : ¶ÁÈ¡Ò»¸öµØÖ·µÄÊý¾Ý
* Êä    Èë         : addr
* Êä    ³ö         : dat
*******************************************************************************/
 
uchar Ds1302Read(uchar addr)
{
   uchar n,dat,dat1;
   RST = 0;
   _nop_();
 
   SCLK = 0;//ÏȽ«SCLKÖõ͵çƽ¡£
   _nop_();
   RST = 1;//È»ºó½«RST(CE)Öøߵçƽ¡£
   _nop_();
 
   for(n=0; n<8; n++)//¿ªÊ¼´«ËÍ°ËλµØÖ·ÃüÁî
   {
      DSIO = addr & 0x01;//Êý¾Ý´ÓµÍλ¿ªÊ¼´«ËÍ
      addr >>= 1;
      SCLK = 1;//Êý¾ÝÔÚÉÏÉýÑØʱ£¬DS1302¶ÁÈ¡Êý¾Ý
      _nop_();
      SCLK = 0;//DS1302ϽµÑØʱ£¬·ÅÖÃÊý¾Ý
      _nop_();
   }
   _nop_();
   for(n=0; n<8; n++)//¶ÁÈ¡8λÊý¾Ý
   {
      dat1 = DSIO;//´Ó×îµÍλ¿ªÊ¼½ÓÊÕ
      dat = (dat>>1) | (dat1<<7);
      SCLK = 1;
      _nop_();
      SCLK = 0;//DS1302ϽµÑØʱ£¬·ÅÖÃÊý¾Ý
      _nop_();
   }
 
   RST = 0;
   _nop_();   //ÒÔÏÂΪDS1302¸´Î»µÄÎȶ¨Ê±¼ä,±ØÐëµÄ¡£
   SCLK = 1;
   _nop_();
   DSIO = 0;
   _nop_();
   DSIO = 1;
   _nop_();
   return dat;   
}
 
/*******************************************************************************
* º¯ Êý Ãû         : Ds1302Init
* º¯Êý¹¦ÄÜ         : ³õʼ»¯DS1302.
* Êä    Èë         : ÎÞ
* Êä    ³ö         : ÎÞ
*******************************************************************************/
 
void Ds1302Init()
{
   uchar n;
   Ds1302Write(0x8E,0X00);       //½ûֹд±£»¤£¬¾ÍÊǹرÕд±£»¤¹¦ÄÜ
   for (n=0; n<7; n++)//дÈë7¸ö×Ö½ÚµÄʱÖÓÐźţº·ÖÃëʱÈÕÔÂÖÜÄê
   {
      Ds1302Write(WRITE_RTC_ADDR[n],TIME[n]);   
   }
   Ds1302Write(0x8E,0x80);       //´ò¿ªÐ´±£»¤¹¦ÄÜ
}
 
/*******************************************************************************
* º¯ Êý Ãû         : Ds1302ReadTime
* º¯Êý¹¦ÄÜ         : ¶ÁȡʱÖÓÐÅÏ¢
* Êä    Èë         : ÎÞ
* Êä    ³ö         : ÎÞ
*******************************************************************************/
 
void Ds1302ReadTime()
{
   uchar n;
   for (n=0; n<7; n++)//¶ÁÈ¡7¸ö×Ö½ÚµÄʱÖÓÐźţº·ÖÃëʱÈÕÔÂÖÜÄê
   {
      TIME[n] = Ds1302Read(READ_RTC_ADDR[n]);
   }
      
}



DS1302.H

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef __DS1302_H_
#define __DS1302_H_
 
//---°üº¬Í·Îļþ---//
#include<reg51.h>
#include<intrins.h>
 
//---Öض¨Òå¹Ø¼ü´Ê---//
#ifndef uchar
#define uchar unsigned char
#endif
 
#ifndef uint 
#define uint unsigned int
#endif
 
//---¶¨Òåds1302ʹÓõÄIO¿Ú---//
sbit DSIO=P3^4;
sbit RST=P3^5;
sbit SCLK=P3^6;
 
//---¶¨ÒåÈ«¾Öº¯Êý---//
void Ds1302Write(uchar addr, uchar dat);
uchar Ds1302Read(uchar addr);
void Ds1302Init();
void Ds1302ReadTime();
 
//---¼ÓÈëÈ«¾Ö±äÁ¿--//
extern uchar TIME[7];   //¼ÓÈëÈ«¾Ö±äÁ¿
 
#endif



Just a remark:
We have no clue of the meaning of the comments, wrote in non english language.
Next time, please translate it !
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top