home | area personale         schemi | tutorial | robotica | pic micro | recensioni         forum | chat irc         faq | contatti         store | Ordina PCB
username
password
cerca

 
FORUM: Pic Micro
Tutto quanto riguarda questi microprocessori... progetti, suggerimenti, aiuti, discussioni...ecc


Errore lettura eeprom interna
     
Autore Messaggio opzioni
labtest





postato il:
24.11.2022, alle ore 10:34
Errore lettura eeprom interna 

Ciao sto utilizzando MPLAB compilatore c18 pikit3 e pic 18f87k90.

Riesco a scrivere in eeprom interna perche se vado attraverso il ttol vedo che effettivamente è scritta ma ho problemi a leggera.

Ho scritto 05 nell indirizzo 0x00 dell EEprom.(VERIFICATO)!

VAdo a leggere wuesta è la routine

 
 qui il codice 

unsigned  Eeprom_ReadByte(unsigned  address)
{

    // Set address registers
    EEADRH = (unsigned )(address >> 8);
    EEADR = (unsigned )address;

    EECON1bits.EEPGD = 0;       // Select EEPROM Data Memory
    EECON1bits.CFGS = 0;        // Access flash/EEPROM NOT config. registers
 

    // A read should only take one cycle, and then the hardware will clear
    // the RD bit
    while(EECON1bits.RD == 1);
 
     EECON1bits.RD = 1;          // Start a read cycle

    return EEDATA;              // Return data






e la leggo in questo modo ma non riesco a trovare il valore corretto:
 popR = Eeprom_ReadByte(0x00);
                   Delay_ms (20);
               if (popR == 5 ){ 
                break;   
               }
                 


non lo legge
primok




una ogni 100 livelli
una ogni 10 livelli


postato il:
24.11.2022, alle ore 19:58
 /**********************************************************/
//                        MAIN 
/**********************************************************/


#include <p18f87k90.h>
#include <delays.h>
#include <stdio.h> //libreria sprintf()
#include <stdlib.h> //libreria atoi(),atof()

void Delay(unsigned int Ritardo);
void DelayUS(unsigned int Ritardo);
void writeeeprom(unsigned char addr,unsigned char byte);  //escribe un dato en la EEPROM
unsigned char readeeprom(unsigned char addr); //lee un dato de la EEPROM




// DELAY ROUTINE
// Descrizione: consumo in tempo pari a Ritardo*1mS (1...65535)
// Parametri passati: Time (mS)
// Parametri ricevuti: nessuno
// Note...
//****************************************************
unsigned char    tst;
unsigned char   readByte;
void Delay(unsigned int Ritardo)
    {
    unsigned int Tempo;
    for (Tempo = 1; Tempo <= Ritardo; Tempo++)
        {
        Delay100TCYx(160);//160 * 100 * 0.0625uS = 1mS
        tst=0;
        }
    }
//******************************************************

void DelayUS(unsigned int Ritardo)
    {
    unsigned int Tempo;
    for (Tempo = 1; Tempo <= Ritardo; Tempo++)
        {
        Delay10TCYx(200)     ;//160 * 10 * 0.0625uS = 0.1mS
        tst=0;
        }
    }
//******************************************************

void writeeeprom(unsigned char addr,unsigned char byte)
{
unsigned char i=INTCONbits.GIEH;
INTCONbits.GIEH = 0; //disable interrupts
EECON1bits.EEPGD=0; //Write to EEPROM
EECON1bits.CFGS=0; //EEPROM not config bits
EECON1bits.WREN=1; //Allows write

EEADR=addr;
EEDATA=byte;
EECON2=0x55;
EECON2=0xaa;
EECON1bits.WR=1;
while(EECON1bits.WR); //Wait until written
//while(!PIR2bits.EEIF);
//PIR2bits.EEIF=0;
EECON1bits.WREN=0; //No more write
INTCONbits.GIEH = i; //restore interrupts
}

unsigned char readeeprom(unsigned char addr)
{
EECON1bits.CFGS=0; //EEPROM not config bits
EECON1bits.EEPGD=0;
EEADR=addr;
EECON1bits.RD=1;
return (unsigned int) EEDATA;
}
void main()
{
writeeeprom(0,6); 
Delay(5);
readByte=readeeprom(0);
Delay(5);



Più piccola è la mente più grande è la presunzione.
primok




una ogni 100 livelli
una ogni 10 livelli


postato il:
24.11.2022, alle ore 20:01
 void main()
{
writeeeprom(0,6); 
Delay(5);
readByte=readeeprom(0);
Delay(5);

while (1)
    {
}



Più piccola è la mente più grande è la presunzione.
segui questo thread con grixFC, per questa funzione devi aver installato il software grixFC

torna su
     

Come utente anonimo puoi leggere il contenuto di questo forum ma per aprire una discussione
o per partecipare ad una discussione esistente devi essere registrato ed accedere al sito




 







 
 
indietro | homepage | torna su copyright © 2004/2024 GRIX.IT - La community dell'elettronica Amatoriale