USB Hello World CDC_DEMO with DT_INTS
                        
		
	
	
                
		
			
			       
                        
                               by 
                        
                         
                        
                        
                        
				
					
						
							Published on - 22nd January 2012  17:43
						
					
					
					
						 Number of Views: 5959
						 
					
				
			
                       
		 
	 
    
    
	Here is some PBP 2.60 code (cut and pasted) from Darrel, with the "Hello World" example added in. Darrel's main code is taken from another thread, located here: 
http://www.picbasic.co.uk/forum/show...4292#post94292 . It uses DT_INTS ( instant interrupts ) to service the USB. As always, DT_INTS can then also be used for all types of other things, while the USB connection is kept alive.
 
	Code:
	'  Compilation of this program requires that specific support files be
'  available in the source directory.  For detailed information, see
'  the file PBP\USB18\USB.TXT.
'  Config files for PIC18F4550 with 20 mhz crystal
asm
        __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
        __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
        __CONFIG    _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_3_2L & _VREGEN_ON_2L
        __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
        __CONFIG    _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
        __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L
endasm
DEFINE OSC 48
INCLUDE "cdc_desc.bas" 'Descriptor file    for CDC    serial demo
;--- Setup Interrupts ------------------------------------------------------
INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas"  ; Include if using PBP interrupts
buffer    Var    Byte[16]
cnt    Var    Byte
ASM
INT_LIST  macro     ; IntSource,          Label,  Type, ResetFlag?
        INT_Handler     USB_INT,  _DoUSBSERVICE,   ASM,  yes
        INT_Handler     INT_INT,    _Handle_INT,   PBP,  yes
    endm
    INT_CREATE             ; Creates the Low Priority interrupt processor
    ;INT_ENABLE  USB_INT   ;we will do this after we initialize USB
    INT_ENABLE  INT_INT
ENDASM
;----[Initialise USB and Interrupts]----------------------------------------
    PAUSE 100                    ; Allow VUSB to stabilize
    USBINIT                      ; initialize the USB driver
    USBSERVICE                   ; service it once
    UIE = $7F                    ; enable USB interrupts
    UEIE = $9F                   ; enable USB Error interrupts
@   INT_ENABLE  USB_INT
;----[Main program loop]----------------------------------------------------
Main:
    cnt = 16        ' Specify input buffer size
    USBIn 3, buffer, cnt, main
' Message received
    buffer[0] = "H"
    buffer[1] = "e"
    buffer[2] = "l"
    buffer[3] = "l"
    buffer[4] = "o"
    buffer[5] = " "
    buffer[6] = "W"
    buffer[7] = "o"
    buffer[8] = "r"
    buffer[9] = "l"
    buffer[10] = "d"
    buffer[11] = 13
    buffer[12] = 10
    buffer[13] = 0
outloop:
    USBOut 3, buffer, 14, outloop
GOTO Main
;----[Interrupt handler -- Service USB]-------------------------------------
DoUSBSERVICE:
      USBSERVICE                   ; Run the SERVICE routines
@ INT_RETURN
;----[Interrupt handler -- INT]
Handle_INT:
 ; something here
@ INT_RETURN
 
		
	
	
    
	
 
Re: 16F690 MCLR as Input
many thanks Henrik to clarify this post.
jackberg1 - 27th October 2025, 20:42that make more sense to me now with further test, when the pin RA3
has nothing connected to it, the input is floating thus
when adding a pulldown it's...