Hi, gah I made an error in the posted snippet: the last lines in the macro should ofcource be: MOVLW 0x00 ; value to low, set to min ADDLW MinBCD ; finally fix-up W instead of the previous: > MOVLW MinBCD-0x01 ; value to low, set to min > ADDLW 0x01 ; finally fix-up W Stupid misstake, I appologise. New revised macro: CHECK_W_BCD_DIGIT_CLAMP MACRO MinBCD,MaxBCD,Temp,KnownZero MOVWF Temp ; save input MOVFF KnownZero,STATUS ; clear status reg (C and DC required for DAW) DAW ; decimal adjust w, -> BCD XORWF Temp,F ; check if w has changed=20 BTFSS STATUS,Z MOVLW MaxBCD ; w has changed, ie input was not BCD, set to maxvalue ; check if below max ADDLW LOW(0xFF-MaxBCD) BTFSC STATUS,C MOVLW 0xFF ; overflow set to max ; now check for minium value ADDLW LOW((MaxBCD-MinBCD)+0x01) BTFSS STATUS,C MOVLW 0x00 ; value to low, set to min ADDLW MinBCD ; finally fix-up W ENDM /Tony -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads