#!/usr/local/bin/php
Ajouter les deux fichiers ci-dessous (eeprom.h et eeprom.c) à votre projet. Inclure le fichier eeprom.h dans chaque fichier utilisant les fonctions eeprom.
eeprom.h
/* Copyright (C) 2008 Philippe Arlotto arlotto@univ-tln.fr IUT GEII Univerity of Toulon Include file for PIC18 EEPROM read write utilities */ #ifndef _EEPROM_H #define _EEPROM_H #define _EEPROM_WRITE_ENABLE_GIE // comment out if interrupts are not used. unsigned char EEWriteFloat(float f, unsigned char adr); float EEReadFloat(unsigned char adr); unsigned char EEWriteInt(int entier, unsigned char adr); int EEReadInt(unsigned char adr); unsigned char EEReadByte(unsigned char adr); void EEWriteByte(unsigned char data,unsigned char adr); #endif
eeprom.c
/* Copyright (C) 2008 Philippe Arlotto arlotto@univ-tln.fr IUT GEII Univerity of Toulon PIC18 EEPROM read write utilities This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "eeprom.h" #include <p18cxxx.h> unsigned char EEWriteFloat(float f, unsigned char adr) { int i ; unsigned char *p ; p = (unsigned char *)&f ; for(i=0;i<sizeof(float);i++) { EEWriteByte(*p,adr); p++; adr++; } return adr ; } unsigned char EEWriteInt(int entier, unsigned char adr) { int i ; unsigned char *p ; p = (unsigned char *)&entier ; for(i=0;i<sizeof(int);i++) { EEWriteByte(*p,adr); p++; adr++; } return adr ; } float EEReadFloat(unsigned char adr){ float f ; int i ; unsigned char * p ; p = (unsigned char*) &f; for(i=0;i<sizeof(float);i++) { *p=EEReadByte(adr); p++; adr++; } return f ; } int EEReadInt(unsigned char adr){ int Entier ; int i ; unsigned char * p ; p = (unsigned char*) &Entier; for(i=0;i<sizeof(int);i++) { *p=EEReadByte(adr); p++; adr++; } return Entier ; } unsigned char EEReadByte(unsigned char adr) { EEADR = adr ; EECON1bits.EEPGD = 0 ; EECON1bits.CFGS = 0 ; EECON1bits.RD = 1 ; return EEDATA ; } void EEWriteByte(unsigned char data,unsigned char adr) { EEADR = adr ; EEDATA = data ; EECON1bits.EEPGD = 0 ; EECON1bits.CFGS = 0 ; EECON1bits.WREN = 1 ; INTCONbits.GIE = 0 ; EECON2=0x55; EECON2=0xAA; EECON1bits.WR = 1 ; #ifdef _EEPROM_WRITE_ENABLE_GIE INTCONbits.GIE = 1 ; #endif while(EECON1bits.WR ) ; EECON1bits.WREN = 0; }