Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

EEPROM code is not working

Status
Not open for further replies.

ADGAN

Full Member level 5
Full Member level 5
Joined
Oct 9, 2013
Messages
295
Helped
4
Reputation
8
Reaction score
4
Trophy points
18
Visit site
Activity points
1,837
Hi! This is the code I wrote for the internal EEPROM of PIC16F887 using MikroC pro. But when I simulate in Proteus it seems to be not working. What is wrong with the code?

Code:
#define Highest(param) ((char *)&param)[3]
#define Higher(param) ((char *)&param)[2]
#define Hi(param) ((char *)&param)[1]
#define Lo(param) ((char *)&param)[0]
unsigned short int t1,t2,t3,t4;
unsigned long pulses;

void main(){
pulses = (count*65536)+ (TMR1H<<8 | TMR1L);
      
      EEPROM_Write(0x00, Highest(pulses));
      Delay_ms(20);
      EEPROM_Write(0x01, Higher(pulses));
      Delay_ms(20);
      EEPROM_Write(0x02, Hi(pulses));
      Delay_ms(20);
      EEPROM_Write(0x03, Lo(pulses));
      Delay_ms(20);
      
      t1 = EEPROM_Read(0x00);
      Delay_ms(20);
      t2 = EEPROM_Read(0x01);
      Delay_ms(20);
      t3 = EEPROM_Read(0x02);
      Delay_ms(20);
      t4 = EEPROM_Read(0x03);
      Delay_ms(20);
      pulses = ((t4 << 0) & 0xFF) + ((t3<< 8) & 0xFF00) + ((t2 << 8) & 0xFF0000) + ((t1 << 8) & 0xFF000000) ;
}
 
Last edited:

Thanks for the reply. This is just a part of the code. I have missed that. I want to count the pulses, when I switch off and on the system it should continue counting from the last pulse. But when I restart it doesn't continue from the last pulse.
 

Always post your full code with error window !!! In that way it might be easier to debug the program!!
 
Last edited:

Have you created .bin file for eeprom in Proteus. If not then in mikroC goto tools EEPROM Editior and save the eeprom file to .ihex file. Rename the file as .hex. Use hex2bin from Keil and convert this file to .bin file. In proteus load this .bin file for eeprom.
 

Thanks for the reply, I can't run the hex2bin converter since I'm using Windows 7(I tried windows XP also but still can't run that). What shall I do?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top