📄 ds1302.lst
字号:
C51 COMPILER V8.05a DS1302 07/20/2008 14:33:06 PAGE 1
C51 COMPILER V8.05a, COMPILATION OF MODULE DS1302
OBJECT MODULE PLACED IN ds1302.OBJ
COMPILER INVOKED BY: D:\Program Files\Keil\C51\BIN\C51.EXE ds1302.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <at89x51.h>
2 #include "lcd_h.h"
3 const char LCDnum[10]="0123456789";
4 sbit clk=P2^7;
5 sbit I_O=P2^6;
6 sbit rst=P2^5;
7 void write1302(unsigned char command1)//向1302写入 1 个字节的数据 $$$
8 {
9 1 unsigned wi,sj;
10 1 sj=command1;
11 1 clk=0;
12 1 for(wi=0;wi<8;wi++)
13 1 {
14 2 // if((sj&0x01)==0x01) cc=1;else cc=0;
15 2 // I_O=cc;
16 2 if((sj&0x01)==0x01) I_O=1;else I_O=0;
17 2 clk=1;
18 2 clk=0;
19 2 sj=sj>>1;
20 2 }
21 1 }
22 void writedata(unsigned char wdataaddr,unsigned char waddr)//写入数据 $$$
23 {
24 1 rst=0;
25 1 clk=0;
26 1 rst=1;
27 1 write1302(wdataaddr);
28 1 write1302(waddr);
29 1 clk=1;
30 1 rst=0;
31 1 }
32 void reset1302(void) //$$$
33 //1302初始化,写入秒,分,时,日,月,星期,年的数据
34 {
35 1 rst=0;clk=0;rst=1;
36 1 write1302(0x8e);
37 1 write1302(0);
38 1 clk=1;
39 1 rst=0;
40 1 writedata(0x80,0);
41 1 writedata(0x82,0);
42 1 writedata(0x84,0);
43 1 writedata(0x86,0);
44 1 writedata(0x88,0);
45 1 writedata(0x8a,0);
46 1 writedata(0x8c,0);
47 1 rst=0;
48 1 clk=0;
49 1 rst=1;
50 1 write1302(0x8e);
51 1 write1302(0x80);
52 1 clk=1;
53 1 rst=0;
54 1 }
55 unsigned char read1302(void)//向1302读出 1 个字节的数据 $$$
C51 COMPILER V8.05a DS1302 07/20/2008 14:33:06 PAGE 2
56 {
57 1 unsigned char ri,rdat=0;
58 1
59 1 clk=0;
60 1 for(ri=0;ri<8;ri++)
61 1 {
62 2
63 2 if (I_O==1) rdat=rdat|0x80;
64 2 clk=1;
65 2 clk=0;
66 2 if (ri<7) rdat=rdat>>1;
67 2 }
68 1 return (rdat);
69 1 }
70 unsigned char readdata(unsigned char rdataaddr)//1302读出数据子程序 $$$
71 // rdataaddr为1302数据的读地址,如81H
72 {
73 1 unsigned char rdata=0;
74 1 rst=0;
75 1 clk=0;
76 1 rst=1;
77 1 write1302(rdataaddr);
78 1 I_O=1;
79 1 rdata=read1302();
80 1 clk=1;
81 1 rst=0;
82 1 return(rdata);
83 1 }
84
85
86
87
88
89 void main(void)
90 {
91 1 unsigned char second[2]={0,0};
92 1 delayms(50);
93 1 init_LCD();
94 1 clear_LCD();
95 1 movexy(1,1);
96 1 //reset1302();
97 1 do
98 1 {
99 2 if (P2_0==0)
100 2 {
101 3 reset1302();
102 3 while(P2_0!=1);
103 3 }
104 2 second[0]=readdata(0x81);
105 2 second[1]=second[0];
106 2 second[0]=second[0]&0x0f;
107 2 second[1]=second[1]&0x70;
108 2 second[1]=second[1]>>4;
109 2 movexy(1,0);
110 2 write_LCD_data(LCDnum[second[1]]);
111 2 write_LCD_data(LCDnum[second[0]]);
112 2 }while(1);
113 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 306 ----
C51 COMPILER V8.05a DS1302 07/20/2008 14:33:06 PAGE 3
CONSTANT SIZE = 2 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 10 2
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -