|
|
View previous topic :: View next topic |
Author |
Message |
nina
Joined: 20 Apr 2007 Posts: 111
|
glcd+rtc |
Posted: Wed Mar 25, 2009 10:48 am |
|
|
When I simulate this code on Proteus, the variable secs count seconds but it doesn't erase the last value. I mean, it count 00 and 01 it is written over 00.
How can I solve this?
tks
nina
Code: | #include <16F877.h>
#use delay(clock=4000000)
#include <glcd.c>
#include <ds1307.c>
void main()
{
byte hora,min,sec;
int status = 1;
char secs[8];
init_ds1307();
sec=write_ds1307(0,0x00);
delay_ms(100);
glcd_init(ON);
glcd_fillScreen(OFF);
while(TRUE){
sec=read_ds1307(0);
sprintf(secs, "%X", (byte)sec); // Converts sec to text
glcd_text57(1, 1, secs, 1, ON);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 25, 2009 3:19 pm |
|
|
Think about the problem. If a write-character routine is overlaying new
characters on top of existing characters, what can you do about it ?
Think. You would want to erase the old character before you write a
new one. How can you do that ? I can think of at least two ways.
What character could you write over the old one to erase it ?
What character would erase all other characters, if you write it on
top of an existing character ?
Or, what option does the glcd_text57() routine have (as a parameter),
to change the color of the character dots ? How can this option be
used to erase a previous character ? |
|
|
nina
Joined: 20 Apr 2007 Posts: 111
|
glcd+rtc |
Posted: Wed Mar 25, 2009 6:59 pm |
|
|
PCM programmer..
thank you for your comments...I tried to do this, but now secs keep blinking...
Code: | #include <16F877.h>
#use delay(clock=4000000)
#include <glcd.c>
#include <ds1307.c>
void main()
{
byte hora,min,sec;
int status = 1;
char secs[8];
init_ds1307();
sec=write_ds1307(0,0x00);
delay_ms(100);
glcd_init(ON);
glcd_fillScreen(OFF);
while(TRUE){
sec=read_ds1307(0);
sprintf(secs, "%X", (byte)sec); // Converts sec to text
glcd_text57(15, 15, secs, 1, ON);
glcd_text57(15, 15, secs, 1, OFF);
}
} |
|
|
|
PICoHolic
Joined: 04 Jan 2005 Posts: 224
|
|
Posted: Thu Mar 26, 2009 5:49 am |
|
|
try this:
Code: |
#include <16F877.h>
#use delay(clock=4000000)
#include <glcd.c>
#include <ds1307.c>
void main()
{
byte hora,min,sec;
int status = 1;
char secs[8] = {0};
init_ds1307();
sec=write_ds1307(0,0x00);
delay_ms(100);
glcd_init(ON);
glcd_fillScreen(OFF);
while(TRUE){
sec=read_ds1307(0);
glcd_text57(15, 15, secs, 1, OFF);
sprintf(secs, "%X\0", (byte)sec); // Converts sec to text
glcd_text57(15, 15, secs, 1, ON);
delay_ms(1000);
}
}
|
|
|
|
nina
Joined: 20 Apr 2007 Posts: 111
|
|
Posted: Thu Mar 26, 2009 6:57 am |
|
|
PICoHolic...
I tried do this but the problem was time is not right because of delay.
That is the point...I thought do this way...
Do you have another way to solve this problem?
I want to display hour, min, sec
tks
nina |
|
|
PICoHolic
Joined: 04 Jan 2005 Posts: 224
|
|
Posted: Thu Mar 26, 2009 7:05 am |
|
|
Quote: |
I tried do this but the problem was time is not right because of delay.
|
The delay_ms(1000) is just for the display. The 1 second timing is coming from your DS1307 RTC.
I suggest that you feed the output of the DS1307 (1 sec clock) into one of your external interrupts and then update your display accordingly.
Good Luck |
|
|
nina
Joined: 20 Apr 2007 Posts: 111
|
glcd |
Posted: Thu Mar 26, 2009 7:23 am |
|
|
but if i have a delay_ms(1000) inside a while loop and inside of this while loop I get reading from ds1307, so for sure I will have a delay between the real time( from ds1307) and the reading of ds1307.
tks again
nina |
|
|
PICoHolic
Joined: 04 Jan 2005 Posts: 224
|
|
Posted: Thu Mar 26, 2009 7:39 am |
|
|
Yes, but not that important...
Anyway if you insist on having it in a loop inside your main, try this out:
Code: |
#include <16F877.h>
#use delay(clock=4000000)
#include <glcd.c>
#include <ds1307.c>
void main()
{
byte hora,min,sec, old_sec = 0xFF;
int status = 1;
char secs[8] = {0};
init_ds1307();
sec=write_ds1307(0,0x00);
delay_ms(100);
glcd_init(ON);
glcd_fillScreen(OFF);
while(TRUE){
sec=read_ds1307(0);
if (old_sec != sec) {
glcd_text57(15, 15, secs, 1, OFF);
sprintf(secs, "%X\0", (byte)sec); // Converts sec to text
glcd_text57(15, 15, secs, 1, ON);
old_sec = sec;
}
}
}
|
|
|
|
nina
Joined: 20 Apr 2007 Posts: 111
|
gldc+rtc |
Posted: Thu Mar 26, 2009 12:49 pm |
|
|
very nice...it is working..
Thanks you very much PICoHolic
Nina |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|