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代码片段说明 2 1. 本文件夹中提供的驱动代码供参赛选手完成程序设计参考。 3 2. 参赛选手可以自行编写相关代码或以该代码为基础,根据所选单片机类型、 -行速度和试题 4 中对单片机时钟频率的要求,进行代码调试和修改。 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)