CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

EEPROM 18F87K22 PROBLEM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
peppapig



Joined: 16 Sep 2016
Posts: 1

View user's profile Send private message

EEPROM 18F87K22 PROBLEM
PostPosted: Fri Sep 16, 2016 6:13 am     Reply with quote

PIC: 18F87K22
COMPILER: PCWHD 4.114

Hello guys,

I have a weird situation with my internal eeprom.

My program always save the last data in all positions of eeprom, i believe that must be a problem with my compiler, take a look at my code.

My variable always return 104 in all position, like he always save the last data of write_eeprom in all position of my memory.
Code:
#include "configuracao.c"

unsigned int leitura;

void main()
{
   printf("Start... \n\r");

   while(true)
   {
      write_eeprom (1, 29);
      write_eeprom (40, 104);

      leitura = 0;
      leitura = read_eeprom(1);
      
      printf ("%u", leitura);
      
      delay_ms(2000);
   }
}


Code:
/*configuracao.c*/

#include    <18F87K22.h>
#fuses     HSH,NOPROTECT,INTRC_IO
#use       delay(clock=8M)
#use       rs232(baud=9600, xmit=pin_g1, rcv=pin_g2, parity=N, stop=1)
   
//PORT A
#use fixed_io(a_outputs = pin_a4,pin_a5,pin_a6,pin_a7)
//PORT B
#use fixed_io(b_outputs = pin_b1,pin_b2,pin_b3,pin_b4,pin_b5,pin_b6,pin_b7)
//PORT C
#use fixed_io(c_outputs = pin_c0,pin_c1,pin_c2,pin_c3,pin_c4,pin_c5,pin_c6,pin_c7)
//PORT D
#use fixed_io(d_outputs = pin_d0,pin_d1,pin_d2,pin_d3,pin_d4,pin_d5,pin_d6,pin_d7)
//PORT E
#use fixed_io(e_outputs = pin_e0,pin_e1,pin_e2,pin_e3,pin_e4,pin_e5,pin_e6,pin_e7)
//PORT F
#use fixed_io(f_outputs = pin_f1,pin_f2,pin_f3,pin_f4,pin_f5,pin_f6,pin_f7)
//PORT G
#use fixed_io(g_outputs = pin_g0,pin_g3,pin_g4)
//PORT H
#use fixed_io(h_outputs = pin_h0,pin_h1,pin_h2,pin_h3,pin_h4,pin_h5,pin_h6,pin_h7)
//PORT J
#use fixed_io(j_outputs = pin_j0,pin_j1,pin_j2,pin_j3,pin_j4,pin_j5,pin_j6,pin_j7)

#byte porta = 0x05
#byte portb = 0x06
#byte portc = 0x07
#byte portd = 0x08
#byte porte = 0x09
#byte portf = 0x10
#byte portg = 0x11
#byte porth = 0x12
#byte portj = 0x13
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Sep 16, 2016 2:47 pm     Reply with quote

don't know about the eeprom but the I/O ports are not at 05h ...13h, ,according to the datasheet that are at 0f80h...0f85h according to table 6-2,page 101.

Jay
guy



Joined: 21 Oct 2005
Posts: 297

View user's profile Send private message Visit poster's website

PostPosted: Sat Sep 24, 2016 1:06 pm     Reply with quote

Quote:
My program always save the last data in all positions of eeprom

I doubt it. Most probably the read_eeprom is getting an old value from the register. Send us the .LST file or upgrade the compiler. Cool
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Sep 26, 2016 7:06 am     Reply with quote

There are lots of problems even with the code incomplete.

First the addresses for the registers have been copied from a PIC16, and are invalid for a PIC18. Duh.
Why these are being used at all (especially given all the fixed_io statements, which these will bypass), is questionable, but if they are needed, they need to be corrected. Temtronic has pointed this out.

Then the fuses are wrong. First, two oscillators being selected (INTRC, and HSH....), and some basic settings missing. It looks like the code has been 'cut and pasted' from something from a basic PIC16, with no attempt to handle the hardware differences of the PIC18, and with stuff set wrongly.....

Then we have the big one, that this is a very early compiler for this chip. The 87K22, was only released in 2010, and guess when 4.114 dates from....
The first CCS compiler with this chip was about 4.112, and generally many functions were often 'not right' for the first few releases when a chip came out in those days.
Compiled with 4.118, with some working fuses, the code runs fine.

Code:

#include <18F87K22.h>
#fuses NOPROTECT, INTRC_IO, SOSC_DIG, NOXINST, NOWDT, NOEXTADDRSFT, NOFCMEN
#fuses NOIESO
#use delay(clock=8m)
#use rs232(baud=9600, UART1, parity=N, stop=1)

void main()
{
   int8 leitura;
   printf("Start... \n\r");

   while(true)
   {
      write_eeprom (1, 29);
      write_eeprom (40, 104);

      leitura = 0;
      leitura = read_eeprom(1);
     
      printf ("%u\n", leitura);
     
      delay_ms(2000);
   }
}


Prints 29
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group