-Andy wrote:
>
> Come on, Henri... Assembly-language programming doesn't get much easier
> than this.
Ohh. Shame on me :-)
But I mostly end up with some optimized code from some "AN..." of the
Embedded Control Handbook". So I like to see something good. And two
persons (mostly) have two different ideas. So I could already catch
some good idea from your code. Thanks for that.
>
> 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.
>
Well, I didn't want bother you all to much. So I reduced the problem
to a small kernel.
Actually I have to interface an ADC AD7714 to a PIC hostcontroller.
Things get a little bit easier when I (e.g. the PIC) provide the
SCLK. BTW: it's also a 3-wire interface, but that doesn't make a
difference in general. I have to send lots of control data to the
ADC, then initiate a read-cycle, then read 16/24bit of data.
Then I'll do just something with that conversion data I hopefully get.
But plenties of time probably will walk throu the land before I get
this far.
Bye
Henri
--
{Quote hidden}> #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
--
=============> The sanest place is still behind the trigger <===============
[]-------------------------------[]---------------------------------------[]
|| Henri Schultze || Magdeburg D-39122 Alt-Fermersleben 88 ||
|| .....henriKILLspam
.....fscz-md.boerde.de || The Cracker Company ||
[]-------------------------------[]---------------------------------------[]
=================> in a world of compromise, some don't <===================