apricot_star
New Member
Hi anyone knows how to Convert BCD to Binary in PIC18F2620 using c language?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
unsigned int BCDtoI(unsigned int BCD){
unsigned int result;
result=(BCD>>12)*1000;
result+=((BCD>>8)&0x0f)*100;
result+=((BCD>>4)&0x0f)*10;
result+=((BCD)&0x0f);
return result;
}
Assuming it's packed BCD in an integer then the following should work,
Code:unsigned int BCDtoI(unsigned int BCD){ unsigned int result; result=(BCD>>12)*1000; result+=((BCD>>8)&0x0f)*100; result+=((BCD>>4)&0x0f)*10; result+=((BCD)&0x0f); return result; }
Mike.
Hi pommie,
Thanks for the reply, however i was wondering why must it shift by 3 and times 3?
;Decode say a DS1307 minutes from BCD to binary
;minutes = 0x27 BCD
call FN_READ8BIT
movff READ8BIT,MIN
movf MIN,W,BANKED
daw
movwf MIN,BANKED
;MIN is now 27 minutes in binary?