ADGAN
Full Member level 5
- Joined
- Oct 9, 2013
- Messages
- 295
- Helped
- 4
- Reputation
- 8
- Reaction score
- 4
- Trophy points
- 18
- Activity points
- 1,837
void readDS1307(){
StartI2C1();
IdleI2C1();
WriteI2C1(0xD0);
IdleI2C1();
WriteI2C1(0x00);
IdleI2C1();
RestartI2C1();
IdleI2C1();
WriteI2C(0xD1);
IdleI2C();
sec = ReadI2C1();
AckI2C1();
min = ReadI2C1();
AckI2C1();
hr = ReadI2C1();
AckI2C1();
week_day = ReadI2C1();
AckI2C1();
day = ReadI2C1();
AckI2C1();
mn = ReadI2C1();
AckI2C1();
year = ReadI2C1();
NotAckI2C1();
StopI2C1();
}
OpenI2C1(MASTER,SLEW_OFF);
Delay10KTCYx(25);
SSPADD = 99;
writeDS1307();
readDS1307();
void ds1307_get_time(void)
{
I2CStart();
writeI2C(DS1307_ADDR); // slave addrs
writeI2C(0x00); // Start at REG 0 - Seconds
I2CRestart();
writeI2C(DS1307_ADDR+1);
sec = bcd2bin(Read_I2C(0));
min = bcd2bin(Read_I2C(0));
hr = bcd2bin(Read_I2C(1));
I2CStop();
}
void main()
{
... etc ........
// Initial the PIC18F26K22 Hardware I2C Master uses RC3 & RC4
CloseI2C();
addr=PCF8574_ADDR; // 4E pour le LCD
// module I2C a 100KHz
OpenI2C(MASTER, SLEW_OFF);
SSPADD = 24 ; // at 10Mhz et 49 at 20MHz;
IdleI2C();
StartI2C();
donnee = SSPBUF; // clear buffer
do
{
status = WriteI2C( addr); //write the address of slave
if(status == -1) //check if collision happened
{
donnee = SSPBUF; //empty the buffer,
SSPCON1bits.WCOL=0; // clear the collision status bit
}
j++;
}
while((status!=0)&& (j<100)); //write untill successful communication
if (PORTAbits.RA5==0) DS1307_Init_Date_Heure(13,8,23,5,16,6);
// k=fprintf(_H_USART,"Lecture DS1307\r\n");
ds1307_get_time();
LCD_Erase_Line(3);
k=sprintf(txt,"Time is %02dH%02dM%02dS ",hr,min,sec);
LCD_puts(txt);
Tempo(1000);
ds1307_get_date();
LCD_Erase_Line(4);
k=sprintf(txt,"Date is %02d/%02d/20%02d ",date,mth,year);
LCD_puts(txt);
How do I check the SQWOUT output?
How do you use Read_I2C(0) or Read_I2C(1) in MPLAB ?
void I2CStart(void)
{
I2CIdle();
SSPCON2bits.SEN = 1;
while (SSPCON2bits.SEN);
}
void I2CRestart(void)
{
I2CIdle();
SSPCON2bits.RSEN = 1;
while (SSPCON2bits.RSEN);
}
void I2CStop(void)
{
I2CIdle();
SSPCON2bits.PEN = 1;
while (SSPCON2bits.PEN);
}
void writeI2C(unsigned char data)
{
PIR1bits.SSP1IF = 0;
SSPBUF = data;
while(!PIR1bits.SSP1IF);
}
char Read_I2C(char ack)
{
I2CIdle();
SSP1CON2bits.RCEN = 1;
while(SSP1CON2bits.RCEN);
while(!SSP1STATbits.BF);
I2CACK(ack);
return SSPBUF;
}
void I2CIdle(void)
{
Tempo(100);
// while((SSP1STAT & 0x04) | (SSPCON2 & 0x1F));
}
void I2CACK(unsigned char ackbit)
{
if(ackbit)
{
SSP1CON2bits.ACKDT = 1;
}
else
{
SSP1CON2bits.ACKDT = 0;
}
SSP1CON2bits.ACKEN = 1;
while(SSP1CON2bits.ACKEN);
}
Lecture DS1307
DS1307 raw time 13/12/22 le 06 22H 58M 06S
DS1307 transformed time 13/12/22 le 06 22H 58M 06S
Lecture DS1307 with other subroutines
DS1307 date 13/12/22/ le 6
DS1307 time 22H58M07S
Lecture DS1307
DS1307 raw time 13/12/22 le 06 22H 58M 07S
DS1307 transformed time 13/12/22 le 06 22H 58M 07S
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?