Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to write a code for real time clock for keil software C prog?

Status
Not open for further replies.

froggy_lim88

Newbie level 3
Joined
Jun 30, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
hi,
i'm doing a project to display the real time clock using rabbit board thru Ithernet time. I would like to know how write. i have problem in writing it. thank u.

TF0=0;
TH0=0xf0
TL0=0x5c;
SCON = 0x50; // mode 1, 8-bit uart, enable receiver
TMOD= 0x21; //Turn timer 1 mode 2.
TH1 = 0XFA; // for 9600 baud rate 0XFD


void gettingtime()
{
if(i==0x7f)// Waiting for the 011111111 to come in as a start signal.
{
count3=0;
}
if(count3==87)// after recieved the start signal. wait for 0.2 sec to the the 1st digit.
{
dig4=i;
}
if(count3==125) //second digit.
{
dig3=i;
}
if(count3==250) //Third digit
{
dig2=i;
}
if(count3==312) // forth digit
{
dig1=i;
}

}
 

You forgot to mention the mcu you are using

Alex
 

    V

    Points: 2
    Helpful Answer Positive Rating
if it is any 8051 generic controller then see this thread
https://www.edaboard.com/threads/170912/
or see my code using p89v51rd2bn controller (8051)


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#include<reg51.h>
#include<intrins.h>
 
sbit rs=P0^0;
sbit en=P0^1;
 
sbit sda=P3^6;
sbit scl=P3^7;
 
unsigned char rtc_adr[8]={0x00,0x01,0x02,0x03,0x04,0x05,0x06};
unsigned char rtc_dat[8]={0x20,0x58,0x23,0x05,0x31,0x12,0x03};
unsigned char dis[7]={0x20,0x20,0x28,0x08,0x0c,0x06,0x80};
unsigned char a,b,c,d;
 
void strt_bt();
void stp_bt();
void dta_wr();
void dta_rd(); 
void cmdwrt();
void datawrt();
void delay();
void rtc_wr();
void rtc_rd();
void display();
 
main()
{
int i;
for (i=0;i<7;i++)
{
a=dis[i];
cmdwrt();
delay();
}
 
P0=0x00;
 
for(i=0;i<8;i++)
{
b=rtc_adr[i];
c=rtc_dat[i];
rtc_wr();
}
 
while(1)
{
a=0x80;
cmdwrt();
delay();
 
b=0x04; //date
rtc_rd();
display();
 
a='/';
datawrt();
delay();
 
b=0x05; //month
rtc_rd();
display();
 
a='/';
datawrt();
delay();
 
b=0x06; //yr
rtc_rd();
display();
 
a='-';
datawrt();
delay();
 
b=0x03; //week
rtc_rd();
display();
 
a=0xc0;
cmdwrt();
delay();
 
b=0x02; //hr
rtc_rd();
display();
 
a=':';
datawrt();
delay(); 
 
b=0x01; //min
rtc_rd();
display();
 
a=':';
datawrt();
delay();
 
b=0x00; //sec
rtc_rd();
display();
}
 
}
 
void rtc_wr()
{
strt_bt(); //write
 
a=0xd0;
dta_wr();
 
a=b;
dta_wr();
 
a=c;
dta_wr();
 
stp_bt();
delay();
}
 
void rtc_rd()
{
strt_bt(); //dummy write
 
a=0xd0;
dta_wr();
 
a=b;
dta_wr();
 
strt_bt(); //read
 
a=0xd1;
dta_wr();
 
dta_rd();
 
 
/* sda=1;
scl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
 
scl=0;
*/
stp_bt();
delay();
}
 
void strt_bt()
{
sda=1;
scl=1;
_nop_();
_nop_();
sda=0;
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;
_nop_();
_nop_();
}
 
void stp_bt()
{
//scl=0;
sda=0;
scl=1;
_nop_();
_nop_();
//_nop_();
//_nop_();
//_nop_();
sda=1;
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;
_nop_();
_nop_();
_nop_();
_nop_();
scl=1;
}
 
void dta_wr()
{
int j;
char m;
m=a;
sda=1;
for(j=0;j<8;j++)
{
a=m;
a=a & 0x80;
if(a==(0x80))
sda=1;
else 
sda=0;
scl=1;
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;
m=m<<1;
}
 
sda=1;
scl=1;
_nop_();
_nop_();
_nop_();
_nop_();
 
scl=0;
delay();
}
 
void dta_rd() 
{
int j;
int c=0,b;
sda=1;
for(j=0;j<8;j++)
{
a=a<<1;
scl=1;
c=sda;
if(c)
b=0x01;
else
b=0x00;
scl=0;
a=a|b;
}
 
sda=1;
//_nop_();
//_nop_();
//_nop_();
//_nop_();
scl=1;
_nop_();
_nop_();
_nop_(); 
scl=0;
//datawrt();
delay();
}
 
void display()
{
d=a;
a=(a>>4);
a=a & 0x0f;
a=a + 0x30;
datawrt();
delay();
 
a=d;
a=a & 0x0f;
a=a + 0x30;
datawrt();
delay();
}
 
 
void cmdwrt()
{
unsigned char s=0;
s=a;
a=a & 0xf0;
a=a>>2;
rs=0;
P0=a;
rs=0;
en=1;
en=0;
a=s;
a=(a<<4);
a=a & 0xf0;
a=a>>2;
rs=0;
P0=a;
rs=0;
en=1;
en=0;
delay();
}
 
 
void datawrt()
{
unsigned char s=0;
s=a;
a=a & 0xf0;
a=a>>2;
rs=1;
//mdata();
//delay();
P0=a;
rs=1;
en=1;
en=0;
a=s;
a=a<<4;
a=a & 0xf0;
a=a>>2;
rs=1;
//mdata();
P0=a;
rs=1;
en=1;
en=0;
delay();
}
 
 
void delay()
{
int i;
for(i=0;i<1000;i++);
}

 

You forgot to mention the mcu you are using

Alex

Hi alex , wht do you mcu? wht is mcu?

---------- Post added at 00:19 ---------- Previous post was at 00:15 ----------

hi,
my hardware is using rabbit board. not i2c hardware
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top