Vai al contenuto
PLC Forum


Pic16f877 Comunicazione Con Eeprom I2c - errore di compilazione


ottoemmezza

Messaggi consigliati

sto tentando di scrivere su una eeprom 24LC02 con un PIC16F877, utilizzo utilizzo un compilatore HI-TECH C, sto usando gli esempi di codice trovati in questo link al paragrafo I2C (ultimo in basso)

http://www.microchipc.com/sourcecode/#i2c

ottengo un errore di linking :( , dal codice originale ho cambiato le definizioni di SDA SCL e TRIS1

che penso fossere da ridefinire. :unsure:

GRAZIE per un eventuale aiuto cordiali saluti Max.

#include    <pic.h>
#define    SDA        RB0
#define    SCL        RB1
#define TRIS1 TRISB
#define    TRUE    1
#define    FALSE    0
typedef    unsigned char byte;
void start_delay(void);
void ee_delay(void);
void ee_start(void);
bit ack(void);
void ee_byte(byte x);
bit ee_byte_to_ee(byte address, byte dat);
bit ee_byte_from_ee(byte address,byte *dat);
void ee_data(byte *x);

void main()
    {
    //attesa inizio
    start_delay();
    //riga dati
    ee_byte_to_ee(0x43,0x81);
    } 
    
//start delay     
void start_delay(void)
{
int delay;
for(delay=0;delay<256;delay++);
}

void ee_delay(void)
{byte delay;
 for(delay=0;delay<10;delay++);
}

bit ee_byte_to_ee(byte address, byte dat)
{
/* Returns True if write was successfully acknowledged */
 ee_start();                 /* Send start sequence */

 ee_byte(0xa0);              /* Control byte (WRITE) */ 


 if (ack()) return(FALSE);     /* Test Acknowledge    */

 ee_byte(address);           /* Address Byte */

 if (ack()) return(FALSE);

 ee_byte(dat);               /* Data byte */

 if (ack()) return(FALSE);

 SCL=0;
 ee_delay(); 
 SDA=0;                      /* Stop condition */
 TRIS1=0;                      /* SDA OUTPUT     */
 ee_delay();
 SCL = 1;
 ee_delay();
 SDA = 1;
 ee_delay();
 return(TRUE);
}

void ee_byte(byte x)
{int i;

 i=0x80;
 do
  {
   SCL=0;
   TRIS1 =0;                /* SDA OUTPUT     */
   ee_delay();
   if (x&i) SDA=1;
    else SDA=0;
   ee_delay();
   SCL=1;
   ee_delay();
   i>>=1;
  }while(i!=0);
}

bit ack(void)
{ 
 SCL=0;                 /* Acknowledge         */
 ee_delay();
 TRIS1=1;                /* SDA Input        */
 ee_delay();
 SCL=1;
 ee_delay();            /* Test Acknowledge    */
 return(SDA);
}

bit ee_byte_from_ee(byte address,byte *dat)
{
/* Returns True if read was successfully acknowledged */

 ee_start();                 /* Send start sequence */

 ee_byte(0xa0);              /* Write Control byte */

 if (ack()) return(FALSE);

 ee_byte(address);           /* Address Byte */

 if (ack()) return(FALSE);

 SCL=0;
 ee_delay();
 SCL=1;
 ee_delay();
 SDA=0;                      /* Start Condition */
 TRIS1=0;                     /* SDA OUTPUT        */
 ee_delay();             

 ee_byte(0xa1);          /* Read Control byte */

 if (ack()) return(FALSE);

 ee_data(dat);           /* Get the data byte */

 ack();

 SCL=0;                  /* Stop condition */
 ee_delay();
 SDA=0;
 TRIS1=0;                 /* SDA OUTPUT        */
 ee_delay();
 SCL=1;
 ee_delay();
 SDA=1;
 return(TRUE);
}

void ee_data(byte *x)
{int i;

 TRIS1=1;        /* SDA INPUT */
 *x=0;
 i=0x80;
 do
  {
   SCL=0;
   ee_delay();
   SCL=1;
   ee_delay();
   if (SDA) *x=(*x)|i;
   i>>=1;
  }while(i!=0);
}

Link al commento
Condividi su altri siti


ho risolto da me, avevo dimenticato di ricopiare la il codice di una funzione e avevo messo solo l'header,

la cosa strana il compilatore hi-tech c mi dava un errore non definito :huh:

Grazie comunque.

Link al commento
Condividi su altri siti

Crea un account o accedi per commentare

Devi essere un utente per poter lasciare un commento

Crea un account

Registrati per un nuovo account nella nostra comunità. è facile!

Registra un nuovo account

Accedi

Hai già un account? Accedi qui.

Accedi ora
×
×
  • Crea nuovo/a...