Data of hserin is ok
............
USBService ' Must service USB regularly
Cnt = 10
USBIn 3, Buffer, Cnt, MainLoop
' Send to pc data recived from pc
GOTO OutLoop <---------not work, not send buffer
GOTO Mainloop
.........
Code:
INCLUDE "modedefs.bas"
' Configuração
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
Buffer VAR BYTE[16]
Cnt VAR BYTE
A VAR BYTE
B VAR BYTE
C VAR BYTE
PIC_TX VAR PORTC.6 ' Transmit Pin
PIC_RX VAR PORTC.7 ' Receive Pin
ADCON1 = 15 ' Set all I/Os to Digital
INTCON2.7 = 1 ' 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 ' Disable USART Transmit Interrupt
PIE1.5 = 1 ' Enable USART Receive Interrupt
PIE2.5 = 0 ' Disable USB Interrupt
PAUSE 1000
USBInit
ON INTERRUPT GOTO Main_Interrupt_Handler
ENABLE INTERRUPT
' Main Program Loop
MainLoop:
USBService ' Must service USB regularly
Cnt = 10
USBIn 3, Buffer, Cnt, MainLoop
' Send to pc data recived from pc
GOTO OutLoop
GOTO Mainloop
' Interrupt Handler
'-------------------------------------------------------------------------------
DISABLE INTERRUPT ' No Interrupts past this point
Main_Interrupt_Handler:
' USART Transmit Interrupt
IF PIR1.4 = 1 THEN
PIR1.4 = 0
ENDIF
' USART Receive Interrupt
IF PIR1.5 = 1 THEN
HSERIN [A, B, C]
Buffer[0] = A
Buffer[1] = B
Buffer[2] = C
Buffer[3] = 13
Buffer[4] = 10
Cnt = 4
OutLoop:
USBService ' Must service USB regularly
USBOut 3, Buffer, Cnt, OutLoop
PIR1.5 = 0
ENDIF
'-------------------------------------------------------------------------------
IntDone:
RESUME ' Return to main program
ENABLE INTERRUPT
'-------------------------------------------------------------------------------
END
Bookmarks