ASM cycles in PICBASIC


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Here's one version using a modified PBP library routine & macro;
    Code:
    Result VAR BYTE BANK0 SYSTEM
    I      VAR BYTE BANK0 SYSTEM
    Temp   VAR BYTE BANK0 SYSTEM
    X      VAR BYTE
    
        TRISB.4 = 1
        Result = 0
        
    Main:
        for I = 0 to 7       ' loop x 8
          X = 0
          while X < 10       ' Test pin x 10
            if PORTB.4 = 1 then
             call BitSet     ; Result.0[I] = 1
            else            
             call BitClear   ; Result.0[I] = 0
            endif
            X = X + 1 
          wend
        next I
    
    Done:
        goto   Done
    	
    BitClear:
    ASM
        call   ConvertBit  ; Bitmask -> W
        movwf  Temp        ; W -> Temp
        comf   Temp,F      ; Invert Temp
        movf   Temp,W      ; Temp -> W
        andwf  Result,F    ; AND W with Result
        return
    ENDASM
    
    BitSet:
    ASM
        call   ConvertBit  ; Bitmask -> W
        iorwf  Result,F    ; OR W with Result
        return
        
    ;******************************************************
    ;* Input      : I = bit (0 - 7)                       *
    ;* Output     : W = bit mask                          *
    ;* Notes      : Modified example from PBP library     *
    ;******************************************************
    ConvertBit              ; See pbppic14.lib CONVBIT & TABLE?C macro
        movlw   btable >> 8 ; Get high address of jump table
        movwf   PCLATH      ; Set program counter latch high
        movf    I,W         ; Get bit number from I into W reg
        andlw   07h         ; Isolate lower 3 bits (only works with 0-7)
        TABLE?C 08h         ; PBP library macro for table alignment
    btable                  ; Returns from table with bit mask in W reg
        retlw   01h         ; %00000001
        retlw   02h         ; %00000010
        retlw   04h         ; %00000100
        retlw   08h         ; %00001000
        retlw   10h         ; %00010000
        retlw   20h         ; %00100000
        retlw   40h         ; %01000000
        retlw   80h         ; %10000000
    ENDASM
    
        END
    You can learn a good deal about assembly language by reading through the
    PBP library.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    breeno,

    In the original example (basic version), the while loops 10 times, reading the pin and overwriting the same bit in the CODE variable. It's no different than just reading it once (other than time used).

    So, with that in mind, here's another possibility...
    Code:
    ASM
       MOVE?CB  8, _i
    IN_Loop
       MOVE?TT  _in, STATUS, C
       CHK?RP   _CODE
       rrf      _CODE, F
       CHK?RP   _i
       decfsz   _i, F
       goto     IN_Loop
    ENDASM
    It just reads the pin, put's the value in the Carry flag, then rotates it into the CODE variable (8 times).
    DT

Similar Threads

  1. Problem using ASM instruction
    By ewandeur in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd April 2008, 15:26
  2. asm e picbasic
    By chip15 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 5th April 2006, 16:03
  3. Replies: 22
    Last Post: - 12th July 2005, 17:39
  4. Can an asm interrupt contain gosub to a picbasic routine?
    By sougata in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st April 2005, 19:49
  5. asm to picbasic
    By wilfried in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 12th March 2003, 01:18

Members who have read this thread : 0

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