ecaits
Member level 4
- Joined
- Jan 16, 2014
- Messages
- 76
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 579
Dear Friends,
I have used EEPROM memory to store the character by keypad. I have used EEPROM memory from byte 0 to byte 1 and I have store one digit to each location as character (by 4x4 keypad). I am working on PIC16F877 using Hi-Tech C compiler.
Say,
Byte 0 = 1,
Byte 1 = 4,
Byte 2 = 6,
Byte 3 = 3,
Byte 4 = 1.
Now I want to make it integer, say total = 14631.
I have used following logic to do the task.
int Value, total=0, p=10000;
for(i=0; i<5; i++)
{
Value= eeprom_read(i); // To read the digit
Value= Value-48; // to make it integer
total = total+(Value*p); // to make total
p=p/10;
}
But it is not giving proper output.
Can anybody suggest other logic or where is the problem in above logic.
Thank you in advance,
Nirav
I have used EEPROM memory to store the character by keypad. I have used EEPROM memory from byte 0 to byte 1 and I have store one digit to each location as character (by 4x4 keypad). I am working on PIC16F877 using Hi-Tech C compiler.
Say,
Byte 0 = 1,
Byte 1 = 4,
Byte 2 = 6,
Byte 3 = 3,
Byte 4 = 1.
Now I want to make it integer, say total = 14631.
I have used following logic to do the task.
int Value, total=0, p=10000;
for(i=0; i<5; i++)
{
Value= eeprom_read(i); // To read the digit
Value= Value-48; // to make it integer
total = total+(Value*p); // to make total
p=p/10;
}
But it is not giving proper output.
Can anybody suggest other logic or where is the problem in above logic.
Thank you in advance,
Nirav