[an error occurred while processing this directive]
[an error occurred while processing this directive]
|
#include /* R/W eeprom on PIC16F87x example: main() Created for PICuWEB - PIC micros and C This file is in use for a commercial product, with approx. 7000 lines of C, and */ static bit gie_temp; EEIF=0; //this is necessary in case this EEPROM write #define MY_EEPROM_READ(addr) \ unsigned char my_eeprom_read(unsigned char addr) unsigned int my_eeprom_read_int(unsigned char addr) void my_eeprom_write_int(unsigned char addr, unsigned int data)
E-mail:
info@telesys.ru
{
my_eeprom_write(addr,data);
if (my_eeprom_read(EEPROM_FORMAT_IN_PROGRESS)==TRUE) etc;
}
http://www.workingtex.com/htpic
(c)2001 Shane Tolmie
copies of this code are currently running on 1100+ 16F876-based units worldwide.
void my_eeprom_write(unsigned char addr, unsigned char value)
{
//see 'writing to eeprom memory' in PIC16F876 manual
//was preceded by a program memory write
EEADR=(unsigned char)(addr);
EEDATA=(unsigned char)(value);
EEPGD=0; //write to EEPROM, not data memory
gie_temp=GIE; //save the status of GIE
WREN=1; //enable writes
GIE=0;
EECON2=0x55;
EECON2=0xAA;
WR=1;
while (!EEIF)
{
//do nothing - wait WR to be cleared in hardware
}
EEIF=0; //so it wont trigger false interrupts
WREN=0; //disable writes
GIE=gie_temp; //restore GIE to previous value
}
\
( (EEADR=((unsigned char)(addr))), \
(EEPGD=0), \
(RD=1), \
((unsigned char)EEDATA) )
{
EEADR=(unsigned char)addr;
EEPGD=0;
RD=1;
return (unsigned char)EEDATA;
}
{
return ((unsigned int)(eeprom_read(addr)) | ((unsigned int)((unsigned int)(eeprom_read((unsigned char)(addr+1)))<<8)));
}
{
eeprom_write(addr,(unsigned char)(data & 0xFF));
eeprom_write((unsigned char)(addr+1),(unsigned char)(data>>8));
}
Ответы