Interesting... Looks like one should have to "OR" the C from the ADD with the C from the DAW and feed the result into the next ADD... Would it work if the DAW never clears the C but leave it set if set before (and set C if needed) ? Have to check my own routines once again :-( I did the following : add_bcd ; add INCH:INCL to BCDH:BCDL ; Adds a BCD coded "increment" to a BCD value. movf INCL, w ; Load low byte of increment addwf BCDL, w ; Add to low BCD byte daw ; Adjust movwf BCDL ; Store back adjusted low BCD byte movf INCH, w ; Load high byte of increment addwfc BCDH, w ; Add to high BCD byte daw ; Adjust movwf BCDH ; Store back adjusted high BCD byte return This have been working for the values I have tested with. I my case the "increment" have been powers of 2 between 0x0000 and 0x0512 (coded as BCD). But, using the "right" values, I expect this code to have the same problem as you are seeing. Gotta think about this a while... Jan-Erik S=F6derholm -----Original Message----- From: Jon M (Mike) Jones [mailto:pmjones3@ATTBI.COM] Sent: den 4 februari 2003 11:15 To: PICLIST@MITVMA.MIT.EDU Subject: Re: [PIC]: Binary to Packed BCD Conversion Problem Thanks for the reminder, I made that mistake once or twice myself. On the assumption that 0x70 and 0x80 are valid packed bcd numbers I just finished a simple test to isolate the problem. The shortened = version of the code goes like this; (Note: 18F452 processor, checking apparent addwfc and/or daw problem) cblock 0x00 binvar:1 bcdval:1 end clrc movf binvar,w addwfc binvar,w daw movwf bcdval Test 1: set binvar =3D 0x70 after the addwfc, WREG =3D 0xE0 Carry =3D 0 after the daw, WREG =3D 0x40 Carry =3D 1 So far so good! Test 2 set binvar =3D 0x80 after the addwfc, WREG =3D 0x00 Carry =3D 1 after the daw, WREG =3D 0x60 Carry =3D 0 What happened to the carry bit ?? I rather expected it to still be there. In fairness, the data sheet doesn't say much about how or why the carry bit is affected, it just say that it is affected. There may be = other documents that give more detailed information about the status bits during and after a 'daw' but I haven't found any yet. Going back to the original problem: I don't know how completely valid this is yet but, after a very brief test, it appears that if I save = the carry bit after the addwfc and restore it after the daw, all may be well. Mike Jones ----- Original Message ----- From: "Jan-erik Svderholm (QAC)" To: Sent: Tuesday, February 04, 2003 12:11 AM Subject: Re: [PIC]: Binary to Packed BCD Conversion Problem I wrote a routine to convert a bin value to BCD some time ago. One thing that I missed about the DAW instruction, is that DAW "Decimal adjust W" when W containes the result of an addition of two other values *which both was in BCD format before the addition*. So you can not add two *binary* values and then use DAW on the result. You'll get all kinds of funny results. (And if one read the data sheet carefully, this is clearly written there...) I have not checked is this is the case for your code, but anyway... Jan-Erik Svderholm. -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body