TODOPIC

Microcontroladores PIC => Todo en microcontroladores PIC => Mensaje iniciado por: nahueldiaz1992 en 18 de Octubre de 2013, 21:42:31

Título: SPI - Error de Proteus ? el esclavo no responde cuando uso dos micros. y simulo
Publicado por: nahueldiaz1992 en 18 de Octubre de 2013, 21:42:31
Hola gente como va ? estoy en el medio de un proyecto que alargue por cuestiones de conocimiento en el tema .... el caso es que intento de lograr una comunicacion por medio del protocolo SPI me ayude con el ejemplo de microchip pero la cuestion es la siguiente :

MAESTRO:     Logre sacar las señales necesarias del maestro , las cuales serian sck , sdo (datos de salida ) - envio un dato fijo para probar - y CS (chip select) , todo bien por separado , analizado con el SPI debugger
(http://imageshack.us/a/img196/2380/x7hf.png)
y tambien tengo un error de perdida de datos a medida que transcurre la comunicacion -.-
(http://imageshack.us/a/img513/7505/j9s0.png)

ESCLAVO:    Logre Comprobar tambien que el esclavo recibe la señal , la procesa y me devuelve una data fija ya preparada  , tambien por separado y analizado por el spi debugger
(http://imageshack.us/a/img138/5043/moz6.png)


El problema comienza cuando meto en un solo circuito ambos micros , maestro y esclavo , con ambos programas conectados entre si y el spi debugger como monitor asi analizando data de entrada y salida , ya que en este caso puedo ller los datos que envio pero no recibo ningun dato ... mi pregunta seria ... estoy mal yo o el proteus ?? a alguno le paso algo parecido ? alguien que me pueda ayudar en el tema ?




codigos :




Maestro :


     LIST      p=16F88              ; list directive to define processor
     #INCLUDE <P16F88.INC>          ; processor specific variable definitions

;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file.  See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------

     __CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _INTRC_IO
     __CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF

;------------------------------------------------------------------------------
;
; VARIABLE DEFINITIONS
;
; Available Data Memory divided into Bank 0 through Bank 3.  Each Bank contains
; Special Function Registers and General Purpose Registers at the locations
; below: 
;
;           SFR           GPR               SHARED GPR's
; Bank 0    0x00-0x1F     0x20-0x6F         0x70-0x7F   
; Bank 1    0x80-0x9F     0xA0-0xEF         0xF0-0xFF 
; Bank 2    0x100-0x10F   0x110-0x16F       0x170-0x17F
; Bank 3    0x180-0x18F   0x190-0x1EF       0x1F0-0x1FF
;
;------------------------------------------------------------------------------

    CBLOCK 0x20 ; Sample GPR variable registers allocated contiguously
        MYVAR1  ; User variable
        MYVAR2  ; User variable
        MYVAR3  ; User variable
    ENDC

Ctr0 EQU 0x20 ; Counter variable - sent to SPI
Dly0 EQU 0x21 ; Delay Variable (low byte)
Dly1 EQU 0x22 ; Delay Variable (high byte)
#define CS 0x02 ; PORTA,2

W_TEMP         EQU        0x7D  ; w register for context saving (ACCESS)
STATUS_TEMP    EQU        0x7E  ; status used for context saving (ACCESS)
PCLATH_TEMP    EQU        0x7F  ; variable used for context saving

;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 16F88 has 256 bytes of non-volatile EEPROM, starting at address 0x2100
;
;------------------------------------------------------------------------------

DATAEE    ORG  0x2100
    DE    "MCHP"  ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3

;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------

RESET     ORG     0x0000            ; processor reset vector
          PAGESEL START
          GOTO    START             ; go to beginning of program

;------------------------------------------------------------------------------
; INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------

ISR       ORG     0x0004            ; interrupt vector location

;         Context saving for ISR
          MOVWF   W_TEMP            ; save off current W register contents
          MOVF    STATUS,W          ; move status register into W register
          MOVWF   STATUS_TEMP       ; save off contents of STATUS register
          MOVF    PCLATH,W          ; move pclath register into W register
          MOVWF   PCLATH_TEMP       ; save off contents of PCLATH register

;------------------------------------------------------------------------------
; USER INTERRUPT SERVICE ROUTINE GOES HERE
;------------------------------------------------------------------------------

;         Restore context before returning from interrupt
          MOVF    PCLATH_TEMP,W     ; retrieve copy of PCLATH register
          MOVWF   PCLATH            ; restore pre-isr PCLATH register contents
          MOVF    STATUS_TEMP,W     ; retrieve copy of STATUS register
          MOVWF   STATUS            ; restore pre-isr STATUS register contents
          SWAPF   W_TEMP,F
          SWAPF   W_TEMP,W          ; restore pre-isr W register contents
          RETFIE                    ; return from interrupt

;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------

START   ; Set up the SPI Support
      BANKSEL TRISA ; BANK 1
      movlw 0x00 ; Set PORTA as
      movwf TRISA ; all Outputs
      movlw 0x01 ; Turn off A/D
      movwf ADCON0 ; so PORTA can be used
; Set up the SPI Port
      BANKSEL TRISB ; BANK 1
      movlw 0x02 ; SCK is output (Master), SDI is input,   
      movwf TRISB ; SDO is output, all others output
      movlw 0x40 ; Mode 1,1 SPI, middle of output
      movwf SSPSTAT ; time sampling
      BANKSEL SSPCON ; BANK 0
      movlw 0x31 ; Mode 1,1 SPI Master Mode, 1/16 Tosc bit
time
      movwf SSPCON ; SSP is on

Send_DT
      
      bcf PORTA,CS ; Enable Chip Select Output (low)
      CALL RUTINE
      movlw 0xF0
      movwf SSPBUF ; put in SSPBUF
      BANKSEL SSPSTAT ; BANK 1
Char1 btfss SSPSTAT,BF ; Data transfer complete? (Buffer Full?)
      goto Char1 ; if not, check again
       BANKSEL SSPBUF ; BANK0
      movf SSPBUF,W ; Get Data from SSPBUF
   ; ; Throw it away
   bsf PORTA,CS ; Disable Chip Select Output (high)
   Update_Test_Counter
   incf Ctr0,F ; Increment counter variable
   Delay movlw 0x01 ; Simple Delay loop
   movwf Dly1 ; |
   movlw 0x0F ; |
   movwf Dly0 ; |
   DlyLoop decfsz Dly0,F ; |
         goto DlyLoop ; |
         decfsz Dly1,F ; |
         goto DlyLoop ; |
   ; Done Delay ; \_/
DoAgain goto Send_DT ; Done, Send Next Byte.

RUTINE   
      return
;------------------------------------------------------------------------------
; PLACE USER PROGRAM HERE
;------------------------------------------------------------------------------

          GOTO $

          END

















ESCLAVO :


    LIST      p=16F88              ; list directive to define processor
     #INCLUDE <P16F88.INC>          ; processor specific variable definitions

;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file.  See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------

     __CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_IO
     __CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF

;------------------------------------------------------------------------------
;
; VARIABLE DEFINITIONS
;
; Available Data Memory divided into Bank 0 through Bank 3.  Each Bank contains
; Special Function Registers and General Purpose Registers at the locations
; below: 
;
;           SFR           GPR               SHARED GPR's
; Bank 0    0x00-0x1F     0x20-0x6F         0x70-0x7F   
; Bank 1    0x80-0x9F     0xA0-0xEF         0xF0-0xFF 
; Bank 2    0x100-0x10F   0x110-0x16F       0x170-0x17F
; Bank 3    0x180-0x18F   0x190-0x1EF       0x1F0-0x1FF
;
;------------------------------------------------------------------------------

    CBLOCK 0x20 ; Sample GPR variable registers allocated contiguously
        MYVAR1  ; User variable
        MYVAR2  ; User variable
        MYVAR3  ; User variable
    ENDC
#define CS 0x20             ; PORTA,5 (HW SS pin)

W_TEMP         EQU        0x7D  ; w register for context saving (ACCESS)
STATUS_TEMP    EQU        0x7E  ; status used for context saving (ACCESS)
PCLATH_TEMP    EQU        0x7F  ; variable used for context saving

;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 16F88 has 256 bytes of non-volatile EEPROM, starting at address 0x2100
;
;------------------------------------------------------------------------------

DATAEE    ORG  0x2100
    DE    "MCHP"  ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3

;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------

RESET     ORG     0x0000            ; processor reset vector
          PAGESEL START
          GOTO    START             ; go to beginning of program


; MAIN PROGRAM
;------------------------------------------------------------------------------

START   
   clrf   PORTB
   CLRF   PORTA
            ; Set up the SPI Support
   BANKSEL TRISA             ; BANK 1
   movlw CS                ; Chip Select pin
   movwf TRISA             ; is in input mode
   movlw 0x06                ; Turn Off A/D mode for at least the
   movwf ADCON1             ; Chip Select pin (all Digital mode)
   

         ; Set up output port
   BANKSEL TRISB             ; BANK 1
   movlw b'00110010'          ; Configure all PORTB pins
   movwf TRISB             ; to be in output mode
   BANKSEL   PORTA   
   CLRF    PORTA
   BANKSEL   TRISB
         ; Set up the SPI
   movlw 0x40                ; Mode 1,1 SPI with
   movwf SSPSTAT             ; middle of output time sampling
   BANKSEL SSPCON             ; BANK 0
   movlw 0x34                ; Mode 1,1 SPI Slave Mode, /SS Required
   movwf SSPCON             ; SSP is on

Chk4Dat
      btfss SSPSTAT,BF            ; Here is the test
      goto Chk4Dat             ; New data, do a transfer (below

Recibed
      BANKSEL SSPBUF    
      movf SSPBUF,W             ; put in SSPBUF into W
      BANKSEL PORTB             ; BANK 0
      movwf PORTB             ; Show the results on PORTB
      CALL  ENVIOSLAVE
      
DoAgain
   ; Optional customer code can go here

goto Chk4Dat             ; Receive Next Byte

ENVIOSLAVE
         MOVLW   0XFF
         MOVWF   MYVAR1
         ADDWF   0X01,MYVAR1
         MOVLW   MYVAR1
         MOVWF   SSPBUF
         RETURN



;------------------------------------------------------------------------------
; PLACE USER PROGRAM HERE
;------------------------------------------------------------------------------

          GOTO $

          END













Agradezco cualquier ayuda !! :)
Título: Re: SPI - Error de Proteus ? el esclavo no responde cuando uso dos micros. y simulo
Publicado por: PCCM en 19 de Octubre de 2013, 00:24:44
Me sucedió igual con otros microcontroladores, esclavo y maestro con SPI.
Lo probé en físico y me funcionó, pero en proteus fallaba.
Título: Re: SPI - Error de Proteus ? el esclavo no responde cuando uso dos micros. y simulo
Publicado por: Pinolillo16 en 19 de Octubre de 2013, 01:53:02
Si deberias revisarlo en fisico amigo, ya que el proteus requiere de algunos retardos extra para buen funcionamiento.

Saludos
Título: Re: SPI - Error de Proteus ? el esclavo no responde cuando uso dos micros. y simulo
Publicado por: BrunoF en 19 de Octubre de 2013, 13:09:42
Hola,

tal vez haya más problemas, pero veo uno en:
Código: ASM
  1. ENVIOSLAVE
  2.          MOVLW   0XFF
  3.          MOVWF   MYVAR1
  4.          ADDWF   0X01,MYVAR1
  5.          MOVLW   MYVAR1
  6.          MOVWF   SSPBUF
  7.          RETURN

Varias de estas instrucciones son erróneas (especialmente el ADDWF), pero lo importante es que estás cargando siempre el mísmo valor a enviar. El valor que estás cargando siempre en SSPBUF son los 8 bits de menor peso del valor constante con el que has declarado a MYVAR1, en este caso 0x20 (declarada en el CBLOCK).

Para enviar un dato incremental cambiante podrías hacer:
Código: ASM
  1. ENVIOSLAVE
  2.          INCF   MYVAR1,F
  3.          MOVF   MYVAR1,W
  4.          MOVWF   SSPBUF
  5.          RETURN

También veo en el esclavo que esperas a recibir el byte del maestro para cargar el dato a enviar mediante el SSPBUF, eso implica que la primera vez que el maestro escribe, el esclavo envía 0xFF (creo que es el valor por defecto cuando no hay nada para enviar) y recién en el segundo envío del maestro el esclavo envía en simultáneo el primer valor.

Fuera de eso, tal vez lo mejor sería que adjuntes todos los archivos del proyecto, incluída la simulación para poder analizarlo mejor.

Saludos.
Título: Re: SPI - Error de Proteus ? el esclavo no responde cuando uso dos micros. y simulo
Publicado por: nahueldiaz1992 en 19 de Octubre de 2013, 14:16:37
Hola,

tal vez haya más problemas, pero veo uno en:
Código: ASM
  1. ENVIOSLAVE
  2.          MOVLW   0XFF
  3.          MOVWF   MYVAR1
  4.          ADDWF   0X01,MYVAR1
  5.          MOVLW   MYVAR1
  6.          MOVWF   SSPBUF
  7.          RETURN

Varias de estas instrucciones son erróneas (especialmente el ADDWF), pero lo importante es que estás cargando siempre el mísmo valor a enviar. El valor que estás cargando siempre en SSPBUF son los 8 bits de menor peso del valor constante con el que has declarado a MYVAR1, en este caso 0x20 (declarada en el CBLOCK).

Para enviar un dato incremental cambiante podrías hacer:
Código: ASM
  1. ENVIOSLAVE
  2.          INCF   MYVAR1,F
  3.          MOVF   MYVAR1,W
  4.          MOVWF   SSPBUF
  5.          RETURN

También veo en el esclavo que esperas a recibir el byte del maestro para cargar el dato a enviar mediante el SSPBUF, eso implica que la primera vez que el maestro escribe, el esclavo envía 0xFF (creo que es el valor por defecto cuando no hay nada para enviar) y recién en el segundo envío del maestro el esclavo envía en simultáneo el primer valor.

Fuera de eso, tal vez lo mejor sería que adjuntes todos los archivos del proyecto, incluída la simulación para poder analizarlo mejor.

Saludos.


Aqui dejo los archivos hay que fijarse que estan ambos programas , esclavo-maestro y varios circuitos de pruebas por separados en las carpetas

Mega archivos SPI (https://mega.co.nz/#!0oZSEa4J!QN69Qw7HDEuVTbO1qkPwIVGSork81vEktIrSJ_v0HLc)

tambien tengan en cuenta que por ahora lo que queria era lograr una comunicacion osea envier y recibir datos , en este caso datos fijos asi simplificaba lo mas posible el programa , total luego armar una subrutina con lo que quiera hacer es otra historia  :-/  por ahora el tema seria enviar un 0XF0 Con el maestro y recibir un 0XFF  del esclavo .

Sino de ultima lo termino provando de forma fisica como me aconsejan uds :) igual les deje todo en el link a ver que opinan :P . y Gracias por la ayuda !! :)
Título: Re: SPI - Error de Proteus ? el esclavo no responde cuando uso dos micros. y simulo
Publicado por: nahueldiaz1992 en 21 de Octubre de 2013, 21:29:44
Como me recomendaron lo prove al circuito en fisico por lo cual tuve algunas respuestas inesperadas que en el simulador de proteus no ocurian ... les dejo a continuacion las imagenes del osciloscopio . , del circuito y el programa modificado a ver que opinan :) ;


Cosas a observar :

La señal de SCK es erronea

El circuito no esta completo , solo envio desde el maestro 0x0f y en el esclavo testeo que bit esta encendido y lo mando a los 4 leds que se ven en el circuito pero solo se enciende uno en la realidad por lo cual la data que llega al esclavo y este procesa es erronea , por deduccion .. uds me diran si es asi o no ...


(http://img163.imageshack.us/img163/2329/r5yx.png)

(http://img547.imageshack.us/img547/1715/yywu.jpg)

(http://img36.imageshack.us/img36/6501/sgj.JPG)

(http://img843.imageshack.us/img843/193/djcz.jpg)

(http://img35.imageshack.us/img35/503/kb6.JPG)




MAestro :

;******************************************************************************
;   This file is a basic code template for code generation                    *
;   on the  PIC16F88. This file contains the basic code building              *
;   blocks to build upon.                                                     *
;                                                                             *
;   Refer to the MPASM User's Guide for additional information on             *
;   features of the assembler.                                                *
;                                                                             *
;   Refer to the respective data sheet for additional                         *
;   information on the instruction set.                                       *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Filename:         xxx.asm                                                *
;    Date:                                                                    *
;    File Version:                                                            *
;                                                                             *
;    Author:                                                                  *
;    Company:                                                                 *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Files Required: P16F88.INC                                               *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Features of the 16F88:                                                   *
;                                                                             *
;    1 10-bit PWM                                                             *
;    8 MHz Internal Oscillator                                                *
;    ICD support                                                              *
;    256 bytes of EEPROM data memory                                          *
;    Capture/Compare Module                                                   *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Notes:                                                                   *
;                                                                             *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Revision History:                                                        *
;                                                                             *
;******************************************************************************

;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------

     LIST      p=16F88              ; list directive to define processor
     #INCLUDE <P16F88.INC>          ; processor specific variable definitions

;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file.  See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------

     __CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _INTRC_IO
     __CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF

;------------------------------------------------------------------------------
;
; VARIABLE DEFINITIONS
;
; Available Data Memory divided into Bank 0 through Bank 3.  Each Bank contains
; Special Function Registers and General Purpose Registers at the locations
; below: 
;
;           SFR           GPR               SHARED GPR's
; Bank 0    0x00-0x1F     0x20-0x6F         0x70-0x7F   
; Bank 1    0x80-0x9F     0xA0-0xEF         0xF0-0xFF 
; Bank 2    0x100-0x10F   0x110-0x16F       0x170-0x17F
; Bank 3    0x180-0x18F   0x190-0x1EF       0x1F0-0x1FF
;
;------------------------------------------------------------------------------

    CBLOCK 0x20 ; Sample GPR variable registers allocated contiguously
        MYVAR1  ; User variable
        MYVAR2  ; User variable
        MYVAR3  ; User variable
    ENDC

Ctr0 EQU 0x20 ; Counter variable - sent to SPI
Dly0 EQU 0x21 ; Delay Variable (low byte)
Dly1 EQU 0x22 ; Delay Variable (high byte)
#define CS 0x02 ; PORTA,2

W_TEMP         EQU        0x7D  ; w register for context saving (ACCESS)
STATUS_TEMP    EQU        0x7E  ; status used for context saving (ACCESS)
PCLATH_TEMP    EQU        0x7F  ; variable used for context saving

;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 16F88 has 256 bytes of non-volatile EEPROM, starting at address 0x2100
;
;------------------------------------------------------------------------------

DATAEE    ORG  0x2100
    DE    "MCHP"  ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3

;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------

RESET     ORG     0x0000            ; processor reset vector
          PAGESEL START
          GOTO    START             ; go to beginning of program

;------------------------------------------------------------------------------
; INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------

ISR       ORG     0x0004            ; interrupt vector location

;         Context saving for ISR
          MOVWF   W_TEMP            ; save off current W register contents
          MOVF    STATUS,W          ; move status register into W register
          MOVWF   STATUS_TEMP       ; save off contents of STATUS register
          MOVF    PCLATH,W          ; move pclath register into W register
          MOVWF   PCLATH_TEMP       ; save off contents of PCLATH register

;------------------------------------------------------------------------------
; USER INTERRUPT SERVICE ROUTINE GOES HERE
;------------------------------------------------------------------------------

;         Restore context before returning from interrupt
          MOVF    PCLATH_TEMP,W     ; retrieve copy of PCLATH register
          MOVWF   PCLATH            ; restore pre-isr PCLATH register contents
          MOVF    STATUS_TEMP,W     ; retrieve copy of STATUS register
          MOVWF   STATUS            ; restore pre-isr STATUS register contents
          SWAPF   W_TEMP,F
          SWAPF   W_TEMP,W          ; restore pre-isr W register contents
          RETFIE                    ; return from interrupt

;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------

START   ; Set up the SPI Support
      BANKSEL TRISA ; BANK 1
      movlw 0x00 ; Set PORTA as
      movwf TRISA ; all Outputs
      movlw 0x01 ; Turn off A/D
      movwf ADCON0 ; so PORTA can be used
; Set up the SPI Port
      BANKSEL TRISB ; BANK 1
      movlw 0x02 ; SCK is output (Master), SDI is input,   
      movwf TRISB ; SDO is output, all others output
      movlw 0x40 ; Mode 1,1 SPI, middle of output
      movwf SSPSTAT ; time sampling
      BANKSEL SSPCON ; BANK 0
      movlw 0x31 ; Mode 1,1 SPI Master Mode, 1/16 Tosc bit
time
      movwf SSPCON ; SSP is on

Send_DT
      
      bcf PORTA,CS ; Enable Chip Select Output (low)
      CALL RUTINE
      movlw 0x0F
      movwf SSPBUF ; put in SSPBUF
      BANKSEL SSPSTAT ; BANK 1
Char1 btfss SSPSTAT,BF ; Data transfer complete? (Buffer Full?)
      goto Char1 ; if not, check again
       BANKSEL SSPBUF ; BANK0
      movf SSPBUF,W ; Get Data from SSPBUF
   ; ; Throw it away
   bsf PORTA,CS ; Disable Chip Select Output (high)
   Update_Test_Counter
   incf Ctr0,F ; Increment counter variable
   Delay movlw 0x01 ; Simple Delay loop
   movwf Dly1 ; |
   movlw 0x0F ; |
   movwf Dly0 ; |
   DlyLoop decfsz Dly0,F ; |
         goto DlyLoop ; |
         decfsz Dly1,F ; |
         goto DlyLoop ; |
   ; Done Delay ; \_/
DoAgain goto Send_DT ; Done, Send Next Byte.

RUTINE   
      return
;------------------------------------------------------------------------------
; PLACE USER PROGRAM HERE
;------------------------------------------------------------------------------

          GOTO $

          END




Esclavo :


;******************************************************************************
;   This file is a basic code template for code generation                    *
;   on the  PIC16F88. This file contains the basic code building              *
;   blocks to build upon.                                                     *
;                                                                             *
;   Refer to the MPASM User's Guide for additional information on             *
;   features of the assembler.                                                *
;                                                                             *
;   Refer to the respective data sheet for additional                         *
;   information on the instruction set.                                       *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Filename:         xxx.asm                                                *
;    Date:                                                                    *
;    File Version:                                                            *
;                                                                             *
;    Author:                                                                  *
;    Company:                                                                 *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Files Required: P16F88.INC                                               *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Features of the 16F88:                                                   *
;                                                                             *
;    1 10-bit PWM                                                             *
;    8 MHz Internal Oscillator                                                *
;    ICD support                                                              *
;    256 bytes of EEPROM data memory                                          *
;    Capture/Compare Module                                                   *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Notes:                                                                   *
;                                                                             *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Revision History:                                                        *
;                                                                             *
;******************************************************************************

;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------

     LIST      p=16F88              ; list directive to define processor
     #INCLUDE <P16F88.INC>          ; processor specific variable definitions

;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file.  See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------

     __CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_IO
     __CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF

;------------------------------------------------------------------------------
;
; VARIABLE DEFINITIONS
;
; Available Data Memory divided into Bank 0 through Bank 3.  Each Bank contains
; Special Function Registers and General Purpose Registers at the locations
; below: 
;
;           SFR           GPR               SHARED GPR's
; Bank 0    0x00-0x1F     0x20-0x6F         0x70-0x7F   
; Bank 1    0x80-0x9F     0xA0-0xEF         0xF0-0xFF 
; Bank 2    0x100-0x10F   0x110-0x16F       0x170-0x17F
; Bank 3    0x180-0x18F   0x190-0x1EF       0x1F0-0x1FF
;
;------------------------------------------------------------------------------

    CBLOCK 0x20 ; Sample GPR variable registers allocated contiguously
        MYVAR1  ; User variable
        MYVAR2  ; User variable
        MYVAR3  ; User variable
    ENDC
#define CS 0x20             ; PORTA,5 (HW SS pin)

W_TEMP         EQU        0x7D  ; w register for context saving (ACCESS)
STATUS_TEMP    EQU        0x7E  ; status used for context saving (ACCESS)
PCLATH_TEMP    EQU        0x7F  ; variable used for context saving

;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 16F88 has 256 bytes of non-volatile EEPROM, starting at address 0x2100
;
;------------------------------------------------------------------------------

DATAEE    ORG  0x2100
    DE    "MCHP"  ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3

;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------

RESET     ORG     0x0000            ; processor reset vector
          PAGESEL START
          GOTO    START             ; go to beginning of program


; MAIN PROGRAM
;------------------------------------------------------------------------------

START   
   clrf   PORTB
   CLRF   PORTA
            ; Set up the SPI Support
   BANKSEL TRISA             ; BANK 1
   movlw CS                ; Chip Select pin
   movwf TRISA             ; is in input mode
   movlw 0x06                ; Turn Off A/D mode for at least the
   movwf ADCON1             ; Chip Select pin (all Digital mode)
   

         ; Set up output port
   BANKSEL TRISB             ; BANK 1
   movlw b'00110010'          ; Configure all PORTB pins
   movwf TRISB             ; to be in output mode
   BANKSEL   PORTA   
   CLRF    PORTA
   BANKSEL   TRISB
         ; Set up the SPI
   movlw 0x40                ; Mode 1,1 SPI with
   movwf SSPSTAT             ; middle of output time sampling
   BANKSEL SSPCON             ; BANK 0
   movlw 0x34                ; Mode 1,1 SPI Slave Mode, /SS Required
   movwf SSPCON             ; SSP is on

Chk4Dat
      btfss SSPSTAT,BF            ; Here is the test
      goto Chk4Dat             ; New data, do a transfer (below

Recibed
      BANKSEL SSPBUF    
      movf SSPBUF,W
      MOVWF MYVAR2            ; put in SSPBUF into W
      CALL  UNOS
      CALL   DOS
      CALL   TRES
      CALL   CUATRO
      BANKSEL PORTB             ; BANK 0
      movwf PORTB             ; Show the results on PORTB
      CALL  ENVIOSLAVE
      
DoAgain
   ; Optional customer code can go here

goto Chk4Dat             ; Receive Next Byte

UNOS   BTFSS   MYVAR2,0
      BCF      PORTA,1
      BSF      PORTA,1
      RETURN
DOS      BTFSS   MYVAR2,1
      BCF      PORTB,5
      BSF      PORTB,5
      RETURN
TRES   BTFSS   MYVAR2,2
      BCF      PORTB,6
      BSF      PORTB,6
      RETURN
CUATRO   BTFSS   MYVAR,3
      BCF      PORTB,7
      BSF      PORTB,7
      RETURN

ENVIOSLAVE
         MOVLW   0XFF
         MOVWF   MYVAR1
         MOVLW   MYVAR1
         MOVWF   SSPBUF
         RETURN



;------------------------------------------------------------------------------
; PLACE USER PROGRAM HERE
;------------------------------------------------------------------------------

          GOTO $

          END




 Desde ya gracias por la ayuda gente !! :)