Addressing multiple PORTs using one Variable


+ Reply to Thread
Results 1 to 32 of 32

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Addressing multiple PORTs using one Variable

    Quote Originally Posted by richard View Post
    have you tried to light a rgb led strip with a 690 @20mHz yet ?
    i have doubts that such a slow chip will do the deed
    That's why I proposed APA102 chips. Not strict on the clock frequency.

    Ioannis
    Last edited by Ioannis; - 25th July 2024 at 22:21.

  2. #2
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Addressing multiple PORTs using one Variable

    have you tried to light a rgb led strip with a 690 @20mHz yet ?

    Check this:
    Roger

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Addressing multiple PORTs using one Variable

    And here's the project's code for now.
    Attached Files Attached Files
    Roger

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Addressing multiple PORTs using one Variable

    Have not checked al of your code, but in the ***_B routine you include many time the same code. Why not insert it one time and then use GoSub to it? Better efficiency and memory usage.

    Also I see you insist on using this difficult protocol. Consider the APA101 as it is less strict and can be used on slow MCUs

    Ioannis

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Addressing multiple PORTs using one Variable

    I tried to not repeat the code and use GOTOs or GOSUBS but then, if I do so, the NeoPixel string won't work anymore.

    Would the use of an alternative LED string as you mention sove the problem of the ports/code/timing?

    I can change for another system but would you have a code snippet to help me started with APA102 please? I've never heard about this one before.h
    Last edited by Ioannis; - 25th July 2024 at 22:21.
    Roger

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: Addressing multiple PORTs using one Variable

    Here is a copy of the Richards example.

    Code:
    '***************************************************************************
    '*  Name    : ap102.pbp                                                    *
    '*  Author  : richard                                                      *
    '*  Notice  :                                                              *
    '*          :                                                              *
    '*  Date    : 10/11/2017                                                   *
    '*  Version : 1.0                                                          *
    '*  Notes   :  only tested on pic18 @64 MHZ                                *
    '*          : pic18f26k22
    '***************************************************************************
    
    #CONFIG
      CONFIG  FOSC = INTIO67
      CONFIG  PLLCFG = ON
      CONFIG  PRICLKEN = OFF
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRTEN = OFF
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 190
      CONFIG  WDTEN = ON
      CONFIG  WDTPS = 32768
      CONFIG  CCP2MX = PORTC1
      CONFIG  PBADEN = OFF
      CONFIG  CCP3MX = PORTB5
      CONFIG  HFOFST = ON
      CONFIG  T3CMX = PORTC0
      CONFIG  P2BMX = PORTB5
      CONFIG  MCLRE = EXTMCLR
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG
    
     led_num  con 3  
     pixels  var byte[led_num * 3]
     pallet   var byte[21]
     apa_global VAR byte bank0       ;global level 0-31
     bit_cnt    VAR byte bank0 
     i VAR byte
     k VAR byte
     j VAR byte
    goto overpix
    asm 
    _showpix 
           movlw    LOW _pixels 
           movwf     FSR2L
           movlw   high _pixels
           movwf   FSR2H 
           movlw 4 
           movwf  _bit_cnt
           movlw 0 
    s_frame              ;start frame  4x 00 bytes
           bcf    PIR1,SSPIF
           movwf  SSPBUF
    stspi  BTFSs    PIR1,SSPIF       
           bra stspi 
           decf   _bit_cnt
           bnz   s_frame
           movlw _led_num 
           movwf  _bit_cnt
    n_led       
           movlw 0xe0
           iorwf _apa_global,W
           bcf    PIR1,SSPIF
           movwf  SSPBUF   ;global led frame
    glspi  BTFSs    PIR1,SSPIF       
           bra glspi        
           movf    POSTINC2 ,W   ;blue
           bcf    PIR1,SSPIF
           movwf  SSPBUF
    blspi  BTFSs    PIR1,SSPIF       
           bra blspi       
           movf    POSTINC2 ,W   ;green
           bcf    PIR1,SSPIF
           movwf  SSPBUF
    gnspi  BTFSs    PIR1,SSPIF       
           bra gnspi
           movf    POSTINC2 ,W    ;red
           bcf    PIR1,SSPIF
           movwf  SSPBUF
    rdspi  BTFSs    PIR1,SSPIF       
           bra rdspi
           decf   _bit_cnt
           bnz   n_led 
           movlw   _led_num /8 +1  ;find magic number  of bytes for stop frame
           movwf  _bit_cnt
           movlw 0  
    stop_frame                 ;send stop frame
           bcf    PIR1,SSPIF
           movwf  SSPBUF
    stopspi  BTFSs    PIR1,SSPIF       
           bra stopspi 
           decf   _bit_cnt       
           bnz   stop_frame
           return 
    endasm        
    overpix: 
      
        define OSC 64
        OSCCON = %11110000            
        ANSELb = 0
        ANSELA = 0
        ANSELC = 0
        SSPCON1=$20;
        SSPSTAT=$40;
        trisc=%11010111
        apa_global=1  
        latb.0=1  
        trisb=%11111110
        arraywrite pallet,[255,0,0 ,0,255,0 ,0,0,255, 255,255,0 ,255,0,255 ,0,255,255, 255,255,255]
        k=0      ;colour index
        j=0
        gosub shuffle 
        
    aloop: 
        call  showpix
        gosub shuffle
        pause  40
    goto aloop
    And a YouTube video here



    Ioannis

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,643


    Did you find this post helpful? Yes | No

    Default Re: Addressing multiple PORTs using one Variable

    the youtube link is a dud, but i take it that it works even though the timing is a little out of specs

    Name:  Untitled.jpg
Views: 52904
Size:  57.2 KB
    Warning I'm not a teacher

Similar Threads

  1. Addressing ports via offset using lookup command
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 1st November 2013, 03:50
  2. How to drive 7 segment using multiple ports?
    By guess79 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 19:43
  3. multiple ports ===> one symbol?
    By PICMAN in forum General
    Replies: 4
    Last Post: - 8th March 2005, 22:24
  4. Problem reading multiple ADC ports
    By jswayze in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 4th November 2004, 16:46
  5. Reading multiple ports
    By Rob Martin in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th May 2004, 17:22

Members who have read this thread : 17

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts