free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Go to page  [1] 2
Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
AnupamAttri
Tue Apr 15 2008, 03:11AM

 User Offline
Registered Member #7182
Joined: Sat Apr 12 2008, 02:43AM

Posts: 15
Thanked 0 times in 0 posts
Hello Ajay,
I learnt from your info page that u are from Khanna, Punjab.
I am checking Port status by multi-meter. I checked by LED also. Results were very abrupt. Sometimes, P1.4 did not light LED whereas P1.5, P1.6, P1.7 lighted LED. Sometimes, none lighted. Sometimes, all lighted. Tomorrow, I will try to make an infinite loop by SJMP.
I want to know another thing. Do you have code of digital clock using DS1307 in C also? But, using DS1307 or any other RTC with RAM.

Thanking you in anticipation,
Anupam Attri



[ Edited Tue Apr 15 2008, 04:40AM ]

Thanking you in anticipation,
Anupam Attri
Back to top


AnupamAttri
Tue Apr 15 2008, 03:25PM

 User Offline
Registered Member #7182
Joined: Sat Apr 12 2008, 02:43AM

Posts: 15
Thanked 0 times in 0 posts
Hello Ajay,
I tried the Digital Clock code of C [beta] on hardware. Its working great. There is no problem in display and all and its really great. thanks for this help.
I read the code. Ihave few doubts. Can you help me in them:
Doubt 1: What is the function biuld_ram? what is the significance of 56 in FOR Loop? All Iknow is that RAM size of RTC is 56K.
Function:
void build_ram()
{
bit_8 i;
wrt_cmd(0x40);
for(i=0;i<56;i++)
wrt_byte(cgram[i]);
}

Doubt 2: How is receive_data working? What is the significance of 1d in FOR Loop?

Doubt 3: I found another thing that the alarm is not stored in RTC RAM. It is stored in the RAM of controller. That is, if the power supply fails, then the real time will be retained but not the alarm time. It is to be set again. If it is so, then can you help me in setting the alarm timeing RTC RAM? How to write the two parameters ahour and amin in RTC RAM? And reading from RTC RAM?
Please reply!!


Thanking you in anticipation,
Anupam Attri
Back to top


AnupamAttri
Tue Apr 15 2008, 07:31PM

 User Offline
Registered Member #7182
Joined: Sat Apr 12 2008, 02:43AM

Posts: 15
Thanked 0 times in 0 posts
Hello Ajay,
i have made few changes in the code. This is to store alarm time in RTC RAM... Please see if these changes will storer alarm in RTC RAm and execute accordingly...
Initially, the RTC RAM is configured as
rtc_ini_val[0] -> sec
rtc_ini_val[1] -> min
rtc_ini_val[2] -> hrs
rtc_ini_val[3] -> day
rtc_ini_val[4] -> date
rtc_ini_val[5] -> month
rtc_ini_val[6] -> year
rtc_ini_val[7] -> control register
rtc_ini_val[8] -> '~'//signature byte

Other two RAM locations that I created
rtc_ini_val[9] -> amins
rtc_ini_val[10] -> ahours

For this the changes that I made:
1) static bit_8 rtc_recv_val[11] _at_ 0x30;
static bit_8 rtc_ini_val[11];

2) In rtc_check(void)
Two more additions
rtc_ini_val[9]=0x00;
rtc_ini_val[10]=0x52;

3) In recv_data()
In for Loop, I changed the if statement
if(y<=10) //It was y<=6
//y<=10 to cover whole 10 locations
// rest same

4) In set_alarm()
I commented, //amins=dec_hex(amins);
//ahours=dec_hex(ahours);
I replaced above statements with
rtc_ini_val[9]=dec_hex(amins);
rtc_ini_val[10]=dec_hex(ahours);
if(ampm)
rtc_ini_val[10]+=-x60;
else
rtc_ini_val[10]+=ox40;
RTC_INI();

5) In void check_alarm() //comparing values directly from RTC RAM
if (rtc_ini_val[10]==rtc_recv_val[2])
if (rtc_ini_val[9]==rtc_recv_val[1])
{
aoff=1;
aon=1;
}

Please check these changes. I guess these are sufficient.
Please reply

Thanking you in anticipation,
Anupam Attri
Back to top


Ajay
Wed Apr 16 2008, 05:24AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3745
Thanked 695 times in 654 posts
Sorry for late reply Now lets discuss your doubts...
AnupamAttri wrote ...
Doubt 1: What is the function biuld_ram? what is the significance of 56 in FOR Loop? All Iknow is that RAM size of RTC is 56K.
Function:
void build_ram()
{
bit_8 i;
wrt_cmd(0x40);
for(i=0;i<56;i++)
wrt_byte(cgram[ i ]);
}

the above function is for LCD not RTC. to build special characters..
AnupamAttri wrote ...
Doubt 2: How is receive_data working? What is the significance of 1d in FOR Loop?

1d is used for synchronization.. but only first 7 bytes are being stored as you can see in that loop.

AnupamAttri wrote ...
Doubt 3: I found another thing that the alarm is not stored in RTC RAM. It is stored in the RAM of controller. That is, if the power supply fails, then the real time will be retained but not the alarm time. It is to be set again. If it is so, then can you help me in setting the alarm timeing RTC RAM? How to write the two parameters ahour and amin in RTC RAM? And reading from RTC RAM?

all you need to do is write those values to RTC ram..
i tell you the sequence.. you can do that using the functions available in rtc.c
[ send start ] [ send RTC Addr + Wr ] [ send sub add ] [ send data to write ] [ sequential data if there ] [ send stop ]

Sub address is the address of RTC's internal ram where you want to store data.
sequential data is fed if you have to store more than one byte.. e.g. if you want to store 5 values.. starting from sub address 10H, then first value will go to 10H, second to 11H and so on...

Hope you understand..

[ Edited Wed Apr 16 2008, 05:27AM ]

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


Ajay
Wed Apr 16 2008, 05:55AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3745
Thanked 695 times in 654 posts
regarding changes you made in the program..

rtc_ini_val[9] -> amins
rtc_ini_val[10] -> ahours

The above are not needed.

1) static bit_8 rtc_recv_val[11] _at_ 0x30; // This one is fine....
static bit_8 rtc_ini_val[11]; // Not needed.. keep is same as original..

addtion 2 is not needed either...

addition 3 is fine...

Addition 4 is wrong.. as i explained in my post earlier, you need to send those alarm values separately to RTC ram. RTC_INI function is called only for initialization of RTC.

In addition 5, you need to compare the current time with alarm time..
that would be..
rtc_recv_val[2] with rtc_rcv_val[8]
and
rtc_recv_val[1] with rtc_recv_val[9]

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


AnupamAttri
Thu Apr 17 2008, 01:55AM

 User Offline
Registered Member #7182
Joined: Sat Apr 12 2008, 02:43AM

Posts: 15
Thanked 0 times in 0 posts
Hello Ajay,
Thanks for the reply.
I have understood the answers to doubt 1 & 2. But, answer to doubt 3 ( that is to store alarm in RTC RAM) is not very clear. What I have understood is that the function RTC_INI() in the code of rtc.c is same what you have written:
[ send start ] [ send RTC Addr + Wr ] [ send sub add ] [ send data to write ] [ sequential data if there ] [ send stop ]
It is:
void RTC_INI(void)
{
bit_8 t;
for(t=0;t<9;t++)
{
start_rtc(); //[ send start ] These comments are written by me.
send_adr(0xd0); //[ send RTC Addr + Wr ]
send_adr(t); //[ send sub add ]
send_adr(rtc_ini_val[t]);//[ send data to write ]
stop_rtc(); //[ send stop ]
}
wrt_cmd(0x1);
}

1. Calling function start_rtc();

2. For send_adr(0xd0).
I don't understand how is RTC Addr + Wr is 0xd0 in send_adr(0xd0).

3. For send_adr(t)
I have understood sub add as ranging from 0, 1, 2,... upto 8. total 9.
t=0 -> sec
t=1 -> min
t=2 -> hrs
t=3 -> day
t=4 -> date
t=5 -> month
t=6 -> year
t=7 -> control register
t=8 -> '~'//signature byte

4. send_adr(rtc_ini_val[t])
Data to write are values to be fed at addresses 0x00, 0x01,... upto 0x08. That is sec, min, hrs, day... And, these updated values are stored in rtc_ini_val[t] array.
And, this is sequential data.

5. Calling function stop_rtc();

In nut-shell, I have understood that values of the alarm, that is "ahour" and "amin" are to be stored in rtc_ini_val[t] array (where, t=8 and 9 and taking 10 as '~' signature byte)
rtc_ini_val[8] = ahour;
rtc_ini_val[9] = amin;

Please reply whether what i have understood is correct or not.


Thanking you in anticipation,
Anupam Attri
Back to top


Ajay
Thu Apr 17 2008, 05:56AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3745
Thanked 695 times in 654 posts
i said.. rtc_ini is specially written for initializing RTC..
its not for storing stuff.. this function is called only if needed otherwise not

so write in simple way as mentioned.. no need to call rtc_ini

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


AnupamAttri
Thu Apr 17 2008, 02:28PM

 User Offline
Registered Member #7182
Joined: Sat Apr 12 2008, 02:43AM

Posts: 15
Thanked 0 times in 0 posts
Hi Ajay!
I guess I have disturbed you a lot. I am sorry for that. But, pleasse understand me; I have not understood the syntax
"[ send start ] [ send RTC Addr + Wr ] [ send sub add ] [ send data to write ] [ sequential data if there ] [ send stop ]" completely. That is why i need some example of it to how to do it. I have tried to find one example out of your code only. I guess storing real time in RTC RAM is same as storing alarm time in RTC RAM, except that there are fixed registers of real-time and no register for alarm time. So, I set the example of how real time is set or changd. It is changed by calling the function "rtc_set()". right?
If I am wrong, then please explain me by some example. Please write its code.
If I am right till here, then I would like to highlight how this function works (as per my understanding.).
1.Values of min, hr, etc. are received from RTC and stroed in 8051 RAM in rtc_recv_val[t] array.
2.Values are processed and changed by setting temperory variables like hour, min, month, etc.
3.Once set, values of variables hour, min, etc are stored back into array rtc_recv_val[t].
4. Finally, RTC_INI() function is called. This function sets the values in the RTC RAM again.
Actually, initial values are set by calling the function rtc_check(). rtc_check() calls the function RTC_INI().
I have linked my 4 points with the function example below.
If you see function rtc_set().
rtc_set()
{
mins = hex_dec(rtc_recv_val[1]);// 1.fetching data from RTC RAM
// 2.Then follows the function of setting the variables or mins. I have omitted the in-between statements.
rtc_ini_val[1] = dec_hex(mins);// 3.storing back the variable to array
rtc_ini_val[2] = dec_hex(hours);
RTC_INI();//4.Calling RTC_INI(). This again sets the RTC RAM
wrt_cmd(1);//Then follws the function of LCD
}

If I wrong, then please explain me by some example. I have not understood the syntax.


Thanking you in anticipation,
Anupam Attri
Back to top


AnupamAttri
Thu Apr 17 2008, 07:18PM

 User Offline
Registered Member #7182
Joined: Sat Apr 12 2008, 02:43AM

Posts: 15
Thanked 0 times in 0 posts
Hello Ajay,
I checked the hardware. There are few bugs in the code.
1. In the display, it never displays PM. It always displays AM, whether it is AM or PM? I checked the code then, I found that statement
if(((rtc_recv_val[2])&20)==20)
wrt_data(pmam[1]);
else
wrt_data(pmam[0]);
is wrong. It will always jump to else because in hex 24 is 18. There is no point of 0x20. So, I wrote statement
if(((rtc_recv_val[2]+0x14)&20)==20)

wrt_data(pmam[1]);
else
wrt_data(pmam[0]);
This adds 14 hex.
When tried this on hardware, then it displayed PM, but results were not satisfactory.

2. Another bug is that the alarm doesn't work. Even when set, control doesn't move to alarm function. I tried this using CRO. The state of P1.4 didn't change.
When you implemented this on hardware, then was alarm working?

If you find solution to above two problems, then please reply.
By the way, can you find some time to chat with me. please tell me when can this be possible.
Thank you!!!1

Thanking you in anticipation,
Anupam Attri
Back to top


AnupamAttri
Fri Apr 18 2008, 01:47AM

 User Offline
Registered Member #7182
Joined: Sat Apr 12 2008, 02:43AM

Posts: 15
Thanked 0 times in 0 posts
Hello Ajay,
I compared your C[beta] code with assembly language code. There what you have done is ANDing hour with 20hex and then comparing it with 00hex and not 20 hex. If one writes in C, then it would be:
if((rtc_recv_val[2]&20)==00)// This statement was: if(((rtc_recv_val[2])&20)==20)
{
wrt_data(pmam[1]);
else
wrt_data(pmam[0]);
}

Although I don't understand the logic of comparing with 00hex directly without any prior addition, but i checked your asm code on hardware and it was bug-free with respect to AM-PM error.
But, please see for alarm. Although I could not fine any bug; logic seems to be correct, but alarm didn't work.
Please see my previous posts for RTC RAM problem. Please explain me it as you have stored Real Time.

Thanking you in anticipation,
Anupam Attri
Back to top


Go to page  [1] 2  

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems