Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

DS1302 / LCD / Codevision

DS1302 / LCD / Codevision

2005-03-03 by Richard Reeves

Hi folks,
I have a student using Codevision to pull the date and time from a 
DS1302 RTC and display it on an LCD, as well as use the data as 
integer values to calculate sunrise and sunset.

Now, I'm not much of a C programmer, and the results we're getting 
look a bit odd.  Now, the code is at work and I'm not, but what we're 
trying is:

char hrs[3];
char mins[3];
char sec[3];
int second;

//Timer1 interrupt every second
{
//This was one way:
rtc_get_time(hrs,mins,sec);
lcd_gotoxy(0,0);
lcd_puts(sec);
}

We also tried reading the bytes individually with 
second=DS1302_read(0xNN); //Can't remember address
second=bin2hex(second);
//Convert to string and dislpay
itoa(second,sec);
lcd_gotoxy(0,0);
lcd_puts(sec);

Now, we get odd values for everything - could someone please tell me 
(an assembler man) where we're going wrong?


Thanks!




Richard
---
"Iz dana u dan ona dolazi i odlazi u talasima"
   http://www.van-gogh.co.yu/

Re: [AVR-Chat] DS1302 / LCD / Codevision

2005-03-03 by Richard Reeves

Svenn:
> The contents of the time and calendar register in DS1302 ar in BCD format.
> 23sec are 0x23, and not 0x17...
Yes, sorry, I typed the wrong thing in my original email (the code is at
work and I was at home.)  We were using:

second=DS1302_read(0xNN); //Can't remember address
second=bcd2bin(second)
//Convert to string and dislpay
itoa(second,sec);
lcd_gotoxy(0,0);
lcd_puts(sec);

Now, if I convert it from BCD to binary and read it out, it should, in the
case of the seconds counter, get to 59 and roll over to 0, but doesn't. 
In fact, it doesn't give sensible numbersat all...

It's very confusing to say the least.  If I retrieve a BCD value, and use
bcd2bin (as we need an int for calculations), surely creating a string
from it to display should work.

Any help is much appreciated.


Richard
-- 
Na vratima raja, ja savijam krila...
http://www.van-gogh.co.yu

Re: [AVR-Chat] DS1302 / LCD / Codevision

2005-03-03 by Svenn Dahlstrøm

The contents of the time and calendar register in DS1302 ar in BCD format.
23sec are 0x23, and not 0x17...
Se datasheet 'Register Address/Definition' (Table 2, page 8 in my datasheet)

Svenn
Show quoted textHide quoted text
>
> Hi folks,
> I have a student using Codevision to pull the date and time from a
> DS1302 RTC and display it on an LCD, as well as use the data as
> integer values to calculate sunrise and sunset.
>
> Now, I'm not much of a C programmer, and the results we're getting
> look a bit odd.  Now, the code is at work and I'm not, but what we're
> trying is:
>
> char hrs[3];
> char mins[3];
> char sec[3];
> int second;
>
> //Timer1 interrupt every second
> {
> //This was one way:
> rtc_get_time(hrs,mins,sec);
> lcd_gotoxy(0,0);
> lcd_puts(sec);
> }
>
> We also tried reading the bytes individually with
> second=DS1302_read(0xNN); //Can't remember address
> second=bin2hex(second);
> //Convert to string and dislpay
> itoa(second,sec);
> lcd_gotoxy(0,0);
> lcd_puts(sec);
>
> Now, we get odd values for everything - could someone please tell me
> (an assembler man) where we're going wrong?
>
>
> Thanks!
>
>
>
>
> Richard
> ---
> "Iz dana u dan ona dolazi i odlazi u talasima"
>   http://www.van-gogh.co.yu/
>
>
>
> Yahoo! Groups Links
>
>
>
>

Re: [AVR-Chat] DS1302 / LCD / Codevision

2005-03-03 by Svenn Dahlstrøm

Things to check :
1-Reading of data is done at SCLK falling edge, and starts with the first 
falling edge after last rising edge at write adr/command...

2-Delay from clock falling edge unthil you read the data input...

Svenn
Show quoted textHide quoted text
>
> Svenn:
>> The contents of the time and calendar register in DS1302 ar in BCD 
>> format.
>> 23sec are 0x23, and not 0x17...
> Yes, sorry, I typed the wrong thing in my original email (the code is at
> work and I was at home.)  We were using:
>
> second=DS1302_read(0xNN); //Can't remember address
> second=bcd2bin(second)
> //Convert to string and dislpay
> itoa(second,sec);
> lcd_gotoxy(0,0);
> lcd_puts(sec);
>
> Now, if I convert it from BCD to binary and read it out, it should, in the
> case of the seconds counter, get to 59 and roll over to 0, but doesn't.
> In fact, it doesn't give sensible numbersat all...
>
> It's very confusing to say the least.  If I retrieve a BCD value, and use
> bcd2bin (as we need an int for calculations), surely creating a string
> from it to display should work.
>
> Any help is much appreciated.
>
>
> Richard
> -- 
> Na vratima raja, ja savijam krila...
> http://www.van-gogh.co.yu
>
>
>
>
> Yahoo! Groups Links
>
>
>
>

RE: [AVR-Chat] DS1302 / LCD / Codevision

2005-03-03 by Javier Fiasche

Here goes some routines i am using and work


// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x1B
#endasm
#include <lcd.h>

// DS1302 Real Time Clock functions
#asm
   .equ __ds1302_port=0x12
   .equ __ds1302_io=2
   .equ __ds1302_sclk=3
   .equ __ds1302_rst=4
#endasm
#include <ds1302.h>
#define rtc_run()    ds1302_write(0x80,0x00)
void main()
{
 unsigned char hora=20 , min=10 , seg=0x00, dia=4,mes=2,ano=5;

   init_mega32();
   lcd_init(20);    // LCD module initialization
   lcd_clear();

     rtc_init(0,1,0);   // DS1302 Real Time Clock initialization
     rtc_set_time(hora,min,seg);
     rtc_set_date(dia,mes,ano);
     rtc_run();
      while (1)
         }
        delay_ms(100);
        rtc_ver_time(0,1);
        rtc_ver_date(9,1);
          };
}


/*--------------------------------------------------------------------------
----------
void rtc_ver_date(const unsigned char x, constunsigned char y);

Convierte el formato de fecha del RTC a caracteres(dd:mm:aa) y lo imprime en
el
Lcd a partir de la direccion (x,y)
----------------------------------------------------------------------------
---------*/

void rtc_ver_date( const unsigned char x, const unsigned char y)
{    unsigned char dia, mes,ano;
 unsigned char buffer[4];
 lcd_gotoxy(x,y);
 rtc_get_date(&dia,&mes,&ano);
 itoa(dia,buffer);
 if(dia<10)lcd_putchar('0');
 lcd_puts(buffer);
 lcd_putchar('/');
 itoa(mes,buffer);
 if(mes<10)lcd_putchar('0');
 lcd_puts(buffer);
 lcd_putchar('/');
 itoa(ano,buffer);
 if(ano<10)lcd_putchar('0');
 lcd_puts(buffer);
}

/*--------------------------------------------------------------------------
----------
void rtc_ver_time(const unsigned char x, constunsigned char y);

Convierte el formato de hora del RTC a caracteres(hh:mm:ss) y lo imprime en
el
Lcd a partir de la direccion (x,y)
----------------------------------------------------------------------------
---------*/
void rtc_ver_time( const unsigned char x, const unsigned char y)
{
 unsigned char buffer[4];
 unsigned char hora, min, seg;
     lcd_gotoxy(x,y);
     rtc_get_time(&hora,&min,&seg);
     itoa(hora,buffer);
     if(hora<10)lcd_putchar('0');
 lcd_puts(buffer);
 lcd_putchar(':');
 itoa(min,buffer);
 if(min<10)lcd_putchar('0');
 lcd_puts(buffer);
 lcd_putchar(':');
 itoa(seg,buffer);
 if(seg<10)lcd_putchar('0');
 lcd_puts(buffer);
}



Hope it helps, its working, but rtc_verdate and time are a little "badly
optimized"

Javier


-----Mensaje original-----
De: Richard Reeves [mailto:r_reeves@blueyonder.co.uk]
Enviado el: Jueves, 03 de Marzo de 2005 04:23 a.m.
Para: aVR-Chat@yahoogroups.com
Asunto: [AVR-Chat] DS1302 / LCD / Codevision


Hi folks,
I have a student using Codevision to pull the date and time from a
DS1302 RTC and display it on an LCD, as well as use the data as
integer values to calculate sunrise and sunset.

Now, I'm not much of a C programmer, and the results we're getting
look a bit odd.  Now, the code is at work and I'm not, but what we're
trying is:

char hrs[3];
char mins[3];
char sec[3];
int second;

//Timer1 interrupt every second
{
//This was one way:
rtc_get_time(hrs,mins,sec);
lcd_gotoxy(0,0);
lcd_puts(sec);
}

We also tried reading the bytes individually with
second=DS1302_read(0xNN); //Can't remember address
second=bin2hex(second);
//Convert to string and dislpay
itoa(second,sec);
lcd_gotoxy(0,0);
lcd_puts(sec);

Now, we get odd values for everything - could someone please tell me
(an assembler man) where we're going wrong?


Thanks!




Richard
---
"Iz dana u dan ona dolazi i odlazi u talasima"
   http://www.van-gogh.co.yu/

      Yahoo! Groups Sponsor
            ADVERTISEMENT





----------------------------------------------------------------------------
----
Yahoo! Groups Links

  a.. To visit your group on the web, go to:
  http://groups.yahoo.com/group/AVR-Chat/

  b.. To unsubscribe from this group, send an email to:
  AVR-Chat-unsubscribe@yahoogroups.com

  c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

______________________________
Visita http://www.tutopia.com y comienza a navegar m�s r�pido en Internet. Tutopia es Internet para todos.

RE: [AVR-Chat] DS1302 / LCD / Codevision

2005-03-03 by Richard Reeves

Javier:
> Here goes some routines i am using and work
<snip code> 

Thank you!!!!  
I shall make sure you get a 'Thank you' in the student's report as 
well.



Richard
---
"Iz dana u dan ona dolazi i odlazi u talasima"
   http://www.van-gogh.co.yu/

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.