Go Down

Topic: SW2803 and PIC18F4525 asm code (Read 351 times) previous topic - next topic



I'm sorry, this question is not about arduino, but I know this forum has a lot of knowledge of the SW2803 LED controller and other microprocessors also. I haven't found much information about the SW2803 elsewhere.

I'm trying to get these two devices to communicate, without any success yet. I'm pretty sure that all wirings are right. Common anode LEDs, anodes to +5V and cathodes to WS2803 channel pins. 1k5 resistor fom ground to IREF pin. I'm using asm code to program the PIC. Can anyone who is familiar with these devices, tell me is there something wrong in my code or should it work? I'm using a 10MHz crystal, PLL enabled and the PIC is operating at 40MHz. I have two versions of the code, SPI and bit bang.

Code: [Select]
         ; SPI SETUP
          movlw   b'01000000'   ; Input data sampled at end of data output time, CKE=1, SMP=0
          movwf   SSPSTAT
          movlw   b'00100000'   ; Enable serial port, SPI mastermode, SPI speed FOSC/4=10MHz, CKP Clock Polarity Select bit=0
          movwf   SSPCON1
          bcf     SSPCON1,5    ; Serial port off. PORTC,3 is set as digital output.
          bsf     PORTC,CKI    ; Single pulse
          bcf     PORTC,CKI 
          ; delay 600us Preparing cycle
          movlw    0xAF
          movwf    delayreg1
          movlw    0x05
          movwf    delayreg2
          decfsz   delayreg1,f
          goto     $+2
          decfsz   delayreg2,f
          goto     Delay_0
          bsf     SSPCON1,5   ; Serial port on
          ; SPI data send
          movlw   0x12        ; 18 to counter, counts 18 bytes
          movwf   bytecounter
          movlw   0xFF     
          movwf   SSPBUF            ; place data in send buffer
          btfss   SSPSTAT,BF        ; has data been received?
          goto    SPIloop           ; loop if not received yet
          movff   SSPBUF,rxdata     ; empty the receive buffer
          decfsz  bytecounter,f     ; All 18 bytes sent?
          goto    Send_again        ; Not yet, send more
          goto    MAIN

Bit bang version:

Code: [Select]
         bcf  PORTA,DAI
         bsf  PORTA,CKI        ; Short pulse CKI
         bcf  PORTA,CKI   
; Delay 600us, preparing cycle
         movlw   0xAF
         movwf   delayreg1
         movlw   0x05
         movwf   delayreg2
         decfsz  delayreg1,f
         goto    $+2
         decfsz  delayreg2,f
         goto    Delay_loop
;Send 144 times 1 to DAI pin (=0xFF to all 18 channels)
         movlw   0x90            ; 144 to counter
         movwf   TEMP
         bsf     PORTA,DAI       ; Set data bit
         bsf     PORTA,CKI       ; Clock pulse rising edge
         bcf     PORTA,CKI       ; Cloc pulse falling edge
         bcf     PORTA,DAI       ; Clear data bit
         bsf     PORTA,DAI       ; Set data bit again
         decfsz  TEMP            ; 144 clock pulses sent?
         goto    Send_again      ; not yet, send more
         bcf     PORTA,DAI       ; all sent
         goto    MAIN

Go Up