| ??? 04/10/10 22:58 Read: times |
#174970 - Special sequence. Responding to: ???'s previous message |
No. I have not looked closely at your code. And I am going to bed, so have not checked the data sheet either.
However, with their AVR devices, you have to use a special sequence of instructions that should execute within a certain # of cycles. So you normally disable IRQs, write the sequence to enable writes, write the value, wait for completion, restore IRQ status.
void wreeprom(unsigned short ads, unsigned char c)
{
#ifdef _i8051
#if defined(_AT89C5131_)
EECON |= (1<<1); /* EEE */
*((unsigned char xdata *)ads) = c;
EECON = 0x54; /* SPECIAL SEQUENCE */
EECON = 0xA4;
while (EECON & (1<<0)); /* EEBUSY */
// EECON &= ~(1<<1); /* EEE */
EECON = 0x00; /* brute force */
#elif defined(_AT89S8252_)
WMCON |= (1<<3); /* EEMEN */
WMCON |= (1<<4); /* EEMWE */
*((unsigned char xdata *)ads) = c;
while ((WMCON & (1<<1)) == 0) ; /* WDTRST */
WMCON &= ~((1<<3)|(1<<4)); /* EEMEN | EEMWE */
#else
#error _i8051 without EEPROM
#endif
#endif
}
From an old source file. I presume that the 5131 code is ok. Note that you may need to disable IRQs David. |
| Topic | Author | Date |
| 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 |



