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.

RTC-DS1307 with 8051+embedded issues

Status
Not open for further replies.

adhiteev

Newbie level 3
Joined
Nov 6, 2006
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,329
ds1307 application

Hiii,
I am working on a board which has the RTC and working with AT89s52 chip. I downloaded some sample codes from the net for RTC but could get anyting which works.
have any of you come across any RTC code which works?

Thanks
Adhiteev
 

ds1307 application note

For Ds1307, the exact code of 24C0x (the I2C eeprom) works perfectly. Both are I2C devices.
 
ds1307 with 8051

Check out this application note:

"Interfacing the DS1307 with an 8051-Compatible Microcontroller"
**broken link removed**

Regards,
IanP
 
  • Like
Reactions: ramina

    ramina

    Points: 2
    Helpful Answer Positive Rating
ds1307+8051

Hi,
I have program for read and write data to ds1307. Use keil complier.
Best regard.
 

application note ds1307

NguyenHai said:
Hi,
I have program for read and write data to ds1307. Use keil complier.
Best regard.

Thank you so much NguyenHai..

but i want it in ASM language.

can you help me please...

Thanks again..
 

Re: ds1307+8051

[what is XTAL for ds1307 in ur code.i think it is working but the time calculation is not exact.
 

RTC-DS1307 with 8051

the application note link mentioned above does not work in my case...any ideas? the controller just resets after i press 'a' from the keyboard... i cant seem to figure out the problem. I am getting all the the serial communication routines right as i can see all text which says...'press a to set the time'....anyone has used this code of the application note???
 

Re: RTC-DS1307 with 8051

first i want to know that the value of RTC where r u displaying in lcd/seven segment.
i have the perfect code of RTC interfacing and display on lcd.
but the code is in c.
 

RTC-DS1307 with 8051

Hi i m MURUGAPANDIYAN.N , I want embedded debugging issues for RTC DS1307 interface with 89S51 microcontroller project for interview purpose with solutions. Please reply me as soon as possible
 

Re: RTC-DS1307 with 8051

Dear Freind..
can u give me that particular code in C...i have similar project based on 8051-XTAl 11.0592,DS1307 and lcd...can u give me ..pls as i m tired up from one week..no code is working provided on the net...i hope ur code will work.,.
 

Re: RTC-DS1307 with 8051

Dear Freind..
can u give me that particular code in C...i have similar project based on 8051-XTAl 11.0592,DS1307 and lcd...can u give me ..pls as i m tired up from one week..no code is working provided on the net...i hope ur code will work.,.

Post your circuit and code, we can solve it..
 


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++);
}

 
Re: RTC-DS1307 with 8051

first i want to know that the value of RTC where r u displaying in lcd/seven segment.
i have the perfect code of RTC interfacing and display on lcd.
but the code is in c.

Dear Friend,
if you have c code for DS1307+8051+lcd then can u post your code ?
 

Dear ckshivaram...i found this code really useful to start with DS 1307...
there is just one thing i need to ask...has this code been tested on board...and what XTAL was used for the microcontroller..
I am going to use 89S51 microcontroller and 11.0592 MHz crystal frequency as i even need the serial communication for the requirement

---------- Post added at 20:16 ---------- Previous post was at 20:14 ----------


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++);
}




Dear ckshivaram...i found this code really useful to start with DS 1307...
there is just one thing i need to ask...has this code been tested on board...and what XTAL was used for the microcontroller..
I am going to use 89S51 microcontroller and 11.0592 MHz crystal frequency as i even need the serial communication for the requirement..can u even give me the circuit diagram for this..
Thanks
Shabaz
 
Thanks to give the code
i request to u that pls upload the ckt diagram also
thanks
 

sda is P3^6 and scl are conected to P3^7.
lcd rs pin is P0^0;
lcd en pin is P0^1;
lcd data pins are connected to P0.2, 0.3, 0.4, 0.5 with a pull up resistor of 10k for all port pins. RTC will have a crystal oscillator of 32.768KHz .
Hope this is clear to you.
 
Hello Sir . I am new to programming. If i post the program can you help me.. i am doing a project wireless notice board with rtc..

RTC - DS1307
uC-89v51
LCD - 4-bit mode..
 

#include<reg51.h>
#include<ds1307.h>
#include<string.h>

sbit rs=P2^2;
sbit en=P2^3;
sfr ldata=0xA0;
sfr KEYPRT = 0X80;
sbit ROW0 = P0^4;
sbit ROW1 = P0^5;
sbit ROW2 = P0^6;
sbit ROW3 = P0^7;
sbit COL0 = P0^0;
sbit COL1 = P0^1;
sbit COL2 = P0^2;
sbit COL3 = P0^3;
unsigned char KEYGET(void);
void lcdcommnd(unsigned char value);
void lcddata(unsigned char value);
void lcd_putc(unsigned char ascii);
void MSDelay(int ms);
void LcdLine1(unsigned char *value);
void LcdLine2(unsigned char *value);
void send2lcd(unsigned char value);
void welcome();
void PowerOn();


void main()
{
unsigned int y,tens,ones;
unsigned char sec, min, hour, date, month, year;

PowerOn();
lcdcommnd(0X01);
MSDelay(256);

lcdcommnd(0X28);
lcdcommnd(0X01);
lcdcommnd(0X0C);
lcdcommnd(0X06);
lcdcommnd(0X01);

MSDelay(20);
welcome();
MSDelay(20);

MSDelay(20);
lcdcommnd(0X01);
MSDelay(20);
PowerOn();

LcdLine1("1->SET DATE&TIME");
LcdLine2("Any other-> SKIP");
COL0 = 1; // make cols input port
COL1 = 1;
COL2 = 1;
COL3 = 1;
y = KEYGET();
lcdcommnd(0x01); // Clear Command
MSDelay(20);
lcddata(y);
MSDelay(20);
if (y == '1')
{

lcdcommnd(0x01); // Clear Command
MSDelay(20);
PowerOn();

LcdLine1("HR:MN:SC");

////////////////hour/////////////////////
y = KEYGET();
tens = y & 0x0F;
tens = (tens << 4) & 0xF0;
lcdcommnd(0XC0);
lcddata(y);

y = KEYGET();
ones = y & 0x0F;
lcdcommnd(0XC1);
lcddata(y);

hour = (tens |ones );
lcdcommnd(0XC2);
lcddata(':');

////////////////min/////////////////////

y = KEYGET();
tens = y & 0x0F;
tens = (tens << 4) & 0xF0;
lcdcommnd(0XC3);
lcddata(y);

y = KEYGET();
ones = y & 0x0F;
lcdcommnd(0XC4);
lcddata(y);

min = (tens |ones );
lcdcommnd(0XC5);
lcddata(':');

////////////////sec/////////////////////

y = KEYGET();
tens = y & 0x0F;
tens = (tens << 4) & 0xF0;
lcdcommnd(0XC6);
lcddata(y);

y = KEYGET();
ones = y & 0x0F;
lcdcommnd(0XC7);
lcddata(y);

sec = (tens |ones );

///////////////////////////////////////
MSDelay(20);
////////////////////////////////////////////
lcdcommnd(0x01); // Clear Command
MSDelay(20);

LcdLine1("DD:MM:YY");


////////////////date/////////////////////
y = KEYGET();
tens = y & 0x0F;
tens = (tens << 4) & 0xF0;
lcdcommnd(0XC0);
lcddata(y);

y = KEYGET();
ones = y & 0x0F;
lcdcommnd(0XC1);
lcddata(y);

date = (tens |ones );
lcdcommnd(0XC2);
lcddata(':');

//////////////////month/////////////////
y = KEYGET();
tens = y & 0x0F;
tens = (tens << 4) & 0xF0;
lcdcommnd(0XC3);
lcddata(y);

y = KEYGET();
ones = y & 0x0F;
lcdcommnd(0XC4);
lcddata(y);

month = (tens |ones );
lcdcommnd(0XC5);
lcddata(':');


///////////////////////////////////////
//////////////////year/////////////////
y = KEYGET();
tens = y & 0x0F;
tens = (tens << 4) & 0xF0;
lcdcommnd(0XC6);
lcddata(y);

y = KEYGET();
ones = y & 0x0F;
lcdcommnd(0XC7);
lcddata(y);

year = (tens |ones );

///////////////////////////////////////


/////////////////////////////////////////
MSDelay(20);
lcdcommnd(0x01); // Clear Command
MSDelay(200);


LcdLine1("Date:");
LcdLine2("Time:");

PowerOn();

DS1307_settime(hour,min,sec); /* Set Time (hh:mm:ss) */

DS1307_setdate(date,month,year); /* Set Date (dd/mm/yy) */

MSDelay(200);


}


lcdcommnd(0x01); // Clear Command

PowerOn();

LcdLine1("Date:");
LcdLine2("Time:");

IE = 0x90; // enable interrupt for serial communication

while(1)
{
lcdcommnd(0X01);
MSDelay(20);
/////////////////////////////rtc///////////////////////////////
PowerOn();

LcdLine1("Date:");
LcdLine2("Time:");

/* Get Date & Time */
sec = DS1307_get(0X00);
min = DS1307_get(0X01);
hour = DS1307_get(0X02);
date = DS1307_get(0X04);
month = DS1307_get(0X05);
year = DS1307_get(0X06);

/* Show Date in format dd/mm/yr */
lcdcommnd(0x85); /* Set LCD cursor at (1,6) */

send2lcd(date); /* Show date on LCD */

lcd_putc('/');

send2lcd(month); /* Show month on LCD */

lcd_putc('/');

send2lcd(year); /* Show year on LCD */

/* Show Time in format hr:min:sec */
lcdcommnd(0xC5); /* Set LCD cursor at (2,6) */

send2lcd(hour); /* Show hour on LCD */

lcd_putc(':');

send2lcd(min); /* Show min on LCD */

lcd_putc(':');

send2lcd(sec); /* Show sec on LCD */

MSDelay(200);
}
}

void lcdcommnd(unsigned char value)
{
rs=0;
ldata=((ldata & 0x0f) | (value & 0X0F0));
en=1;
MSDelay(5);
en=0;
MSDelay(5);
ldata=((ldata & 0x0f) | (value<<4 & 0X0F0));
en=1;
MSDelay(5);
en=0;
MSDelay(5);
}

void lcddata(unsigned char value)
{


rs=1;
ldata=((ldata & 0x0f) | (value & 0X0F0));
en=1;
MSDelay(5);
en=0;
MSDelay(5);
ldata=((ldata & 0x0f) | (value<<4 & 0X0F0));
en=1;
MSDelay(5);
en=0;
MSDelay(5);
}

void lcd_putc(unsigned char ascii)
{
rs = 1; /* Set bit P2.5 */

ldata = (ldata & 0x0F)|((ascii) & 0x0F0);
en=1;
MSDelay(5);
en=0;
MSDelay(5);
ldata = (ldata & 0x0F)| ((ascii <<4) & 0x0F0);
en=1;
MSDelay(5);
en=0;
MSDelay(5);

}

void MSDelay(int ms)
{
unsigned int i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<921;j++);
}
}

void LcdLine1(unsigned char *value)
{
int i,value1,len;
len=strlen(value);
lcdcommnd(0x80);
for(i=0;i<len;i++)
{
value1=value;
lcddata(value1);
}
}
void LcdLine2(unsigned char *value)
{
int i,value1,len;
len=strlen(value);
lcdcommnd(0x0C0);
for(i=0;i<len;i++)
{
value1=value;
lcddata(value1);
}
}

void send2lcd(unsigned char value)
{
unsigned char buf = 0;

buf = value & 0xF0; /* Filter for high byte */
buf = (buf>>4)|(0x30); /* Convert to ascii code */

lcddata(buf);
MSDelay(5); /* Show on LCD */

buf = value & 0x0F; /* Filter for low byte */
buf = buf | 0x30; /* Convert to ascii code */

lcddata(buf);
MSDelay(5); /* Show on LCD */
}



unsigned char KEYGET()
{
unsigned char colloc, rowloc, keyvalue;
unsigned char keypad[4] [4] = {'0', '1', '2','3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F'};



do
{
ROW0 = 0;
ROW1 = 0;
ROW2 = 0;
ROW3 = 0; // ground all rows
colloc = KEYPRT; // read port0
colloc &= 0x0F; //mask used bits
} while ( colloc != 0X0F); // check until all keys released


do
{ do
{
MSDelay(5);
colloc = KEYPRT; // read port0
colloc &= 0x0F; //mask used bits
} while ( colloc == 0X0F); //keep checking for keypress

MSDelay(5); //delay for debounce
colloc = KEYPRT; // read port0
colloc &= 0x0F; //mask used bits
} while ( colloc == 0X0F); //keep checking for keypress

while (1)

{
ROW0 = 0; // ground row0
ROW1 = 1;
ROW2 = 1;
ROW3 = 1;
colloc = KEYPRT; // read port0
colloc &= 0x0F; //mask used bits
if( colloc!=0x0F)
{
rowloc = 0;
break;
}

ROW0 = 1; // ground row1
ROW1 = 0;
ROW2 = 1;
ROW3 = 1;
colloc = KEYPRT; // read port0
colloc &= 0x0F; //mask used bits
if( colloc!=0x0F)
{
rowloc = 1;
break;
}

ROW0 = 1; // ground row2
ROW1 = 1;
ROW2 = 0;
ROW3 = 1;
colloc = KEYPRT; // read port0
colloc &= 0x0F; //mask used bits
if( colloc!=0x0F)
{
rowloc = 2;
break;
}

ROW0 = 1; // ground row3
ROW1 = 1;
ROW2 = 1;
ROW3 = 0;
colloc = KEYPRT; // read port0
colloc &= 0x0F; //mask used bits
rowloc = 3;
break;
}


if( colloc ==0x0E)
keyvalue = keypad [rowloc] [0];
else if ( colloc ==0x0D)
keyvalue = keypad [rowloc] [1];
else if ( colloc ==0x0B)
keyvalue = keypad [rowloc] [2];
else
keyvalue = keypad [rowloc] [3];
return (keyvalue);
}

void welcome()
{

lcdcommnd(0X01);
MSDelay(25);
LcdLine1(" WELCOME ");

}

void PowerOn()
{
unsigned char inner, outer;

for (outer = 0x00; outer < 0x10; outer++)
{
for (inner = 0x00; inner < 0xFF; inner++);
}


for (inner = 0; inner < 10; inner++)
MSDelay(2);
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top