¿Cómo guardar datos en EEPROM interna del PIC18F4550 en PIC C Compiler?

Hola. Buen día. Quisiera guardar datos en la EEPROM interna del PIC18F45550 en PIC C.
Tengo entendido que se utiliza la directiva #ROM 0x2100 pero al utilizarla en el PIC no me va, en todo caso decidí verificar que en realidad al inicio del programa me estaba lanzando datos y los mandé directamente a un LCD, y como pensé no tenían más que el valor total de cada banco que es 256 bytes.

Aquí dejo el programa. Realicé un ejemplo del libro de PIC C Y Proteus donde hace una cerradura.

De ante mano he verificado en el foro para ver si había temas con el mismo problema y los respondieron pero tengo entendido que utilizaron PICs de gama media y en mi caso estoy utilizando uno de gama alta.
¿Puede ser que los bancos de memoria empiecen con otro número?

Para solucionar este problema en el código, escribí nuevamente la clave de la siguiente manera:
write_eeprom(0,'7');
write_eeprom(1,'2');
write_eeprom(2,'3');
PHP:
#include <18f4550.h>

#use delay(clock=4000000)
#use standard_io(a)
#use fast_io(b)
#use fast_io(d)

#rom 0x2100={'7','2','3'}

#fuses XT,NOWDT,NOMCLR,PUT

#include <My_lcd.c>
#include <stdlib.h>


char teclado(void) 
{  
      output_b(0b11111110);
      if(input (PIN_B4)==0)
         return('1');
      if(input (PIN_B5)==0)
         return('2');
      if(input (PIN_B6)==0)
         return('3');
      if(input (PIN_B7)==0)
         return('A');
         
       output_b(0b11111101);
      if(input (PIN_B4)==0)
         return('4');
      if(input (PIN_B5)==0)
         return('5');
      if(input (PIN_B6)==0)
         return('6');     
      if(input (PIN_B7)==0)
         return('B');
         
      output_b(0b11111011);
      if(input (PIN_B4)==0)
          return('7');
      if(input (PIN_B5)==0)
          return('8');
      if(input (PIN_B6)==0)
          return('9');
      if(input (PIN_B7)==0)
          return('C');
          
      output_b(0b11110111);
      if(input (PIN_B4)==0)
          return('*');
      if(input (PIN_B5)==0)
          return('0');
        if(input (PIN_B6)==0)
        return('#');
      if(input (PIN_B7)==0)
          return('D');
          
      return (0);
}
void main()
{
   char k;
   int i;
   char data[3], clave[3];
   write_eeprom(0,'7');
   write_eeprom(1,'2');
   write_eeprom(2,'3');
   set_tris_a(0b00000001);
   set_tris_b(0b11110000);
   lcd_init();
   port_b_pullups(TRUE);
   while(TRUE) {
   i=0;
   printf(lcd_putc,"\fPulsar tecla 1\n");
   delay_ms(300);

   while(i<=2){
      k=teclado();
         if (k!=0)
            
            {delay_ms(200);
            data[i]=k;
             i++;
             printf(lcd_putc,"\fPulsar tecla %u\n",i+1);
             
             
            }
   }
   delay_ms(300);
   for (i=0;i<=2;i++){
      clave[i]=read_eeprom(i);}
   if((data[0]==clave[0])&&(data[1]==clave[1])&&(data[2]==clave[2]))
      {printf(lcd_putc,"\fPuerta Abierta");
       output_high(PIN_A0);
       delay_ms(500);
       output_low(PIN_A0);}
  else printf(lcd_putc,"\fPuerta Cerrada");
   delay_ms(1000);
   }
}
De ante mano, muchas gracias por su tiempo.
 
Última edición por un moderador:
En el PIC18F4550 la dirección inicial para la EEPROM interna es: 0xF00000
18F4550TEMP.ASM dijo:
;******************************************************************************
;EEPROM data
; Data to be programmed into the Data EEPROM is defined here

ORG 0xf00000

DE "Test Data",0,1,2,3,4,5

;******************************************************************************
Y lógicamente sí cambian los rangos de memoria.
Entonces al usar la directiva #ROM para escribir datos iniciales en la EEPROM interna, sería de esta forma:
#rom 0xF00000 = {0,1,2,3,4,5,6,7,8,9}

18F4550 EEPROM Data.jpg

PD:
La palabra de configuración que estás usando para que el CPU trabaje a 4MHz, no es correcta.
Usa esta:
Código:
[B][COLOR=Red]#fuses[/COLOR]   NOMCLR,NOFCMEN,NOVREGEN,NOPBADEN
[COLOR=Red]#use[/COLOR]     delay(crystal = [COLOR=SeaGreen]4[/COLOR]MHz)[/B]
 
Última edición:
Muchas gracias por tu ayuda
Y bueno sobre lo que colocas relacionado al cristal la verdad es que me viene muy bien ya que e realizado programas donde utilizo el crystal y las acciones no me las realizaba al tiempo que yo especificaba.
 
Atrás
Arriba