Ok, I got it all working now. I took Darrel's advice and switched to using HSERIN and HSEROUT but added the use of hardware interrupts to capture the RS232 data.
Here's the new code:
Code:DEFINE OSC 48 DEFINE HSER_RCSTA 90h DEFINE HSER_TXSTA 20h DEFINE HSER_BAUD 9600 DEFINE HSER_CLROERR 1 INCLUDE "modedefs.bas" Buffer VAR BYTE[16] Cnt VAR BYTE B0 VAR BYTE PIC_TX VAR PORTC.6 ' Transmit Pin PIC_RX VAR PORTC.7 ' Receive Pin LED1A VAR PORTB.0 ' 2 Color LED #1 LED1B VAR PORTB.1 LED2A VAR PORTB.2 ' 2 Color LED #2 LED2B VAR PORTB.3 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 LOW LED1A ' Turn LED #1 Green HIGH LED1B LOW LED2A ' Turn LED #2 Off LOW LED2B PAUSE 500 USBInit ON INTERRUPT GOTO Main_Interrupt_Handler ENABLE INTERRUPT ' Main Program Loop MainLoop: USBService ' Must service USB regularly Cnt = 16 USBIn 3, Buffer, Cnt, MainLoop HIGH LED2A PAUSE 25 HSEROUT [STR Buffer\Cnt] LOW LED2A 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 HIGH LED2B PAUSE 25 HSERIN [B0] Buffer[0] = B0 Cnt = 1 OutLoop: USBService ' Must service USB regularly USBOut 3, Buffer, Cnt, OutLoop LOW LED2B PIR1.5 = 0 ENDIF '--------------------------------------------------------------------------- IntDone: RESUME ' Return to main program ENABLE INTERRUPT '------------------------------------------------------------------------------- END




Bookmarks