Henri Schultze (henri@fscz-md.boerde.de) wrote: >currently there was a discussion about serial programming and not >reinventing the wheel. Well, that's exactly how I feel, but I >didn't catch up any piece of code. So does somebody of you >have a teenie weenie piece of assembler code for reading serial >data on a 2-wire interface (SCLK,DATA) ? Come on, Henri... Assembly-language programming doesn't get much easier than this. Since you didn't give any details, I'll assume that DATA is valid when SCLK is high, and that you're only reading 8 bits from the interface. #DEFINE DATA [any port] #DEFINE SCLK [any other port] RECEIVE EQU [any file register] ;.... initialize registers, setup port TRIS registers, etc. .... GETBYTE MOVLW 00000001B ;PUT A "1" IN "RECEIVE"'S LSB SO MOVWF RECEIVE ;WE'LL KNOW WHEN WE'VE RECEIVED ;8 BITS. CLRC ;ASSUME WE'LL SHIFT A "0" INTO ;"RECEIVE". GETBIT BTFSS SCLK ;WAIT FOR SCLK TO GO HIGH (CARRY GOTO $-1 ;IS ALWAYS CLEAR HERE). BTFSC DATA ;IF DATA = 0, SKIP AHEAD. SETC ;OTHERWISE, SETUP TO SHIFT A ;"1" INTO "RECEIVE". RLF RECEIVE ;SHIFT THE CARRY INTO "RECEIVE". SKPNC ;IF WE'VE RECEIVED ALL 8 BITS, GOTO DONE ;GO EXIT. BTFSC SCLK ;OTHERWISE, WAIT FOR SCLK TO GO GOTO $-1 ;LOW. GOTO GETBIT ;LOOP BACK. DONE .... ;8 BITS OF RECEIVED DATA ARE IN ;"RECEIVE". FIRST BIT RECEIVED ;IS IN THE MSB, LAST BIT IS IN ;THE LSB. -Andy -- Andrew Warren - fastfwd@ix.netcom.com Fast Forward Engineering, Vista, California