ajit_nayak87
Member level 5
Dear all,
I am looking for example sample code to read and write internal eeprom using PIC16F886. Kindly suggest me sample code here.
I have used Mplab IDE 8.86 with hitech compiler v 9.83. Here is my code I could able to read only 1 from memory location 0X10 in debug mode
I am looking for example sample code to read and write internal eeprom using PIC16F886. Kindly suggest me sample code here.
I have used Mplab IDE 8.86 with hitech compiler v 9.83. Here is my code I could able to read only 1 from memory location 0X10 in debug mode
Code:
#include <pic.h>
#include <htc.h>
#include "delay.h"
__CONFIG(WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & DEBUG_ON);
unsigned char Prg_setting[10];
unsigned char INTYPE[2];
unsigned char OUTTYPE[2];
#define LED RC2
unsigned char Write_flag=0;
void Timer1_Interrupt() {
INTCON = 0b00000000;
PIE1=0b00000001;
PIR1=0x01;
TMR1H=0xFD;
TMR1L=0xE8;
T1CON=0x31;
}
void eeprom_readvalue() {
Prg_setting[0]=eeprom_read(0x10);
Prg_setting[1]=eeprom_read(0x11);
Prg_setting[2]=eeprom_read(0x12);
Prg_setting[3]=eeprom_read(0x13);
}
void Init_Controller() {
OSCCON=0b01110001;
PIE2=0b00010000;
PIR2=0b00000000;
CM1CON0 = 0b00000000;
CM2CON0 = 0b00000000;
TRISC = 0x00;
PORTC =0x00;
TRISB=0X00;
PORTB = 0X00;
TRISA=0x10;
PORTA=0x00;
ADCON0= 0x00;
ANSEL = 0b00000000;
ANSELH=0b00000000;
IOCB=0b00000000;
WPUB=0b00000000;
Timer1_Interrupt();
}
void WRITE_EEPROM() {
GIE=0;
Prg_setting[0]=0X01;
Prg_setting[1]=0X0A;
Prg_setting[2]=0X0B;
Prg_setting[3]=0X0C;
eeprom_write(0X10,Prg_setting[0]);
eeprom_write(0X11,Prg_setting[1]);
eeprom_write(0X12,Prg_setting[2]);
eeprom_write(0X13,Prg_setting[3]);
GIE=1;
}
void interrupt isr(void) {
asm("CLRWDT");
if(TMR1IF == 1) {
TMR1IF =0;
TMR1H=0xFD;
TMR1L=0xE8;
LED=!LED;
// Write_flag=0;
}
}
void main(void) {
Init_Controller();
GIE=1;
PEIE=1;
TMR1IE=1;
eeprom_readvalue();
Write_flag=1;
while(1) {
if(Write_flag==1) {
Prg_setting[0]=0X01;
Prg_setting[1]=0X0A;
Prg_setting[2]=0X0B;
Prg_setting[3]=0X0C;
eeprom_write(0X10,Prg_setting[0]);
eeprom_write(0X11,Prg_setting[1]);
eeprom_write(0X12,Prg_setting[2]);
eeprom_write(0X13,Prg_setting[3]);
Write_flag=0;
eeprom_readvalue();
}
}
}