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.

[PIC] convert Hours + Minutes BCD to minutes Hex word

Status
Not open for further replies.

igeorge

Member level 5
Joined
Oct 31, 2010
Messages
85
Helped
1
Reputation
2
Reaction score
2
Trophy points
1,288
Activity points
1,956
Hello,
I have a big issue and i do not know where to find the solution.
I have a PIC18F87K90. It has a real time clock. The time and date are out on BCD.
I setup on the EEprom 10 sets of hours and minutes when i want the pic to put some outputs ON
The data stored on EEprom is minutes
Example :
For 06:30 i have
6*60=360 minutes + 30 minutes = 390 minutes.
On my eeprom i have at address $205 data 01 and at address $206 data 86.
In total for 6:30 converted to minutes = 390 minutes i have a Word = $0186
At 6:30, the pic give me
06 BCD and 30 BCD
I do not know how to convert them to a word so i can compare with the value from eeprom.
Please help.
Thank you very much.
 

Are you working in C language or assembler? or something else?

In C it looks quite simple:

if (((BCD_Hours * 60) + (BCD_Minutes)) == ((EEPROM_Minutes_High << 8) + EEPROM_Minutes_Low))
 

try out this

Code:
char bcd2bin(char bcd_value) // Input range - 00 to 99.
{
   return ((bcd_value & 0x0f) + (((bcd_value >> 4) & 0x07) * 10));
}

then use typecasting from char to int. Hope you got the idea.

Enjoy
 

Hi,

If you knew the values which the pic will give in respective hours. Why dont you save that value directly in eeprom instead of word value, sothat you can compare it directly and save this extra computation?.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top