1 /*
 2  * DS1302.h
 3  *
 4  *  Created on: 2013-11-27
 5  *      Author: Allen
 6  */
 7 
 8 #ifndef DS1302_H_
 9 #define DS1302_H_
10 
11 #include     <MSP430G2553.h>
12 #include    "MyType.h"
13 
14 //时间结构体
15 typedef struct
16 {
17     uchar year;    //00-99,前面自己加入20,比如读出13为2013
18     uchar month;
19     uchar date;
20     uchar hour;
21     uchar min;
22     uchar sec;
23     uchar week;
24 }_calendar_obj;
25 
26 extern _calendar_obj calendar;    //日历结构体
27 
28 #define delay_time              0
29 //DS1302地址定义
30 #define ds1302_sec_add            0x80        //秒数据地址
31 #define ds1302_min_add            0x82        //分数据地址
32 #define ds1302_hr_add            0x84        //时数据地址
33 #define ds1302_date_add            0x86        //日数据地址
34 #define ds1302_month_add        0x88        //月数据地址
35 #define ds1302_day_add            0x8a        //星期数据地址
36 #define ds1302_year_add            0x8c        //年数据地址
37 #define ds1302_control_add        0x8e        //控制数据地址
38 #define ds1302_charger_add        0x90
39 #define ds1302_clkburst_add        0xbe
40 
41 //SCLK:P2.3
42 #define        SCLK_DIR        (P2DIR)
43 #define        SCLK_OUT        (P2OUT)
44 #define        SCLK_REN        (P2REN)
45 #define        SCLK_PIN        (BIT3)
46 
47 #define        SCLK_UP            (Set_Bit(SCLK_REN,SCLK_PIN))
48 #define        SCLK_DirOut        (Set_Bit(SCLK_DIR,SCLK_PIN))
49 #define        SCLK_H            (Set_Bit(SCLK_OUT,SCLK_PIN))
50 #define        SCLK_L            (Clr_Bit(SCLK_OUT,SCLK_PIN))
51 
52 
53 //DS_SDA:P2.4
54 #define        IO_DIR            (P2DIR)
55 #define        IO_OUT            (P2OUT)
56 #define        IO_IN            (P2IN)
57 #define        IO_REN            (P2REN)
58 #define        IO_PIN            (BIT4)
59 
60 #define        IO_UP            (Set_Bit(IO_REN,IO_PIN))
61 #define        IO_DirOut        (Set_Bit(IO_DIR,IO_PIN))
62 #define        IO_H            (Set_Bit(IO_OUT,IO_PIN))
63 #define        IO_L            (Clr_Bit(IO_OUT,IO_PIN))
64 
65 
66 #define        IO_DirIn        (Clr_Bit(IO_DIR,IO_PIN))
67 #define        IO_Data            (Get_Bit(IO_IN,IO_PIN))
68 
69 //RST:P2.5
70 #define        RST_DIR            (P2DIR)
71 #define        RST_OUT            (P2OUT)
72 #define        RST_IN            (P2IN)
73 #define        RST_REN            (P2REN)
74 #define        RST_PIN            (BIT5)
75 
76 #define        RST_UP            (Set_Bit(RST_REN,RST_PIN))
77 #define        RST_DirOut        (Set_Bit(RST_DIR,RST_PIN))
78 #define        RST_H            (Set_Bit(RST_OUT,RST_PIN))
79 #define        RST_L            (Clr_Bit(RST_OUT,RST_PIN))
80 
81 
82 void DS1302_Init(void);
83 static void delay_us( unsigned int k );
84 void ds1302_write_byte(uchar addr, uchar data);
85 uchar ds1302_read_byte(uchar addr);
86 void ds1302_write_time(uchar year,uchar month,uchar day,uchar hour,uchar min,uchar sec,uchar week);
87 void ds1302_read_time(void);
88 void ds1302_sendtime_uart(void);
89 
90 #endif
DS1302.h

相关文章:

  • 2021-12-30
  • 2021-10-05
  • 2021-06-30
  • 2022-02-11
  • 2022-12-23
  • 2021-08-27
  • 2021-12-30
  • 2021-08-08
猜你喜欢
  • 2021-12-30
  • 2021-12-30
  • 2022-01-05
  • 2021-12-30
  • 2021-12-30
相关资源
相似解决方案