Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/11/10 09:06
Read: times


 
#174977 - Hope this explains
Responding to: ???'s previous message
Yaniv K. said:
Sorry, but I'm kinda new to the whole microcontroller area...

1)I assume IRQ is Interrupt Request, if so then I have nothing to disable as none of the interrupt are enabled in the first place.

2)what is the purpose of those (1<<1) after EECON (how are they setting the needed bits)

3)I see theres a function with a pointer, I am unfamiliar with working with pointers there can you please explain how this function works and how to address it?



void wreeprom(unsigned short ads, unsigned char c)
{
	EECON |= (1<<1);		/* EEE */
	*((unsigned char xdata *)ads) = c;
	EECON = 0x54;			/* SPECIAL SEQUENCE */
	EECON = 0xA4;
	while (EECON & (1<<0)); 	/* EEBUSY */
	EECON = 0x00;			/* brute force */
}
 


There are no function pointers. I have just cast 'ads' as an 8051 'xdata' because the function actually is designed for other processors.

The (SFR & (1<<SFR_BIT)) syntax is just portable C code. So I presume that the following will be specific for some 8051 C compilers.

void wreeprom(unsigned char xdata *ads, unsigned char c)
{
	EEE = 1;        	/* EEE */
	*ads = c;               /* needs no cast cos in signature */
	EECON = 0x54;		/* SPECIAL SEQUENCE */
	EECON = 0xA4;
	while (EEBUSY);         /* EEBUSY */
	EECON = 0x00;		/* brute force */
}

 

and the equivalent read function:
unsigned char rdeeprom(unsigned char xdata *ads)
{
	unsigned char c;
	EEE = 1;		/* EEE */
	c = *ads;               /* no cast needed */
	EEE = 0;		/* EEE */
	return c;
}

 

You can of course use macros for both of these functions. However the compiler will not know whether you are trying to use a non-xdata 'ads'.

I still have not checked the data sheet. The 5131 may or may not worry if there is an interruption between the two SPECIAL instructions. If you do not use IRQs, you do not have to disable them.

David.

List of 23 messages in thread
TopicAuthorDate
EEPROM Read/Write Issues            01/01/70 00:00      
   if it was an external EEPROM            01/01/70 00:00      
   if it was an external EEPROM            01/01/70 00:00      
   Special sequence.            01/01/70 00:00      
      Thanks, but can you please simplyfy it?            01/01/70 00:00      
         Hope this explains            01/01/70 00:00      
   Managed to fix lockups, but it doesnt read/write            01/01/70 00:00      
      You have to choose your API            01/01/70 00:00      
         Already did all that            01/01/70 00:00      
            char vs int            01/01/70 00:00      
            I gave you a function            01/01/70 00:00      
               Still no luck            01/01/70 00:00      
                  unsigned int is not the size of the unsigned int* pointer            01/01/70 00:00      
                  Why not use the function I gave you.            01/01/70 00:00      
                     I did use you function            01/01/70 00:00      
                        My apologies.            01/01/70 00:00      
                           Sorry to keep dragging you back here...            01/01/70 00:00      
                              FLIP is a pain            01/01/70 00:00      
                                 We have progress!            01/01/70 00:00      
                                    Terribly sorry to bump but I really need help            01/01/70 00:00      
                                       Found the solution!            01/01/70 00:00      
                                          Study your C textbooks            01/01/70 00:00      
                                          it cant distinguise the sign bit            01/01/70 00:00      

Back to Subject List