Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Problem with displaying values on LCD using DS1307

Status
Not open for further replies.

auto_mitch

Full Member level 3
Joined
Oct 14, 2004
Messages
172
Helped
16
Reputation
32
Reaction score
3
Trophy points
1,298
Activity points
1,240
My project is to built an alarm clock. I want to display on lcd the current date and the time and with a keypad have access in a menu in which you can set the alarm time.
I try to use the ds1307 functions of codevision and i cannot get anything on lcd.I dont know what is going wrong. The only value that i can get by displaying the seconds is always 128. Can you help me?

Code:
// I2C Bus functions
#asm
   .equ __i2c_port=0x15 ;PORTC
   .equ __sda_bit=1
   .equ __scl_bit=0
#endasm

// Alphanumeric LCD Module functions
#asm                                     
   .equ __lcd_port=0x18 ;PORTA
#endasm
#include <mega16.h>
#include <i2c.h>
#include <lcd.h>
#include<stdio.h>
#include<stdlib.h>
#include<delay.h>
#include<ds1307.h>

char secbuffer[16];


void main(void)
{
unsigned char h,m,s;

// LCD Initialization.
lcd_init(16);
// I2C Initialization.         
i2c_init();
delay_ms(100);
// Initialize the DS1307 RTC
rtc_init(0,0,0);
delay_ms(100);
rtc_set_time(04,05,22);


while (1)
      {
        rtc_get_time(&h,&m,&s);
        sprintf(secbuffer,"%02d",s);
        lcd_gotoxy(6,0);
        lcd_puts(secbuffer);
        };
}
 

eidtech

Junior Member level 2
Joined
Jun 13, 2006
Messages
21
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,281
Location
Mexico
Activity points
1,406
ds1307 problem

Check your connections,

If you are not using a Backup Battery, connect Pin 3 to GND.

Check your 32Khz Oscillator.
 

yousafzai

Full Member level 5
Joined
Jun 1, 2006
Messages
244
Helped
15
Reputation
30
Reaction score
8
Trophy points
1,298
Activity points
2,292
codevision ds1307

Are the pullup resistors on SCL and SDA lines are propoerly installed?
 

auto_mitch

Full Member level 3
Joined
Oct 14, 2004
Messages
172
Helped
16
Reputation
32
Reaction score
3
Trophy points
1,298
Activity points
1,240
rtc ds1307 codevision

I have already checked all the connections and they look ok. yes the pullup resistors are properly installed and a cell battery is connected. The osc is at 32.768KHz.
 

SAR

Advanced Member level 4
Joined
Sep 25, 2002
Messages
107
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Activity points
988
ds1307 not working

Bit 7 on DS1307 is probably set to halt. You need to set the start bit on the DS1307.

Read the data sheet and search on the net, there's tons of information on the DS1307 RTC.

Also? Do you have the battery hooked up to the DS1307?
 

k2-4u

Newbie level 1
Joined
Apr 5, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,283
Re: DS1307 problem

its my problem too!
on ATmega16L

My Code

Code:
/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.4 Standard
Automatic Program Generator
ˆ Copyright 1998-2004 Pavel Haiduc, HP InfoTech s.r.l.
[url]http://www.hpinfotech.com[/url]
e-mail:office@hpinfotech.com

Project : 
Version : 
Date    : 05/04/2010
Author  : KOrosh                          
Company : Korosh                          
Comments: 


Chip type           : ATmega16L
Program type        : Application
Clock frequency     : 8,000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/

#include <mega16.h>
#include <stdlib.h>
#include <delay.h>


// I2C Bus functions
#asm
   .equ __i2c_port=0x1B ;PORTA
   .equ __sda_bit=0
   .equ __scl_bit=1
#endasm
#include <i2c.h>

// DS1307 Real Time Clock functions
#include <ds1307.h>

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

// Declare your global variables here


void main(void)
{
// Declare your local variables here
        unsigned char h,m,s;
        unsigned char sc[20];

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// I2C Bus initialization
i2c_init();

// DS1307 Real Time Clock initialization
// Square wave output on pin SQW/OUT: Off
// SQW/OUT pin state: 1
rtc_init(0,0,1);

// LCD module initialization
lcd_init(16);

lcd_clear();
lcd_gotoxy(0,0); 

//rtc_set_time(1,2,3);  
delay_ms(1000);


while (1)
      {
        rtc_get_time(&h,&m,&s);
        itoa(s,sc); 
        lcd_gotoxy(0,0); 
        lcd_puts(sc);

        delay_ms(50);

      };
}
 

demuri

Newbie level 2
Joined
Jun 10, 2008
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,312
// I also had these problems.
// I was searching for solutions in the datasheet, in the books, in the forums, familiar and unfamiliar .... is even.
// After months of anguish, ..."Eureka"
// - read once again battered pile of papers, I discovered "America",
//
// ...." Data valid: The state of the data line represents valid data when, after a START condition, the data
// line is stable for the duration of the HIGH period of the clock signal. The data on the line must be
// changed during the LOW period of the clock signal. There is one clock pulse per bit of data .".........
// And here is my "Newton solution":

void clock (void)
{
//=======================================================================
// for the time to add
//two line below:
//=======================================================================
while (PORTC.5 == 1) //this is "my" SDA = PORTC.5
{delay_us (1);}
//=======================================================================
i2c_start ();
i2c_read (0);
rtc_get_time (& RTC_Hour, & RTC_Mins, & RTC_Sec);
//=======================================================================
/ / And repeat the same thing for date
//=======================================================================
while (PORTC.5 == 1)
{delay_us (1);}
//=======================================================================
rtc_get_date (& RTC_Day, & RTC_Month, & RTC_Year);
i2c_stop ();
// .........................
}
// Enjoy. And do not suffer anymore.;D
// Please only say, "Thank you uncle Demuri.";D))
// demuri@hotmail.com
 

gunbrown

Newbie level 3
Joined
Mar 28, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,301
if you have already checked the I2C buss connection and battery backup in RTC look ok.

I suggest you to try TWI method for interfacing to I2C devices.
try I2C Master Interface library from Peter Fleury in Peter Fleury Online: AVR Software
i already tested that code for my project using DS1307 and works great to other I2C device like eeprom AT24C512.

---------- Post added at 01:07 ---------- Previous post was at 01:06 ----------
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top