ds1302.lst
来自「STC51系列的源码」· LST 代码 · 共 309 行 · 第 1/2 页
LST
309 行
C51 COMPILER V8.02 DS1302 09/25/2008 18:46:20 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE DS1302
OBJECT MODULE PLACED IN .\DS1302.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\DS1302\DS1302.c LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\DS1302.lst) OBJE
-CT(.\DS1302.obj)
line level source
1 /********************************************************************************/
2 /* filename : DS1302.c */
3 /* created : xillinx */
4 /* descript : 时钟芯片的处理函数 */
5 /********************************************************************************/
6 #include "../CPU/CPU.h"
7 #include "../DS1302/DS1302.h"
8
9 st_ds1302_time DS1302_time;
10 unsigned char DS1302_second;
11
12 /********************************************************************************/
13 /* function : DS1302_set_clk() */
14 /* recension: xillinx */
15 /* descript : 设置或者清除DS1302的CLK引脚 */
16 /********************************************************************************/
17 void DS1302_set_clk(unsigned char clk)
18 { if(clk)
19 1 { c51_U19_latch|=0x02;
20 2 }
21 1 else
22 1 { c51_U19_latch&=0xFD;
23 2 }
24 1 c51_hc138_cs_io2[0x0]=c51_U19_latch;
25 1 }
26
27 /********************************************************************************/
28 /* function : DS1302_set_sel() */
29 /* recension: xillinx */
30 /* descript : 设置或者清除DS1302的CS引脚 */
31 /********************************************************************************/
32 void DS1302_set_sel(unsigned char sel)
33 { if(sel)
34 1 { c51_U19_latch|=0x01;
35 2 }
36 1 else
37 1 { c51_U19_latch&=0xFE;
38 2 }
39 1 c51_hc138_cs_io2[0x0]=c51_U19_latch;
40 1 }
41
42 /********************************************************************************/
43 /* function : DS1302_set_dat() */
44 /* recension: xillinx */
45 /* descript : 设置或者清除DS1302的DATA引脚 */
46 /********************************************************************************/
47 void DS1302_set_dat(unsigned char dat)
48 { DS1302_DIO=dat;
49 1 }
50
51 /********************************************************************************/
52 /* function : DS1302_get_dat() */
53 /* recension: xillinx */
54 /* descript : 设置或者清除DS1302的DATA引脚 */
C51 COMPILER V8.02 DS1302 09/25/2008 18:46:20 PAGE 2
55 /********************************************************************************/
56 unsigned char DS1302_get_dat(void)
57 { return DS1302_DIO;
58 1 }
59
60 /********************************************************************************/
61 /* funname : DS1302_delay() */
62 /* created : xillinx */
63 /* time : 2008-08-06 */
64 /* descript: 简单的时间延时 */
65 /********************************************************************************/
66 void DS1302_delay_max(void)
67 { _nop_();
68 1 _nop_();
69 1 _nop_();
70 1 _nop_();
71 1 _nop_();
72 1 _nop_();
73 1 _nop_();
74 1 _nop_();
75 1 _nop_();
76 1 _nop_();
77 1 _nop_();
78 1 _nop_();
79 1 }
80 void DS1302_delay_min(void)
81 { _nop_();
82 1 _nop_();
83 1 _nop_();
84 1 _nop_();
85 1 _nop_();
86 1 _nop_();
87 1 }
88
89 /********************************************************************************/
90 /* funname : DS1302_open() */
91 /* created : xillinx */
92 /* time : 2008-08-06 */
93 /* descript: 打开DS1302 */
94 /********************************************************************************/
95 void DS1302_open(void)
96 {
97 1 DS1302_set_clk(0x0);
98 1 DS1302_delay_min();
99 1 DS1302_set_sel(0x0); //* 禁止DS1302
100 1 DS1302_delay_min();
101 1 DS1302_set_sel(0x1); //* 使能DS1302
102 1 }
103
104
105 /********************************************************************************/
106 /* funname : DS1302_close() */
107 /* created : xillinx */
108 /* time : 2008-08-06 */
109 /* descript: 关闭DS1302 */
110 /********************************************************************************/
111 void DS1302_close(void)
112 { DS1302_set_sel(0x0); //* 禁止DS1302
113 1 DS1302_delay_min();
114 1 DS1302_set_dat(0x1); //* 释放数据总线
115 1 DS1302_delay_min();
116 1 DS1302_set_clk(0x1);
C51 COMPILER V8.02 DS1302 09/25/2008 18:46:20 PAGE 3
117 1 }
118
119 /********************************************************************************/
120 /* funname : DS1302_write_8_bit() */
121 /* created : xillinx */
122 /* time : 2008-08-06 */
123 /* descript: 写入8位数据 */
124 /********************************************************************************/
125 void DS1302_write_8_bit(unsigned char mdata)
126 { unsigned char i;
127 1 for(i=0x0; i<0x8; i++)
128 1 { if(mdata&0x1)
129 2 { DS1302_set_dat(0x1);
130 3 }
131 2 else
132 2 { DS1302_set_dat(0x0);
133 3 }
134 2 DS1302_delay_min();
135 2 DS1302_set_clk(0x1); //* 上升沿写入数据
136 2 DS1302_delay_max();
137 2 DS1302_set_clk(0x0);
138 2 DS1302_delay_min();
139 2 mdata >>= 0x1;
140 2 }
141 1 }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?