51_LanQiaoBei/模板/蓝桥杯全模块测试例程/DS18B20温度模块/User/Listings/ds1302.lst
2025-04-13 01:02:19 +08:00

111 lines
3.6 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

C51 COMPILER V9.59.0.0 DS1302 02/24/2024 21:37:53 PAGE 1
C51 COMPILER V9.59.0.0, COMPILATION OF MODULE DS1302
OBJECT MODULE PLACED IN .\Objects\ds1302.obj
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE ..\Driver\ds1302.c OPTIMIZE(8,SPEED) BROWSE INCDIR(..\Driver) DEBUG OBJE
-CTEXTEND PRINT(.\Listings\ds1302.lst) TABS(2) OBJECT(.\Objects\ds1302.obj)
line level source
1 /* # DS1302莉」遐∫援谿オ隸エ譏<EFBDB4>
2 1. 譛ャ譁<EFBDAC>サカ螟ケ荳ュ謠蝉セ帷噪鬩ア蜉ィ莉」遐∽セ帛盾襍幃€画焔螳梧<E89EB3>遞句コ剰ョセ隶。蜿り€<E3828A>€<EFBFBD>
3 2. 蜿りオ幃€画焔蜿ッ莉・閾ェ陦檎シ門<EFBDBC>逶ク蜈ウ莉」遐∵<E98190>莉・隸・莉」遐∽クコ蝓コ遑€<E98191><EFBFBD>ケ謐ョ謇€騾牙黒迚<E9BB92>惻邀サ蝙九€∬ソ
-占。碁€溷コヲ蜥瑚ッ暮「<E69AAE>
4 荳ュ蟇ケ蜊慕援譛コ譌カ髓滄「醍紫逧<E7B4AB>ヲ∵アゑシ瑚ソ幄。御サ」遐∬ー<E288AC>ッ募柱菫ョ謾ケ縲<EFBDB9>
5 */
6 #include "ds1302.h"
7 #include "REG52.H"
8 #include "intrins.h"
9 sbit SCK = P1 ^ 7;
10 sbit SDA = P2 ^ 3;
11 sbit RST = P1 ^ 3;
12 //
13 void Write_Ds1302(unsigned char temp)
14 {
15 1 unsigned char i;
16 1 for (i = 0; i < 8; i++)
17 1 {
18 2 SCK = 0;
19 2 SDA = temp & 0x01;
20 2 temp >>= 1;
21 2 SCK = 1;
22 2 }
23 1 }
24
25 //
26 void Write_Ds1302_Byte(unsigned char address, unsigned char dat)
27 {
28 1 RST = 0;
29 1 _nop_();
30 1 SCK = 0;
31 1 _nop_();
32 1 RST = 1;
33 1 _nop_();
34 1 Write_Ds1302(address);
35 1 Write_Ds1302(dat);
36 1 RST = 0;
37 1 }
38
39 //
40 unsigned char Read_Ds1302_Byte(unsigned char address)
41 {
42 1 unsigned char i, temp = 0x00;
43 1 RST = 0;
44 1 _nop_();
45 1 SCK = 0;
46 1 _nop_();
47 1 RST = 1;
48 1 _nop_();
49 1 Write_Ds1302(address);
50 1 for (i = 0; i < 8; i++)
51 1 {
52 2 SCK = 0;
53 2 temp >>= 1;
C51 COMPILER V9.59.0.0 DS1302 02/24/2024 21:37:53 PAGE 2
54 2 if (SDA)
55 2 temp |= 0x80;
56 2 SCK = 1;
57 2 }
58 1 RST = 0;
59 1 _nop_();
60 1 SCK = 0;
61 1 _nop_();
62 1 SCK = 1;
63 1 _nop_();
64 1 SDA = 0;
65 1 _nop_();
66 1 SDA = 1;
67 1 _nop_();
68 1 return (temp);
69 1 }
70 void Set_Rtc(unsigned char *ucRtc)
71 {
72 1 unsigned char i;
73 1 Write_Ds1302_Byte(0x8e, 0x00); // 蜈ウ髣ュ蜀吩ソ晄侃
74 1 for (i = 0; i < 3; i++)
75 1 Write_Ds1302_Byte(0x84 - 2 * i, ucRtc[i]);
76 1 Write_Ds1302_Byte(0x8e, 0x80); // 謇灘シ€蜀吩ソ晄侃
77 1 }
78 void Read_Rtc(unsigned char *ucRtc)
79 {
80 1 unsigned char i;
81 1 for (i = 0; i < 3; i++)
82 1 ucRtc[i] = Read_Ds1302_Byte(0x85 - 2 * i);
83 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 220 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 6
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)