📄 pcf8583.lst
字号:
C51 COMPILER V8.08 PCF8583 01/23/2008 14:09:39 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE PCF8583
OBJECT MODULE PLACED IN pcf8583.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE pcf8583.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include
*** ERROR C309 IN LINE 1 OF pcf8583.c: bad or missing filename
*** WARNING C318 IN LINE 1 OF pcf8583.c: can't open file ''
2 #include
*** ERROR C309 IN LINE 2 OF pcf8583.c: bad or missing filename
*** WARNING C318 IN LINE 2 OF pcf8583.c: can't open file ''
3 #include
*** ERROR C309 IN LINE 3 OF pcf8583.c: bad or missing filename
*** WARNING C318 IN LINE 3 OF pcf8583.c: can't open file ''
4
5 sbit KSET = P3^4; /* key 1 */
*** ERROR C202 IN LINE 5 OF PCF8583.C: 'P3': undefined identifier
6 sbit KINC = P3^5; /* key 2 */
*** ERROR C202 IN LINE 6 OF PCF8583.C: 'P3': undefined identifier
7 sbit KDEC = P1^6; /* key 3 */
*** ERROR C202 IN LINE 7 OF PCF8583.C: 'P1': undefined identifier
8 sbit DSET = P1^7; /* DISP MODE */
*** ERROR C202 IN LINE 8 OF PCF8583.C: 'P1': undefined identifier
9
10 #define key_down 0 /* key press down: GND */
11 #define key_up 1 /* key lift up : VCC */
12
13 sbit ALARM="P1"^0; /* indicate lamp LED */
*** ERROR C144 IN LINE 13 OF PCF8583.C: 'ALARM': invalid sbit specifier
14 sbit POWER="P1"^1; /* display power switch */
*** ERROR C144 IN LINE 14 OF PCF8583.C: 'POWER': invalid sbit specifier
15 sbit SDA = P1^5;
*** ERROR C202 IN LINE 15 OF PCF8583.C: 'P1': undefined identifier
16 sbit SCL = P1^4;
*** ERROR C202 IN LINE 16 OF PCF8583.C: 'P1': undefined identifier
17
18 unsigned char code db[26]=
19 { 0x3F,0x06,0x5B,0x4F,0X66,0x6D,0x7D,0x07,0x7F,0X6F,0x00,
20 /* 0 1 2 3 4 5 6 7 8 9 NULL */
21 0x6E,0x79,0x77,0x37,0x5C,0x54,0x1C,0x76,0x5E,0x39,0x40,
22 /* Y E A M o n u H d C - */
23 0x38,0x48,0x04,0x0E };
24 /* L = i j*/
25
26
27 unsigned char dv[6],j,df;
28 bit ksetf, kdecf, kincf, dsetf,kf;
29 unsigned char year,month,day,hour,minute,second,week;
30 unsigned char adj;
31
32 /********** Function Declare Begin **********************/
33
34 char Start(); /* Start IIC bus for reading or writing*/
35 void Stop(); /* Stop IIC bus */
36 char Shin(); /* Shift a byte from EEPROM, */
37 /* most significant first */
38 void Shout(char Byte); /* Shift a byte to EEPROM */
39 char TestAck(); /* check if Acknowledge bit is valid */
40 char RandomRead(char DeviceAddr, char ByteAddr);
41 void RandomWrite(char DeviceAddr, char ByteAddr, char Byte);
C51 COMPILER V8.08 PCF8583 01/23/2008 14:09:39 PAGE 2
42 char SRead( char DeviceAddr, char ByteAddr, char ByteNum, char ReadBuf[] );
43
44 /*
45 void PageWrite(char DeviceAddr, char ByteAddr, char ByteNum, char ByteBuf[] );
46 */
47
48
49 /********** Function Declare End *************************/
50
51 char Start()//开始信号
52 {
53 1 SCL="1"; /* release SCL */
*** ERROR C202 IN LINE 53 OF PCF8583.C: 'SCL': undefined identifier
54 1 SDA="1"; /* release SDA */
*** ERROR C202 IN LINE 54 OF PCF8583.C: 'SDA': undefined identifier
55 1 _nop_();
56 1 if( SCL==0 || SDA==0 ) return 0; /* IIC bus not available, Start false */
57 1 else
58 1 {
59 2 SCL="1"; /* Send start operation */
60 2 _nop_();
61 2 _nop_();
62 2 SDA="0"; /* SDA high-to-low when SCL high */
63 2 _nop_();
64 2 _nop_();
65 2 _nop_(); /*one cycle delay function */
66 2 _nop_(); /*declare in */
67 2 _nop_();
68 2 SCL="0";
69 2 _nop_();
70 2 SDA="1"; /*release SDA */
71 2 }
72 1 } /*return with SDA high, SCL low */
73
74 void Stop() //停止信号
75 {
76 1 SDA="0";
77 1 _nop_();
78 1 SCL="1";
79 1 _nop_();
80 1 _nop_();
81 1 _nop_();
82 1 _nop_();
83 1 _nop_();
84 1 SDA="1"; /* SDA low-to-high when SCL high, return with SCL SDA high */
85 1 }
86
87 char Shin()//接受一个字节
88 {
89 1 char i,RetByte;
90 1 for(i="0";i<8;i++)
91 1 {
92 2 SCL="0";
93 2 _nop_();
94 2 _nop_();
95 2 _nop_();
96 2 _nop_();
97 2 _nop_();
98 2 SCL="1";
99 2 _nop_();
100 2 _nop_();
101 2 RetByte<<=1;
C51 COMPILER V8.08 PCF8583 01/23/2008 14:09:39 PAGE 3
102 2 if( SDA ) RetByte++;
103 2 }
104 1 SCL="0";
105 1 _nop_();
106 1 _nop_(); /* return with SCL low, SDA high */
107 1 SDA="1";
108 1 return RetByte;
109 1 }
110
111 void Shout( char Byte ) //输出一个字节
112 { /* Send one byte to EEPROM */
113 1 /* most significant */
114 1 char i;
115 1 for(i="0";i<8;i++)
116 1 {
117 2 SCL="0";
118 2 _nop_();
119 2 if( Byte&0x80 ) SDA="1";
120 2 else SDA="0";
121 2 _nop_();
122 2 _nop_();
123 2 _nop_();
124 2 _nop_();
125 2 Byte<<=1;
126 2 SCL="1";
127 2 _nop_();
128 2 _nop_();
129 2 _nop_();
130 2 _nop_();
131 2 _nop_();
132 2 }
133 1 SCL="0";
134 1 _nop_();
135 1 _nop_();
136 1 SDA="1"; /* return with SCL low , SDA high */
137 1 }
138
139 char TestAck()//应答信号
140 {
141 1 char rf="0"; /* return flag */
142 1 SCL="0";
143 1 _nop_();
144 1 SDA="1"; /* release SDA */
145 1 _nop_();
146 1 SCL="1";
147 1 _nop_();
148 1 _nop_();
149 1 _nop_();
150 1 _nop_();
151 1 _nop_();
152 1 if( SDA==1 ) rf="1"; /* Acknowledge bit is invalid*/
153 1 else rf="0";
154 1 SCL="0";
155 1 _nop_();
156 1 SDA="1"; /* return with SCL low, and SDA high*/
157 1 }
158
159 char RandomRead( char DeviceAddr, char ByteAddr )
160 {
161 1 char rc="0";
162 1 Start();
163 1 Shout( DeviceAddr&0xFE ); /* send device address & write command */
C51 COMPILER V8.08 PCF8583 01/23/2008 14:09:39 PAGE 4
164 1 if( !TestAck() )
165 1 {
166 2 Shout( ByteAddr ); /* send byte address to read */
167 2 if( !TestAck() )
168 2 {
169 3 Start();
170 3 Shout( DeviceAddr|0x01 ); /* send read command */
171 3 if( !TestAck() )
172 3 rc="Shin"();
173 3 TestAck();
174 3 }
175 2 }
176 1 Stop();
177 1 return rc;
178 1 }
179
180
181 char SRead( char DeviceAddr, char ByteAddr, char ByteNum, char ReadBuf[] )
182 {
183 1 char i;
184 1 Start();
185 1 Shout( DeviceAddr&0xFE );
186 1 if( !TestAck() )
187 1 {
188 2 Shout( ByteAddr );
189 2 if( !TestAck() )
190 2 {
191 3 Start();
192 3 Shout( DeviceAddr|0x01 );
193 3 if( !TestAck() )
194 3 for(i="0";i{
195 4 ReadBuf[i]=Shin();
196 4 SCL="0";
197 4 _nop_();
198 4 _nop_();
199 4 SDA="0";
200 4 _nop_();
201 4 _nop_();
202 4 SCL="1";
203 4 _nop_();
204 4 _nop_();
205 4 _nop_();
206 4 _nop_();
207 4 _nop_();
208 4 SCL="0";
209 4 _nop_();
210 4 SDA="1";
211 4 }
212 3 ReadBuf[i]=Shin();
213 3 TestAck();
214 3 }
215 2 }
216 1 Stop();
217 1 }
218
219 void RandomWrite( char DeviceAddr, char ByteAddr, char Byte)
220 {
221 1 Start();
222 1 Shout( DeviceAddr&0xFE ); /* write command */
223 1 if( !TestAck() )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -