KVN1477
Junior Member level 3
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
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);
}