DT USB Flags


Closed Thread
Results 1 to 5 of 5

Thread: DT USB Flags

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588

    Default DT USB Flags

    How do these flags in DT_HID260.pbp:
    Code:
    USB_Flags          VAR BYTE BANK0
    
    Plugged            VAR USB_Flags.0 
    RX_Rcvd            VAR USB_Flags.1
    RX_READY           VAR USB_Flags.2
    TX_READY           VAR USB_Flags.3
    RX_ERROR           VAR USB_Flags.4
    TX_ERROR           VAR USB_Flags.5
    "Connect" with these pins in our programs:
    Code:
    DEFINE USB_PLUGGED     PORTD,1      ; LED indicates if USB is connected
    DEFINE USB_RXrcv       PORTD,2      ;  "      "     data received from PC
    DEFINE USB_RXrdy       PORTD,3      ;  "      "     data being received from PC
    DEFINE USB_TXrdy       PORTD,4      ;  "      "     data being sent to PC
    DEFINE USB_RXerr       PORTD,5      ;  "      "     data error from PC
    DEFINE USB_TXerr       PORTD,6      ;  "      "     data error to PC
    I looked at the datasheet and can't figure out how Port D links up with Bank 0. I'm also puzzled by the syntax PORTD,2.

    Robert

  2. #2
    Join Date
    Sep 2009
    Posts
    737

    Default Re: DT USB Flags

    That is ASM syntax.
    DEFINE's are just passed to LST file, after compile.
    There is no direct connection between that two pice of code.
    LED's are turned on/off with macro's in DT_HID260.pbp
    MACROs for LED:
    Code:
    ASM
        ifndef  USB_LEDPOLARITY          ; If LED polarity wasn't specified?
    USB_LEDPOLARITY = 1                  ;   default to ON when HIGH
        endif
        
    ;-------------------------------     
    LEDOFF  macro Port, Bit              ; -- Turn LED OFF --
        if (USB_LEDPOLARITY == 1)        ;   If LED is ON when HIGH?
            LOW?T  Port, Bit             ;     make it LOW
        else                             ;   otherwise
            HIGH?T Port, Bit             ;     make it HIGH
        endif
      endm
    
    ;-------------------------------  
    LEDON  macro Port,Bit                ; -- Turn LED ON --
        if (USB_LEDPOLARITY == 1)        ;   If LED is ON when HIGH?
            HIGH?T Port, Bit             ;     make it HIGH
        else                             ;   otherwise
            LOW?T  Port, Bit             ;     make it LOW
        endif
      endm
    
    ;-------------------------------  
    ifLEDisON  macro Port,Bit, Label
        if (USB_LEDPOLARITY == 1)        ; if LED is ON when HIGH
            btfsc   Port, Bit            ;   and the pin is LOW
        else                             ; or if LED is ON when LOW
            btfss   Port, Bit            ;   and the pin is HIGH
        endif                            ; then the LED is OFF
        goto      Label                  ;    so don't jump to the label
      endm                                       
    ;-------------------------------  
    ifLEDisOFF  macro Port,Bit, Label
        if (USB_LEDPOLARITY == 1)        ; if LED is ON when HIGH
            btfss   Port, Bit            ;   and the pin is HIGH
        else                             ; or if LED is ON when LOW
            btfsc   Port, Bit            ;   and the pin is LOW
        endif                            ; then the LED is ON
        goto      Label                  ;    so don't jump to the label
      endm  
    ENDASM
    As you can see from macros, Darrel used HIGH and LOW commands from PBP to handle BANK, TRIS, and output register of port.

    To turn TX LED:
    Code:
    ;----[Send USB data]--------------------------------------------------------
    DoUSBOut:
        ASM
            ifdef    USB_TXLED
                LEDON  USB_TXLED
            endif  
        ENDASM
    ....
    He call LED macro from DoUSBOut subrutine...

    Code:
    DoUSBService:
        INTS_FROM = INTS_FROM | UIR
    ASM
       ifdef USB_ServiceLED
         LEDON  USB_ServiceLED
       endif
    ENDASM
    etc...
    Last edited by pedja089; - 7th April 2015 at 18:16.

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588

    Default Re: DT USB Flags

    Argh, I had looked for FLAG in the include.

    And I just noticed I can't rename those as I wish either, ooops.

    Robert

  4. #4
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229

    Default Re: DT USB Flags

    "DEFINEs in PBP are converted literally to Assembly Language #DEFINE directives." from the PBP manual.

    The "DEFINE USB_RXrcv POTRD,2" in PBP is converted to "#DEFINE USB_RXrcv PORTD,2"
    An Assembly "#Define" in this case is just a text substitution.
    In the Assembly code, wherever "USB_RXrcv" is, it is substituted (replaced) with "PORTD,2"
    Regards,
    TABSoft

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588

    Default Re: DT USB Flags

    Thank you, that's what I thought from Pedja's post.

    Robert

Similar Threads

  1. USB to USB flash Drive File Copier
    By surya089 in forum USB
    Replies: 2
    Last Post: - 16th December 2012, 02:22
  2. USB to USB flash Drive File Copier
    By emildownloads in forum General
    Replies: 222
    Last Post: - 27th October 2011, 02:23
  3. LCD issue - what does FLAGS = 0 really do?
    By BrianT in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th February 2008, 06:26
  4. set flags within a variable?
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 24th October 2006, 12:07
  5. trouble with FLAGs
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 10th November 2004, 03:26

Members who have read this thread : 2

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