Il giorno Thu, 7 Dec 2006 20:55:29 +0100, "SBS" ha scritto:
Dopo la tua richiesta in pvt commento il programma assembler sul ng perchè potrebbe interessare anche a qualcun altro:
Questa routine simula una SPI hardware
RecByteSPI: Ldi R16,0x80 ; Ultimo bit a 1 ;serve per evitare un contatore apposito Loop: Sbis PinD,Clk ;Skip Bit I/o Set = SBIS Rjmp Loop ;queste due istruzioni gestiscono il primo loop ;finchè il pin CLK resta basso viene esguito il JMP ;quando il pin sale, 'skippa' cioè salta l'istruzione successiva.
Clc ;reset Carry Flag Sbic PinD,Data ;Skip Bit I/o Clear = SBIC Sec ;set Carry Flag ;queste tre istruzioni gestiscono la polarità del dato, ;mettendo alto o basso il Carry flad a seconda dello ;stato del pin DATA
Rol R16 ;C>b7 b0>C ;questa istruzione shifta il Carry sul registro da sinistra ;verso destra
Brcc Loop ;questa salta a Loop se il Carry Flag è a zero ;se hai shiftato 8 bits il primo 80H su R16 si trova ora sul Carry flag Ret ;dopo 8 bits torna al chiamante col datoda SPI in R16.
Se vuoi analizzare le istruzioni, qui ci sono tutte:
-- ciao Stefano