I am currently in the process of building a digital clock using the Olimex AVR-MT-129 board with a DS1307 connected to it. The AVR-MT128 is working great and has a lot of functionality. Got most of my code working for a menu system for setting the clock but when i hookup the DS1307 to the AVR i get nothing. I am wondering if anyone else has tried to do this and has had any luck and if anyone might know what i am doing wrong. I am including a code snippet and the wiring that i have done. Thanks for any help.
Garry
DS1307 AVRmega128
Pin 5 SDA to PD1
Pin 6 SCL to PD0
Pin 7 SQW to PE2
Pin 8 to +5
Pin 4 to GND
Pin 1 and 2 got to a 32.768kHZ crystal
Code:
#include <mega128.h>
#include <delay.h>
#include <stdio.h>
// I2C Bus functions
#asm
.equ __i2c_port=0x12 ;PORTD
.equ __sda_bit=1
.equ __scl_bit=0
#endasm
#include <i2c.h>
// DS1307 Real Time Clock functions
#include <ds1307.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
// Declare your global variables here
unsigned char date,month,year,hour,minute,second;
char lcd_buffer[33];
void main(void)
snip
// I2C Bus initialization
i2c_init();
// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: On
// Square wave frequency: 1Hz
rtc_init(0,1,0);
// LCD module initialization
lcd_init(16);
rtc_set_date(31,12,02);
lcd_clear();
rtc_set_time(23,59,58);
lcd_clear();
while (1)
{
// Place your code here
rtc_get_date(&date,&month,&year);
sprintf(lcd_buffer,“%2u-%2u-200%u”,date,month,year);
lcd_gotoxy(0,0);
lcd_puts(lcd_buffer);
delay_ms(500);
rtc_get_time(&hour,&minute,&second);
sprintf(lcd_buffer,“%2u:%2u:%2u”,hour,minute,second);
lcd_gotoxy(0,1);
lcd_puts(lcd_buffer);
delay_ms(500);
lcd_clear();
};
}