Programming PIC16628A- Program section is written but EEPROM is not written - Page 1
Forum section: electronics / general

author: asadulhuq
author_rank: Contributor
timestamp: September 05, 2020, 06:54:11 am
content: Dear All,I am trying to write a HEX file into the PIC16F628 using a PICkit-2 compatible programmer. The HEX file was produced using MikroC Pro for PIC.Please see 2 attached pictures (Before and After HEX file loading).Following is the relevant code segment://////// TIMER project at DIYfan.blogspot.com /Modified by Psyklops/Asadul Huq//PIC16F628A--4mhz external Crystal osc. Compiler MikroC pro for PIC v7.6//Note://This timer starts without a trigger and as soon as power is applied with a//preset time stored in EEPROM. AH. 27-08-2020//Code V.12 AH. 04-09-2020#define OneSecondDefault 977 // default value for OneSecond#define my_delay_30() Delay_ms(30)#define my_delay_50() Delay_ms(50)#define my_delay_500() Delay_ms(500)#define my_debounce() Delay_ms(100)// LCD pinssbit LCD_RS at RA1_bit;sbit LCD_EN at RA0_bit;sbit LCD_D4 at RB7_bit;sbit LCD_D5 at RB6_bit;sbit LCD_D6 at RB5_bit;sbit LCD_D7 at RB4_bit;sbit LCD_RS_Direction at TRISA1_bit;sbit LCD_EN_Direction at TRISA0_bit;sbit LCD_D4_Direction at TRISB7_bit;sbit LCD_D5_Direction at TRISB6_bit;sbit LCD_D6_Direction at TRISB5_bit;sbit LCD_D7_Direction at TRISB4_bit;//Output settingssbit SND at RA2_bit; // define beep sound pinsbit OUT at RB3_bit; // define Relay OUT pinsbit RUN_IND at RA4_bit;sbit END_ALARM at RA3_bit;// PUSH BUTTON connectionssbit START_sw at RA5_bit;sbit RESET_sw at RB0_bit;sbit MIN1_sw at RB1_bit; // MIN1 = (MIN++) buttonsbit MIN2_sw at RB2_bit; // MIN2 = (MIN--) button// Variablesint cnt, OneSecond; // tmp;unsigned short seconds, minutes, sound_sec;unsigned short Set_seconds, Set_minutes;bit a, start, oldF1;//char str1;void Read_EEPROM() { ////Load from eepromif (EEPROM_Read(0x16) == 1){my_delay_30();minutes = EEPROM_Read(0x11);my_delay_30();seconds = EEPROM_Read(0x12);my_delay_30();}}void Write_EEPROM() {Delay_100ms();EEPROM_Write(0x16,1);my_delay_50();//EEPROM_Write(0x12,seconds);EEPROM_Write(0x12,0);my_delay_50();EEPROM_Write(0x11,minutes);my_delay_50();//EEPROM_Write(0x10,hours);//Delay_ms(50);}... ////////////////////////////////////Please note that the complete code is attached bellow.Seems that the Program memory section is written successfully. However, the EEPROM data storage section is not written (Please see figure-After. All locations are FF). By the way, while I simulate with the Proteus, the PIC is loaded with the HEX file data. When simulation starts EEPROM data is loaded. So, in the Proteus EEPROM data is loaded successfully. Does not it mean that the HEX file contains the EEPROM data? But that data is not written in the PIC in real life.I will appreciate it so much if one can assist me to solve the issue. Thanks.

author: Lindley
author_rank: Regular Contributor
timestamp: September 05, 2020, 08:45:50 am
content: Hi,You need to show your program code.Simulation programs can work differently to actual programming up.

author: asadulhuq
author_rank: Contributor
timestamp: September 05, 2020, 08:51:19 am
content: Thanks. I will attach the source program with the original question.

author: asadulhuq
author_rank: Contributor
timestamp: September 05, 2020, 03:17:32 pm
content: Hi there,Complete code is now attached with the original post. Please have a look. Thanks.

author: Lindley
author_rank: Regular Contributor
timestamp: September 05, 2020, 03:40:22 pm
content: Hi,Not into Mikro C, so hopefully others can help out with the detail, but from your code you show a routine for Reading from EEprom and one for Writing Data to EEprom for use once your code is running.Your question seems to say you want to load EEprom with data at programming time, but you do not appear to have any code to do that.Expect something along these lines is whats needed in your code to load EEprom with data, with the correct memory location for the chip you are using,__EEPROM_DATA(0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07);or#pragma romdata eedata_scn=0xf00000rom eedata_values = {0, 1, 2, 3, 4, 5, 6, 7};#pragma romdataAgain not into MikroC but your code does not appear to have any Config Bits, though do not know if thats done separately in MikroC ?

author: asadulhuq
author_rank: Contributor
timestamp: September 05, 2020, 03:53:57 pm
content: Hello,Now screenshot of config settings (for MikroC Pro for PIC) has been attached the main post. Thanks for your effort.

author: Lindley
author_rank: Regular Contributor
timestamp: September 05, 2020, 04:14:08 pm
content: If you are wanting to load EEprom at programming time, seems MikroC has its own EEprom Editor tool , if thats what you are trying to do ?

author: asadulhuq
author_rank: Contributor
timestamp: September 05, 2020, 04:53:13 pm
content: Hello,Yes i am trying to do that. However, I did not know that MikroC needed a separate tool to write preset data into the EEPROM during writing a PIC. Thanks for your information I will try to use that tool.

author: Bud
author_rank: Super Contributor
timestamp: September 05, 2020, 05:47:33 pm
content: As Lindley said you do not seem to have EEPROM data initialization directives in your code, hence nothing is written in it during chip programming. Can you point out the part in your code that you believe would initialize the EEPROM ?

author: asadulhuq
author_rank: Contributor
timestamp: September 06, 2020, 04:13:29 am
content: Hi there. I am new to Microcontroller programming. I didn't know that I needed additional steps to record my preset data in EEPROM while downloading hex file into the Pic device. Furthermore, simulation with Proteus recorded preset data while I inserted hex file into the pic. So, I thought the hex file was complete and would store preset data into EEPROM storage section while burning the Pic. Now, I understand that I have to include additional code to store preset data in EEPROM in real life. Now, I shall add additional statements in the code to store preset data.Thanks again.