Microcontroller › AVR › problem with Interfacing ds1307 with atmega 32.
- This topic has 2 replies, 3 voices, and was last updated 11 years, 10 months ago by
romel emperado.
-
AuthorPosts
-
July 20, 2011 at 4:47 am #1203
sunilkumar
ParticipantHello everyone..
i have a problem here. i am using avr studio/avr gcc,16x2LCD(8-bit i/o mode),atmega32. i have compiled the below code ..
also i am not using any keys.(will use it later). i just want to see running clock.(i.e running from default time.). but it is showing “hello world” “00:00:00 AM”. and time wont update at all..my connections are LCD to Port A& B,SCL,SDA are as usual. please help.. thanks.
please forgive if this is not the right section to post my doubt..
Code:#include <avr/io.h>
#include <util/delay.h>#define FALSE 0
#define TRUE 1#define LCD_DATA PORTA
#define ctrl PORTB
#define en PB2
#define rw PB1
#define rs PB0
#define CH 7
void LCD_cmd( char cmd);
void init_LCD(void);
void LCD_write( char data);
void LCD_write_string( char *str);
uint8_t DS1307Read(uint8_t address,uint8_t *data);
uint8_t DS1307Write(uint8_t address,uint8_t data);
uint8_t I2CReadByte(uint8_t *data,uint8_t ack);
uint8_t I2CWriteByte(uint8_t data);
void I2CInit();
void I2CClose();
void I2CStart();
void I2CStop();int main(void)
{
char Time[12];
uint8_t data;
DDRA=0xFF;
DDRB=0xFF;
init_LCD();
I2CInit();
uint8_t temp;
DS1307Read(0x00,&temp);//Clear CH Bit
temp&~(1<<CH));
DS1307Write(0x00,temp);
//Set 12 Hour Mode
DS1307Read(0x02,&temp);//Set 12Hour BIT
temp|=(0b01000000);//Write Back to DS1307
DS1307Write(0x02,temp);LCD_write_string(“hello world”);
while(1)
{
DS1307Read(0x00,&data);
Time[8]=’