hserin work 100% but if i use usbin code not work
Code:
INCLUDE "modedefs.bas"
asm
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
; ; ; USB clock source comes from the 96 MHz PLL divided by 2
; ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
; No prescale (4 MHz oscillator input drives PLL directly)
__CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
; ; ; Oscillator Switchover mode disabled
; ; Fail-Safe Clock Monitor disabled
; XT oscillator, PLL enabled, XT used by USB
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
__CONFIG _CONFIG5L, _CP0_ON_5L & _CP1_ON_5L & _CP2_ON_5L & _CP3_ON_5L
__CONFIG _CONFIG5H, _CPB_ON_5H
endasm
DEFINE OSC 48
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 9600
DEFINE HSER_CLROERR 1
Led Var PORTA.0
Recebe VAR PIR1.5 ' Receive interrupt flag (1=full , 0=empty)
Transmite VAR PIR1.4 ' Transmit interrupt flag (1=empty, 0=full)
Buffer VAR BYTE[16]
Cnt VAR BYTE
A VAR BYTE
B VAR BYTE
C VAR BYTE
ADCON1 = 15 ' Set all I/Os to Digital
INTCON2.7 = 0 ' Disable PortB Pullups
CMCON = 7 ' Disable Comparators
' Interrupt Settings
RCON.7 = 0 ' Disable Priority Interrupts, 1 to Enable
' Enable/Disable Interrupts
INTCON.4 = 0 ' Disable INT0 (PORTB.0)
INTCON3.3 = 0 ' Disable INT1 (PORTB.1)
INTCON3.4 = 0 ' Disable INT2 (PORTB.2)
INTCON.5 = 0 ' Disable TMR0 (Timmer 0)
INTCON.6 = 1 ' Enable Peripheral Interrupts
INTCON.7 = 1 ' Enable Global Interrupt Handler
PIE1.4 = 0 ' USART Transmit Interrupt
PIE1.5 = 1 ' USART Receive Interrupt
PIE2.5 = 0 ' USB Interrupt
PORTA = 0
TRISA = %00000000
HIGH LED
PAUSE 1000
USBInit
PAUSE 1
LOW LED
ON INTERRUPT GOTO Interruptor
ENABLE INTERRUPT
'-------------------------------------------------------------------------------
Inicio:
USBService
Cnt = 3
USBIn 3, Buffer, Cnt, Inicio
GOTO usbSaida
GOTO Inicio
'-------------------------------------------------------------------------------
DISABLE INTERRUPT
Interruptor:
IF Transmite = 1 THEN
Transmite = 0
ENDIF
IF Recebe = 1 THEN
HSERIN 2, Continua, [Wait("<"), a, b]
Buffer[0] = A
Buffer[1] = B
Buffer[2] = 13
Buffer[3] = 10
Cnt = 3
Recebe = 0
goto usbSaida
ENDIF
Continua:
Recebe = 0
GOTO Fim
'-------------------------------------------------------------------------------
usbSaida:
USBService
USBOut 3, Buffer, Cnt, usbSaida
goto Inicio
'-------------------------------------------------------------------------------
Fim:
RESUME
ENABLE INTERRUPT
'-------------------------------------------------------------------------------
END
Bookmarks