原创 DS12887 在51单片机上应用

2007-5-16 16:30 5905 7 7 分类: MCU/ 嵌入式


1     /*
2         DS12887 on 51 mcu
3         designed by zl0801
4        
5         zhaoliang0801@dl.cn
6         2007-5-16 16:22
7
8     /*
9     register description
10
11    REGISTER A
12    MSB                                                     LSB
13    BIT 7   BIT 6   BIT 5   BIT 4   BIT 3   BIT 2   BIT 1   BIT 0
14    UIP     DV2     DV1     DV0     RS3     RS2     RS1     RS0
15
16        Update In Progress (UIP) : The time, calendar,
17    and alarm information in RAM is fully available
18    for access when the UIP bit is zero.
19       
20        DV2     DV1     DV0      : A pattern of 010 is the
21    only combination of bits that will turn the oscillator on
22    and allow the RTC to keep time.
23
24
25    REGISTER B
26    MSB                                                     LSB
27    BIT 7   BIT 6   BIT 5   BIT 4   BIT 3   BIT 2   BIT 1   BIT 0
28    SET     PIE     AIE     UIE     SQWE    DM      24/12   DSE
29
30        SET     :   When the SET bit is written to a one, any update transfer
31    is inhibited and the program can initialize the time and
32    calendar bytes without an update occurring in the midst
33    of initializing.
34
35
36        DM  Data Mode (DM)  :   A one in DM signifies binary data
37    while a zero in DM specifies Binary Coded Decimal
38    (BCD) data.
39
40        24/12   : A one indicates the 24¨Chour mode and a zero indicates
41    the 12¨Chour mode.
42
43    */
44
45    #include
46    #include
47
48    /*************************/
49    #define     TM_SEC      XBYTE[0xFF00]
50    #define     TM_MIN      XBYTE[0xFF02]
51    #define     TM_HOU      XBYTE[0xFF04]
52    #define     DAY         XBYTE[0xFF06]
53    #define     DATE        XBYTE[0xFF07]
54    #define     MONTH       XBYTE[0xFF08]
55    #define     YEAR        XBYTE[0xFF09]
56
57    #define     AM_SEC      XBYTE[0xFF01]
58    #define     AM_MIN      XBYTE[0xFF03]
59    #define     AM_HOU      XBYTE[0xFF05]
60
61    #define     REG_A       XBYTE[0xFF0a]
62    #define     REG_B       XBYTE[0xFF0b]
63    #define     REG_C       XBYTE[0xFF0c]
64    #define     REG_D       XBYTE[0xFF0d]
65
66
67    void Set_calendar(void);
68    void Read_calendar(void);
69    void Start_calendar(void);
70    void Stop_calendar(void);
71
72    code unsigned char at[7]={9,8,7,4,2,0,6};   /* Year Month Day hour minute second weekday*/
73
74    unsigned char calendar_time[7]={07,5,16,15,43,00,3}; /* 05/8/16 18:58:00 ÐÇÆÚ¶þ*/
75
76    unsigned char xdata *calendar_address=0xff00;
77
78    sbit sec_LED = P2^7;
79
80    void main(void)
81    {
82        sec_LED = 1;        // shut down
83        Set_calendar();     // set
84        Start_calendar();   // start
85
86        while(1)
87        {
88            Read_calendar();   // Read
89
90            if( calendar_time[5] % 2 )
91                sec_LED = 0;    // flash per second
92            else
93                sec_LED = 1;
94        }
95    }
96
97    void Set_calendar(void) //  Set_calendar
98    {
99        unsigned char i;
100
101       REG_B=0x80;         // start initialize
102
103       for(i=0;i<7;i++)
104           *(calendar_address+at[i])=calendar_time[i];
105   }
106
107   void Read_calendar(void) // Read_calendar
108   {
109       unsigned char  temp,i;
110
111       REG_B = 0x06;   //  binary data,24¨Chour mode
112
113       do              // monitor the UIE bit
114       {
115           temp = REG_A;
116       } while( temp & 0x80 );
117
118       for(i=0;i<7;i++)    //  Read_calendar and save in memory
119           calendar_time[i]=*(calendar_address+at[i]);
120   }
121
122   void Start_calendar(void) // turn on oscillator
123   {
124       REG_A=0x20;     //  0_010_0000  turn on oscillator
125       REG_B=0x06;     //  binary data,24¨Chour mode
126   }
127
128   void Stop_calendar(void) // turn off clock
129   {
130       REG_A=0x70;     //  0_111_0000  Stop oscillator
131   }






点击看大图


 


说明:


这个是一个 点阵板的驱动电路,上面有 DS12887 时钟,一路ds18b20 红外遥控控制,蜂鸣器定时报警


 串口232 下载程序


暑假的时候,制作一个 LED点阵 电子钟 !



文章评论0条评论)

登录后参与讨论
我要评论
0
7
关闭 站长推荐上一条 /2 下一条