Multi-Button CSM with Pic16LF722A


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    Hi Richard,

    Would you please explain in a little more detail as to how the "GetAddress" section of code works?

    Cheers
    Barry
    VK2XBP

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    the get address macro is part of dt-ints . it places the address of a label in a pbp word var.
    this is the actual macro , its already there so why not use it.
    Code:
    ASM
    ;---[Returns the Address of a Label as a Word]------------------------------
    GetAddress macro Label, Wout
        CHK?RP Wout
        movlw low Label          ; get low byte
        movwf Wout
    ;    movlw High Label         ; get high byte  MPLAB 8.53 killed high
        movlw Label >> 8         ; get high byte
        movwf Wout + 1
      endm
    endasm

    so

    @ GetAddress _my_pwm,_paddress

    gets the address of my_pwm: and places it in var paddress


    the data
    my_pwm:
    @ DW 3,6,13,26,50,95,177,328,600,1023 [data stored as an array of 14 bit values]

    each flash memory address can hold a maximum 14 bit piece of data

    i'm using that address plus an offset to index the array

    readcode paddress+pl ,pw ; address + offset
    [note pw is a word var]
    so if pl= 3
    readcode paddress+3, and returns the value 26

    hope that's understandable

    ps I might add that in my setup that saves 44 words of code space compared to using lookup2
    Last edited by richard; - 23rd May 2016 at 12:55. Reason: ps
    Warning I'm not a teacher

  3. #3
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    Hi Richard,

    Thank you for your very clear and concise explanation.

    When you store the data, what does "DW" refer to?
    In the example you use "@ DW" however in previous code snippets you use "@ dW"
    Can you clarify please?

    Cheers
    Barry

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    In the example you use "@ DW" however in previous code snippets you use "@ dW"
    Any line beginning with @ is a statement for the assembler to process [just a shorthand way of ASM--DO STUFF ---ENDASM]
    the assembler is usually case sensitive CARE NEEDS TO TAKEN
    but for Data Directives like da db dw etc it seems to have no problem with the case . I only fix typing if I have to , mpasm doesn't care about the case here so nether do i
    dW == DW == Dw == [ dw – DECLARE DATA OF ONE WORD]

    for more info google mpasm assembler directives
    or
    http://ww1.microchip.com/downloads/e...Doc/33014L.pdf
    Warning I'm not a teacher

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    in this example I use indirect addressing to retrieve the data ,but due to the 12f1822 architecture only the low 8 bits are retrievable .wastes a bit of space but its heaps quicker

    Code:
    '****************************************************************
    '*  Name    : ws2812.BAS                                                                              *
    '*  Author  : richard                                                                                       *
    '*  Notice  :                                                                                                   *
    '*          :                                                                                                     *
    '*  Date    : 1/11/2016                                                                                  *
    '*  Version : 1.0                                                                                            *
    '*  Notes   : pic12f1822  @32 mhz 3v3                                                           *
    '*          : porta.5 >>>> ws2821 Din                                                             *
    '****************************************************************
     #CONFIG
    cfg1 = _FOSC_INTOSC
    cfg1&= _WDTE_ON
    cfg1&= _PWRTE_OFF
    cfg1&= _MCLRE_ON
    cfg1&= _CP_OFF
    cfg1&= _CPD_OFF
    cfg1&= _BOREN_ON
    cfg1&= _CLKOUTEN_OFF
    cfg1&= _IESO_ON
    cfg1&= _FCMEN_ON
      __CONFIG _CONFIG1, cfg1
    
    cfg2 = _WRT_OFF
    cfg2&= _PLLEN_ON
    cfg2&= _STVREN_ON
    cfg2&= _BORV_19
    cfg2&= _LVP_OFF
      __CONFIG _CONFIG2, cfg2
    
    #ENDCONFIG
    
     bt VAR byte  bank0
     px VAR byte  bank0
     pc var byte bank0   ; number of rgb led to write x3
    
     pixels  var byte[3]    ;  rgb led  x3
     DURATION  var byte
     
     palette var word    ;address of pallet
     TEMP VAR WORD
     OFFSET VAR WORD     ;pallet index
    
    
     
     
       
     goto overpalette   ; green,red,blue data   
     my_palette:     ;  note !!!  inde read can only access the low byte of each  stored  word
     @ dw 100,120,0  ;
     @ dW 0,100,0  ; RED
     @ dW 0,80,0  ;
     @ dW 0,60,0  ;
     @ dW 0,20,0  ;
     @ dW 200,200,0  ;OR
     @ dW 160,160,0  ;
     @ dW 100,100,0  ;
     @ dW 80,80,0  ;
     @ dW 2,5,0  ; 
     @ dW 200,150,0  ;YEL
     @ dW 160,120,0  ;
     @ dW 100,75,0  ;
     @ dW 80,60,0  ;
     @ dW 40,30,0  ; 
     @ dW 150,200,0  ; ?
     @ dW 120,160,0  ;
     @ dW 75,100,0  ;
     @ dW 60,80,0  ;
     @ dW 30,40,0  ; 
     @ dW 120,100,0  ;
     @ dW 160,160,160  ; WH
     @ dW 100,100,100  ;
     @ dW 80,80,80  ;
     @ dW 30,30,30  ;
    ASM  
     
    
    ;---[Returns the Address of a Label as a Word]------------------------------
    GetAddress macro Label, Wout
        CHK?RP Wout
        movlw low Label          ; get low byte
        movwf Wout
        movlw Label >> 8         ; get high byte
        movwf Wout + 1
      endm     
    endasm
    overpalette :  
     
     goto overasm
       asm
    _pram                     ;entry point to read from sram
            movlw   low _pixels
            movwf   FSR0L
            movlw   high _pixels
            movwf   FSR0H 
            goto _nxby
    _prom                     ;entry point to read from flash 
            CHK?RP _OFFSET
            MOVE?WW   _OFFSET , FSR0
            BSF FSR0H ,7
    _nxby   MOVIW  FSR0 ++
            movwf _px
            MOVLW 8
            movwf _bt
            RLF _px,F
    _nxbt   BSF LATA ,5
            BTFSS STATUS,C
            GOTO XX
            NOP
            NOP
            NOP
    XX      BCF  LATA ,5
            NOP
            RLF _px,F
            DECFSZ _bt,F
            GOTO _nxbt 
            DECFSZ _pc,F
            GOTO _nxby
            RETURN 
       
    endasm
    
    overasm:
    
    
    
     CLEAR
     define OSC 32
     osccon=$f0
     trisa=%011110
     @ GetAddress _my_palette,_palette  ;set pallet address
     
     
    loopy: 
     GOSUB FLICKER
     PC=3    ; value is  number of rgb leds X 3 
     call prom
     pause DURATION
     goto loopy
     
     
     
     
    FLICKER:
     RANDOM TEMP
     DURATION=TEMP&$7F
     RANDOM TEMP
    ' temp=0
     OFFSET =(TEMP //25)*3 + palette
    RETURN
    Warning I'm not a teacher

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    you can toggle on/off like this

    IF KP = 0 THEN '1/0 BUTTON PRESSED
    ;use p_level to see what state machine is in 0=off ,non zero = on
    if p_level then
    ccp1con=0 ;must be on kill it
    led=0
    p_level= 0
    else ;must be off power to max
    p_level= 5
    endif

    stoping it repeating too quickly is a bit trickier
    a pause that's long enough to allow reaction time would do , its a bit klunky.
    the best way is to wait for the key to be released before acting (or repeating the action)
    maybe counting three passes through main loop with flg=0 after an I/O key press would indicate key is released
    and its safe to re-enable the key
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    since the isr TB1 is an accurate timebase you can
    make a new var
    Code:
     kio_inhibit var byte
    modify the I/o key routine
    Code:
    IF KP = 0 THEN '1/0 BUTTON PRESSED
            ;use  p_level to see what state machine is in  0=off ,non zero = on
            if kio_inhibit==0 then
               kio_inhibit=152    ;152*32mS = about 5 seconds
            if  p_level then     
                ccp1con=0 ;must be on kill it
                led=0
                p_level= 0
            else         ;must be off  power to max
                p_level= 5
            endif
           endif
    and add this to the isr

    Code:
    if kio_inhibit then
        kio_inhibit =  kio_inhibit -1
        endif
    now the I/O key is inhibited for 5 sec after being acted on

    I like ART's quote and its so true
    PBP is very well documented, however you’ll notice all examples of command use are also examples of exactly how not to write a cyclic program.
    you need to adjust your way of thinking to loops , states and flags . it opens up a whole new vista
    Last edited by richard; - 25th May 2016 at 08:26.
    Warning I'm not a teacher

Similar Threads

  1. Replies: 5
    Last Post: - 18th March 2012, 21:40
  2. multi functions button press
    By malwww in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th May 2009, 00:12
  3. Multi-Threading
    By Ted's in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 2nd September 2008, 05:55
  4. Multi-tasking
    By malc-c in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 13th July 2006, 18:50
  5. Multi Interrupt How To ?
    By capitano in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd February 2005, 14:48

Members who have read this thread : 4

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