Author Topic: Display time and date with a DS1307 and 18f452  (Read 4544 times)

galere

  • Newbie
  • *
  • Posts: 1
    • View Profile
Display time and date with a DS1307 and 18f452
« on: March 30, 2010, 11:48:32 PM »
Hello, i have a problem in my program, i searched and i don't found.



Program:(I use Mplab)

#include <p18f452.h>
#include <delays.h>
#include <stdio.h>
#include <i2c.h>
#include <xlcd.h>





#pragma config WDT =OFF

int octetrecu1;
int octetrecu2;
int octetrecu3;
int octetrecu4;
int octetrecu5;
int octetrecu6;
int octetrecu7;
int octetrecu8;














/////////////////////////////////////////////////////////////
// PROTOTYPE //
/////////////////////////////////////////////////////////////

void ack(void);
void init_I2C(void);
void read_trameI2C(int *octet1, int *octet2, int *octet3, int *octet4,int *octet5, int *octet6, int *octet7, int *octet8);
void tempo(unsigned int count);
unsigned int SWReadI2C( void );
void SetPosition(unsigned char x, unsigned char y);
void SetDDRamAddr(PARAM_SCLASS unsigned char);














/////////////////////////////////////////////////////////////
// read_tram_i2c(); //
/////////////////////////////////////////////////////////////

void read_trameI2C(int *octet1, int *octet2, int *octet3, int *octet4,int *octet5, int *octet6, int *octet7, int *octet8)
{
*octet1 = ReadI2C();
SSPCON2bits.ACKEN = 1;
ack();
*octet2 = ReadI2C();
SSPCON2bits.ACKEN = 1;
ack();
*octet3 = ReadI2C();
SSPCON2bits.ACKEN = 1;
ack();
*octet4 = ReadI2C();
SSPCON2bits.ACKEN = 1;
ack();
*octet5 = ReadI2C();
SSPCON2bits.ACKEN = 1;
ack();
*octet6 = ReadI2C();
SSPCON2bits.ACKEN = 1;
ack();
*octet7 = ReadI2C();
SSPCON2bits.ACKEN = 1;
ack();
*octet8 = ReadI2C();
}















////////////////////////////////////////////////////////////////////////
// TEST ACK //
////////////////////////////////////////////////////////////////////////

void ack(void)
{
IdleI2C();
while (SSPCON2bits.ACKSTAT);
}

















////////////////////////////////////////////////////////////////////////
// TEMPO //
////////////////////////////////////////////////////////////////////////

void tempo(unsigned int compte)
{
while (compte--);
}













/////////////////////////////////////////////////////////////
// INITIALISATION I2C //
/////////////////////////////////////////////////////////////

void init_I2C(void)
{
DDRCbits.RC3=1;
DDRCbits.RC4=1;
SSPCON1=0x28;

SSPSTATbits.SMP=1;

SSPADD=9;
}
















/////////////////////////////////////////////////////////////
// Fonction Principale //
/////////////////////////////////////////////////////////////

void main(void)
{




int Valeur = 1;
//InitLCD();
stdout = _H_USER;
OpenXLCD(FOUR_BIT & LINES_5X7);   //la librairie XLCD du C

init_I2C();
IdleI2C();

StartI2C();
while (SSPCON2bits.RSEN);

WriteI2C(0xD0);
ack();

WriteI2C(0x00);
ack();

WriteI2C(0x00);
ack();

WriteI2C(0x01);
ack();

WriteI2C(0x00);
ack();

WriteI2C(0x02);
ack();

WriteI2C(0x51);
ack();

WriteI2C(0x03);
ack();

WriteI2C(0x03);
ack();

WriteI2C(0x04);
ack();

WriteI2C(0x11);
ack();

WriteI2C(0x05);
ack();

WriteI2C(0x03);
ack();

WriteI2C(0x06);
ack();

WriteI2C(0x09);
ack();

WriteI2C(0x07);
ack();

WriteI2C(0x03);
ack();

StopI2C();

while (SSPCON2bits.PEN);

tempo(60000);

IdleI2C();

StartI2C();

while (SSPCON2bits.RSEN);

WriteI2C(0xD1);
ack();














////////////////////////////////////////////////////////////////////////
// lecture de la trame I2C //
////////////////////////////////////////////////////////////////////////

read_trameI2C(&octetrecu1, &octetrecu2, &octetrecu3, &octetrecu4, &octetrecu5, &octetrecu6, &octetrecu7, &octetrecu8);



















////////////////////////////////////////////////////////////////////////
// CLOTURATION I2C //
////////////////////////////////////////////////////////////////////////

NotAckI2C(); // transmet l'acquittement du maître
while (SSPCON2bits.ACKEN); // attend fin de l'acquittement

StopI2C(); // initialise une stop-condition


while (SSPCON2bits.PEN); // attend fin de stop-condition





printf("=%X", octetrecu1);
printf("=%X", octetrecu2);
printf("=%X", octetrecu3);
printf("=%X", octetrecu4);
printf("=%X", octetrecu5);

SetPosition(0,1);

printf("=%X", octetrecu6);
printf("=%X", octetrecu7);
printf("=%X", octetrecu8);
while(1); // boucle infinie
}

void SetPosition(unsigned char x, unsigned char y)
{
if (y) SetDDRamAddr(0x40+x);
 else SetDDRamAddr(x);
}

void DelayFor18TCY(void)
{
    Delay10TCYx(2);
}
void DelayPORXLCD(void)
{
    Delay1KTCYx(15);     //Delai de 15 ms
}
void DelayXLCD(void)
{
    Delay1KTCYx(20);     //Delai de 20 ms
}

ymasur

  • Full Member
  • ***
  • Posts: 13
    • View Profile
    • Homepage ymasur
Re: Display time and date with a DS1307 and 18f452
« Reply #1 on: June 07, 2010, 02:05:34 PM »
Et quel est le problème?