PDA

View Full Version : DT USB Flags



Demon
- 7th April 2015, 16:59
How do these flags in DT_HID260.pbp:

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:

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

pedja089
- 7th April 2015, 17:08
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:

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:

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


DoUSBService:
INTS_FROM = INTS_FROM | UIR
ASM
ifdef USB_ServiceLED
LEDON USB_ServiceLED
endif
ENDASM
etc...

Demon
- 7th April 2015, 17:35
Argh, I had looked for FLAG in the include.

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

Robert

Tabsoft
- 7th April 2015, 17:40
"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"

Demon
- 7th April 2015, 19:22
Thank you, that's what I thought from Pedja's post.

Robert