Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

[SOLVED] PIC18F458 is not reading RTC DS1307

Status
Not open for further replies.

KVN1477

Junior Member level 3
Joined
Nov 18, 2013
Messages
26
Helped
4
Reputation
8
Reaction score
4
Trophy points
3
Activity points
184
hi all,
i have tried so much but PIC 18F458 is not reading RTC DS1307, PLz help me
oscillator -HS 20Mhz
complier-micro c pro for pic
here is code
Code:
// LCD module connections
sbit LCD_RS at RB7_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_D4 at RB5_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D7 at RB2_bit;
sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;
// End LCD module connections


unsigned short read_ds1307(unsigned short address)
{
  unsigned short r_data;
  I2C1_Start();
  I2C1_Wr(0xD0);
  I2C1_Wr(address);
  I2C1_Repeated_Start();
  I2C1_Wr(0xD1); 
  r_data=I2C1_Rd(0);
  I2C1_Stop();
  return(r_data);
}
unsigned char BCD2UpperCh(unsigned char bcd)
{
  return ((bcd >> 4) + '0');
}
unsigned char BCD2LowerCh(unsigned char bcd)
{
  return ((bcd & 0x0F) + '0');
}

int second;
int minute;
int hour;
char time[] = "Time:00:00:00";
void main()
 {
CMCON = 0x07;   // To turn off comparators
   //ADCON0.adon =0;  // To turn off analog to digital converters
   ADCON1=0x07; //digital io
   //ccp1con=0x00;
   TRISA = 0xff;
   PORTD = 0x00;  //0x00;
   trisd=0x00;
   I2C1_Init(100000); //DS1307 I2C is running at 100KHz
   Lcd_Init();// Initialize LCD
   Lcd_Cmd(_LCD_CURSOR_OFF);// Cursor off
  Lcd_Cmd(_LCD_CLEAR);

      do
   {


              second = read_ds1307(0);
              minute = read_ds1307(1);
              hour = read_ds1307(2);

            time[5] = BCD2UpperCh(hour);
            time[6] = BCD2LowerCh(hour);
            time[8] = BCD2UpperCh(minute);
            time[9] = BCD2LowerCh(minute);
            time[11] = BCD2UpperCh(second);
            time[12] = BCD2LowerCh(second);
            Lcd_out(1,1,time);
            delay_ms(50);

   }while(1);
 }
 

Hi,

after addressing the DS1307 does it send the acknowledge?

Klaus
 

thanks for replay
how i can check acknowledgement?
i have exucated same code on PIC16F877A and its working fine
is there is any problem in initialization of ports, enabling and disabling any services like ADC, comparator etc
 

Hi,

how i can check acknowledgement?
After addressing the I2C device it sends out an acknowledge bit. This signals the master that the device exist at the bus.
Therefore in my eyes it should be mandatory to check the acknowledgement bit.

The ACK bit is transmitted immediately after the 8th data bit, or after the R/W bit (after 7 bits of address).

Read the I2C specification.

You are using I2C functions in your code. To use it you need to include the library. Read the library documentation on how to check ACK bit.

Klaus
 

i forget to change proprieties of pull up registers as "digital" in protuse
thanks Klaus for ur support
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top