Yahoo Groups archive

AVR-Chat

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

Message

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.

Attachments

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.