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 support@ccsinfo.com

eeprom

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







eeprom
PostPosted: Sun Mar 09, 2008 10:03 pm     Reply with quote

hi i using PIC18F452 or PIC18F4520

i can write to the eeprom but power off the thing i write in is gone and is clear to FF can u help me. pls thk
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 09, 2008 11:04 pm     Reply with quote

Are you doing this on real hardware, or this being done on a simulator
such as Proteus ?

If it's real hardware then post a short test program that shows the
problem. Also post your compiler version.

Here is an example program of how to save a value to eeprom
when you push a button. Then when the PIC is powered up again,
the program will read the last value that was saved in eeprom
and start the count at the place where it left off:
http://www.ccsinfo.com/forum/viewtopic.php?t=22109&start=17

Note:
That example is for a 16F877. Note that the #rom address for
embedded eeprom data is different for an 18F452. It's 0xF00000.
Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=25522&start=5


Last edited by PCM programmer on Sun Mar 09, 2008 11:21 pm; edited 1 time in total
ruijing
Guest







reply
PostPosted: Sun Mar 09, 2008 11:17 pm     Reply with quote

Yes i do it with real hardware and i use PCW C compiler IDE

Code:

#include "18F452.h" // 18F4520.h
#device ICD=true  // Able in-circuit programmer
#fuses HS,NOWDT,NOLVP,WDT128,NOPUT,NOBROWNOUT,NOPROTECT,NOWRTD,CPD
#use delay(clock=20000000) // 20 MHz
#use rs232(parity=N,BITS=8,xmit=PIN_C6,rcv=PIN_C7)
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "reg18F452.h"
//#define buffer_size 255



static char answer,ans;
static char answer2[5]={"test"};
static char answer3[5]={"baud"};
static char num;
static char num2;
static int8 key,key1,x,y;
static char RxMessage[20];
static char RxMessage2[5];
static int8 next_in,check,count,next_out;
static char baudrate;
#define ADDR 0x50


byte done=0;



void ide()
{

      output_low(PIN_A0); //switch 1
      output_low(PIN_A1); //switch 1
      output_low(PIN_A2); //switch 2
      output_low(PIN_A3); //switch 2
      output_low(PIN_E0); //switch 3
      output_low(PIN_A5); //switch 3
      output_low(PIN_B2); //switch 4
      output_low(PIN_B3); //switch 4

}

void switch2()
   {
      switch (num2)
      {
         case '1':
                  output_low(PIN_E0);
                  output_low(PIN_A5);
                  output_low(PIN_B2);
                  output_low(PIN_B3);
                  output_low(PIN_A2);
                  output_low(PIN_A3);    // for RFout 1
                  printf("\r\nRFout 1\r\n");
                  break;

         case '2':
                  output_low(PIN_E0);
                  output_low(PIN_A5);
                  output_low(PIN_B2);
                  output_low(PIN_B3);
                  output_high(PIN_A2);
                  output_low(PIN_A3);    // for RFout 2
                  printf("\r\nRFout 2\r\n");
                  break;

         case '3':
                  output_low(PIN_E0);
                  output_low(PIN_A5);
                  output_low(PIN_B2);
                  output_low(PIN_B3);
                  output_low(PIN_A2);
                  output_high(PIN_A3);    // for RFout 3
                  printf("\r\nRFout 3\r\n");
                  break;

         case '4':
                  output_low(PIN_E0);
                  output_low(PIN_A5);
                  output_low(PIN_B2);
                  output_low(PIN_B3);
                  output_high(PIN_A2);
                  output_high(PIN_A3);    // for RFout 4
                  printf("\r\nRFout 4\r\n");
                  break;
      }
   }

void switch3()
   {
      switch (num2)
      {
         case '1':
                  output_low(PIN_B2);
                  output_low(PIN_B3);
                  output_low(PIN_A2);
                  output_low(PIN_A3);
                  output_low(PIN_E0);
                  output_low(PIN_A5);    // for RFout 5
                  printf("\r\nRFout 5\r\n");
                  break;

         case '2':
                  output_low(PIN_B2);
                  output_low(PIN_B3);
                  output_low(PIN_A2);
                  output_low(PIN_A3);
                  output_high(PIN_E0);
                  output_low(PIN_A5);    // for RFout 6
                  printf("\r\nRFout 6\r\n");
                  break;

         case '3':
                  output_low(PIN_B2);
                  output_low(PIN_B3);
                  output_low(PIN_A2);
                  output_low(PIN_A3);
                  output_low(PIN_E0);
                  output_high(PIN_A5);    // for RFout 7
                  printf("\r\nRFout 7\r\n");
                  break;

         case '4':
                  output_low(PIN_B2);
                  output_low(PIN_B3);
                  output_low(PIN_A2);
                  output_low(PIN_A3);
                  output_high(PIN_E0);
                  output_high(PIN_A5);    // for RFout 8
                  printf("\r\nRFout 8\r\n");
                  break;
      }
   }
void switch4()
   {
      switch (num2)
      {
         case '1':
                  output_low(PIN_E0);
                  output_low(PIN_A5);
                  output_low(PIN_A2);
                  output_low(PIN_A3);
                  output_low(PIN_B2);
                  output_low(PIN_B3);    // for RFout 9
                  printf("\r\nRFout 9\r\n");
                  break;

         case '2':
                  output_low(PIN_E0);
                  output_low(PIN_A5);
                  output_low(PIN_A2);
                  output_low(PIN_A3);
                  output_high(PIN_B2);
                  output_low(PIN_B3);    // for RFout 10
                  printf("\r\nRFout 10\r\n");
                  break;

         case '3':
                  output_low(PIN_E0);
                  output_low(PIN_A5);
                  output_low(PIN_A2);
                  output_low(PIN_A3);
                  output_low(PIN_B2);
                  output_high(PIN_B3);    // for RFout 11
                  printf("\r\nRFout 11\r\n");
                  break;

         case '4':
                  output_low(PIN_E0);
                  output_low(PIN_A5);
                  output_low(PIN_A2);
                  output_low(PIN_A3);
                  output_high(PIN_B2);
                  output_high(PIN_B3);    // for RFout 12
                  printf("\r\nRFout 12\r\n");
                  break;
      }sleep();
   }

void switch1()
{
if(key==1)
{
switch (num)
   {
      case '1':     //switch 1
               ide();
               break;

      case '2':  output_high(PIN_A0);   //switch 1
               output_low(PIN_A1);    //switch 1
               switch2();
               break;

      case '3':  output_low(PIN_A0);    //switch 1
               output_high(PIN_A1);   //switch 1
               switch3();
               break;

      case '4':  output_high(PIN_A0);   //switch 1
               output_high(PIN_A1);   //switch 1
               switch4();
               break;

      default: break;   // off all antenna
   }


   key=0;
   sleep();

}
}

#INT_EXT
void keyinput()
{
   start_of_program:
      output_high(PIN_B4);
      printf("first 1,2,3,4\r\n");
      for(next_in=0;next_in<=20;next_in++)
     {

             while(!kbhit());
             answer=getch();
             RxMessage[next_in]=answer;
             if(next_in>=1 & next_in<=4)
             {
               if(RxMessage[next_in]!=answer2[next_in-1] && RxMessage[next_in]!=answer3[next_in-1])
                  {
                     printf("\r\n error");
                     goto start_of_program;
                  }
             }

             if(next_in==5)
             {
               check=0;
               for(x=1;x<=4;x++)
               {
                  if(RxMessage[x]!=answer2[x-1])
                  {

                  }else
                  {
                  check=1;

                  }
               }
               for(y=1;y<=4;y++)
               {

                  if (check==1)
                  {

                  }else if(RxMessage[y]!=answer3[y-1] )
                  {
                     printf("\r\n error");
                     goto start_of_program;
                  }
                  else
                  {
                  check=2;
                  }
               }

             }
             if(next_in>5 && RxMessage[next_in]=='\n' )
             {
               goto next_run;
             }

      }

      next_run:

      printf("\r\n");
      for(next_out=1;next_out<=next_in;next_out++)
          putc(RxMessage[next_out]);

      come_here:

      printf("\r\nContinue (Y,N)?\r\n");

      do {

         ans=getch();

      }while(ans!='y' && ans!='n');


      if (ans=='y')
      {
         num=Rxmessage[6];
         done=Rxmessage[6];
         num2=Rxmessage[8];

         if(check==2)
         {

            switch( num )
            {

               case '0' : set_uart_speed(9600);
                         write_eeprom(ADDR,done);  break;

               case '1' : set_uart_speed(19200);
                         write_eeprom(ADDR,done);   break;

               case '2' : set_uart_speed(38400);
                         write_eeprom(ADDR,done);  break;

               case '3' : set_uart_speed(57600);
                          write_eeprom(ADDR,done);  break;
            }

         }else if(check==1)
             {
                  key=1;
             }


      }
      output_low(PIN_B4);
}


void main(void)
{

enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);

  baudrate=(char)read_eeprom(ADDR);


if(baudrate>=0 && baudrate<=3 )
{
   switch(baudrate)
   {
      case '0' : set_uart_speed(9600);   break;

      case '1' : set_uart_speed(19200);   break;

      case '2' : set_uart_speed(38400);   break;

      case '3' : set_uart_speed(57600);  break;
   }
}
else
 set_uart_speed(9600);




for(;;)
{
      switch1();
}

}


thk
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 09, 2008 11:22 pm     Reply with quote

That's a lot of code. I was editing my post while you were doing
your post. I added a link to a sample program. Look at that first.
ruijing
Guest







rely
PostPosted: Mon Mar 10, 2008 12:30 am     Reply with quote

PCM programmer wrote:
That's a lot of code. I was editing my post while you were doing
your post. I added a link to a sample program. Look at that first.



still cannot
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