News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Having issues communicating between 2 PICs

Started by JohnB, Sep 16, 2023, 01:49 PM

Previous topic - Next topic

JohnB

I don't seem to be able to get the serial comms working between 2 PICs in real life so I built a very basic Host setup so I could test it in ISIS. 

The essential comms code for HOST and CLIENT PICs are shown below:

Host:
  dim ctr as byte
    ctr = 50
    ' See if the matrix display is connected
  while ctr>0
    HrsOut2 "Sending $AA, $A0",$D
    HRSOut Pre,Attn
    TmpB1 = HrsIn, {500, Timeout}, WAit(Pre)            ' wait for response from Matrix display                                   ' Something has responded
    If TmpB1 = Ack then                                  ' If matrix should respond with Ack
      Matrix_OK = true                                   '
      HrsIn MatrixHasTemp                                ' See if it has Air temp sensor
      HRSOut2 "Matrix OK",$D                             ' report Matrix Display present
      GoTo Mainloop
    endif
    Timeout:                                             ' Timed out waiting for response
      HRSOut2 "Retrying",$D
      dec(ctr)
  Wend
  HRSOut2 "Given up",$D                                  ' so report it.


MainLoop:
stop


Client:
    TmpB1 = HrSin, {1000, Acquire}, wait(Pre) ' Look for Sync - $5555 and fetch control byte
    Select TmpB1
      CAse Attn                             ' Get Matrix Config
        HrsOut Ack, HasTempSensor
      case PutPoolTemp                        ' Update Pool Temperature  ( from Master )
        PrevPool = PoolTemp
        HRSIn PoolTemp
        HrsOut Ack
      Case PutAirTemp                       ' Update Air Temperature   ( from Master )
        PrevAir = AirTemp
        HRSIn AirTemp                       ' read in air temp and acknowledge
        HrsOut Ack
      Case GetAirTemp                       ' Get Air Temperature
        if HasTempSensor = true then
          HrsOut Ack, AirTemp               ' Return Temperature   ( To Master )
        else
          HrsOut Nack                       ' No sensor so Nack it
        EndIf
    else
      HrsOut Nack                           ' Anything else NACK it
    endSelect

The Client PIC never responds to the Wakeup command.

Any suggestion would be welcomed, perhaps this is not the best approach.

I have attached the HOST and CLIENT code and the ISIS simulation.



JohnB

tumbleweed

I think you're going to have a problem getting reliable communications using HRSIN.
There's only a 2 byte hardware buffer in the uart, so if more than that ever come in then you'll get an overrun error and it'll lock up until cleared.
If that happens then you'll have a hard time getting things in sync again.

That could happen right from the get-go if you happened to start the master side running before the receiver.

You could try adding the appropriate 'Hserial_Clear' to both sides, but that'll only help so far.

For the RX sides you're a lot better off using an interrupt-driven serial buffer arrangement.

tumbleweed

Just to add...

I've found that there are two simple ways to get comms between two processors working half-way reliably (along with having an interrupt input buffer)

1) use ASCII text messages and terminate the commands with a CR. It's slower, but you can always detect the end of a message, malformed messages, etc. Has the added benefit of being able to easily watch what's going on between them and you don't have to worry about the size of the data (bytes, words, signed) or the format (highbyte/lowbyte, float, integer, etc).

2) if you want to use binary data then use a real packet format. Doesn't have to be too complicated, something as simple as <SOM><BYTE COUNT><message body><EOM> can go a long way towards letting both sides be able to sync messages since you now have half a shot at figuring out when a message starts/ends.

JohnB

Quote from: tumbleweed on Sep 16, 2023, 03:22 PMFor the RX sides you're a lot better off using an interrupt-driven serial buffer arrangement.
That's what I suspected but I noticed there isn't a buffered USART library for the 16F series as far as I could see so I wondered if there is a reason for that. e.g. memory addressing limitations.

I will give it a go with ASCII and I try cutting my own Buffered serial for the 16 series.
JohnB

TimB

John

I have written a lot of pic - pic coms software. If you let me know some basic info like the devices, and the packet type i.e if raw data or ascii (raw recommended)  I will post some code to enable you to talk. Easy to amemned....




JohnB

Project comprises main unit with a Nextion HMI display built in and a repeater display which will be remote.  Main unit and Repeater are connected by RS232 link.

Main unit uses PIC 18F27K42, I'm using USART1 to drive the HMI, using Les's buffer RX for input from the HMI.
I have a receive protocol running happily on the USART1 it starts with 3 bytes $AA $AA $AA header, control 1 byte, Data 3 bytes, followed by trailer $FF $FF $FF.  The Tx protocol is similar but can be can have any length of ASCII data bytes.  The protocol has been largely dictated by the HMI comms protocol.

USART2 drives the repeater display and will ideally run the same protocol.

PIC in the repeater display is a PIC 16F1705, but there are no buffered RX libraries for 16 Series PICs so I was wondering if there is a reason for that. i.e. are there issues with 16 series architecture that make it difficult to implement an interrupt driven buffered receive. If you have suitable code which implements buffered receive on a 16 series that would be very helpful.
JohnB

TimB


Hi John

I have started on it. All usarts will be buffered in and out. Although the USART IN will not work like HRSIN. It will just set a flag when you have data. i.e the 3 bytes

The 16F code will be a RX routine that you will have to manage the data decoding as I do not know the format. It is very easy though to figure out what is going on.

Tim

JohnB

thank Tim  looking forward to seeing your solution
JohnB

top204

Whenever I use serial coms, I use an interrupt serial buffer for receive, and the interrupt serial buffering is very similar on an enhanced 14-bit core device to an 18F device because they have a mechanism that makes RAM, almost, linear when used indirectly, and when a particular bit is set in the RAM address, and the compiler takes this into account. They also have WREG as an SFR, so the final buffer code is also very similar to an 18F device.

But there are some important differences because the enhanced 14-bit core devices all use WREG as a temporary storage when transfering variables into each other, as opposed to the 18F devices that have the Movff and Movffl mnemonics that do not use WREG. This type of difference can be very important when writing code for low-level operations to replace the compiler's mechanisms.

Below is a code listing for a library file that will create an interrupt driven buffered replacement for the HRSin1 and HSerin1 commands for a PIC16F1705 device, with and without timeouts:

$ifndef _USART_INT_BUFFER_
$define _USART_INT_BUFFER_
'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Interrupt driven serial buffer for an enhanced 14-bit core PIC16F1705 device.
' Written by Les Johnson for the Positron8 compiler.
'
    #Disable HRSIn, HRSInTo, HRSIn_RCREG_Read                       ' Disable the library subroutines for Hrsin1 and HSerin1 with and without timeouts

$ifndef True
    $define True 1
$endif
$ifndef False
    $define False 0
$endif

'------------------------------------------------------------------------------

$define IntGlobal_Enable()  INTCONbits_GIE = 1                      ' Enable global interrupts
$define IntGlobal_Disable() INTCONbits_GIE = 0                      ' Disable global interrupts

$define IntPeriph_Enable()  INTCONbits_PEIE = 1                     ' Enable peripheral interrupts
$define IntPeriph_Disable() INTCONbits_PEIE = 0                     ' Disable peripheral interrupts

'------------------------------------------------------------------------------
$define USART1_RX_Int_Enable()  PIE1bits_RCIE = 1                   ' Enable interrupt on USART1 receive on a PIC16F1705 device
$define USART1_RX_Int_Disable() PIE1bits_RCIE = 0                   ' Disable interrupt on USART1 receive on a PIC16F1705 device

'------------------------------------------------------------------------------
' Enable USART1 on a PIC16F1705 device
'
$define USART1_Enable() '
    TX1STAbits_TXEN = 1 '
    RCSTAbits_SPEN = 1

'------------------------------------------------------------------------------
' Disable USART1 on a PIC16F1705 device
'
$define USART1_Disable() '
    TX1STAbits_TXEN = 0  '
    RCSTAbits_SPEN = 0

'------------------------------------------------------------------------------
$define USART1_TX_Disable() TX1STAbits_TXEN = 0                     ' Disable USART1 TX on a PIC16F1705 device
$define USART1_TX_Enable()  TX1STAbits_TXEN = 1                     ' Enable USART1 TX on a PIC16F1705 device
'------------------------------------------------------------------------------
$define USART1_RX_Disable() RCSTAbits_SPEN = 0                      ' Disable USART1 RX on a PIC16F1705 device
$define USART1_RX_Enable()  RCSTAbits_SPEN = 1                      ' Enable USART1 RX on a PIC16F1705 device

'------------------------------------------------------------------------------
$define USART1_RX_Flag() PIR1bits_RCIF                              ' The bit that indicates a byte has been received on USART1 on a PIC16F1705 device
$define USART1_TX_Flag() PIR1bits_TXIF                              ' The bit that indicates a byte is being transmitted from USART1 on a PIC16F1705 device
'
' Create some Compiler system variables used in the hardware serial receive commands
'
    Dim GEN                   As Byte System                        ' \
    Dim GENH                  As Byte System                        ' / Buffered HRsin1 Timeout value storage
    Dim PP0                   As Byte System                        ' Holds the received byte
    Dim PP1                   As Byte System                        ' \
    Dim PP1H                  As Byte System                        ' / Buffered HRsin1 Timeout inside loop counter
'
' Create variables for the USART1 interrupt buffered serial
'
    Dim USARTx_TimeoutInt     As GEN
    Dim USARTx_TimeoutIntH    As GENH
    Dim USARTx_wTimeoutValue  As USARTx_TimeoutInt.Word             ' Alias the timeout value to GEN\H
    Dim USARTx_InsideLoopInt  As PP1
    Dim USARTx_InsideLoopIntH As PP1H
    Dim USARTx_wInsideLoop    As USARTx_InsideLoopInt.Word          ' Alias the inside loop to PP1\H
    Dim USARTx_wOutsideLoop   As Word Access                        ' Holds the outside loop counter
    Dim USARTx_bRXByte        As Byte Access                        ' Holds the byte received from USART1
    Dim USART1_bIndexIn       As Byte Access                        ' Pointer to the next empty location in the USART1 buffer
    Dim USART1_bIndexOut      As Byte Access                        ' Pointer to the location of the oldest character in the USART1 buffer
    Dim USARTx_wFSR0Save      As Word                               ' Holds a copy of FSR0L and FSR0H within the HRsin1 library replacement routines
'
' Create the actual serial buffer for USART1 in high RAM, so it does not interfere with variables that require RAM bank switching
'
$define _cUSART1_RX_BufferSize 64                                   ' The amount of RAM reserved for the USART1 receive buffer (Max 255)
    Dim USART1_bRX_Buffer[_cUSART1_RX_BufferSize] As Byte Heap      ' Array for holding received bytes from USART1 (in high RAM because it is used indirectly, so needs no RAM bank switching mnemonics)

    Dim Global_tByteInBuffer1 As Bit                                ' Indicates that there is a byte in USART1's RX buffer
'
' Alias some SFR's as 16-bit variables
'
    Dim USARTx_wFSR0 As FSR0L.Word
    Dim USARTx_wFSR1 As FSR1L.Word

'------------------------------------------------------------------------------------------
    Goto _USARTx_Main_                                              ' Jump over the replacement library subroutines

'------------------------------------------------------------------------------------------
' Wait for a byte from the interrupt driven circular USART1 buffer with timeout
' Input     : GEN\GENH hold the timeout value in approx ms (0 to 65535)
' Output    : PP0 and WREG hold the value received
'           : Carry Flag (STATUS.0) Clear if timeout out
' Notes     : Uses FSR0L\H as buffer pointers, so they are saved and restored
'
__HRsin1_With_TimeOut__:
    USARTx_wOutsideLoop = USARTx_wTimeoutValue                      ' Save the timeout value so it doesn't get overwritten
    USARTx_wInsideLoop = 0                                          ' Reset the inside loop counter
_USART1_OutsideLoop:
    DelayCS 2                                                       ' Delay for 2 cycles within the outside loop
_USART1_InsideLoop:
    DelayCS 1                                                       ' Delay for 1 cycle within the inside loop
    WREG = USART1_bIndexIn                                          ' \
    Subwf USART1_bIndexOut,w                                        ' / Is there anything in the serial buffer?
    Bnz USART1_GetByte                                              ' Yes. So read it
    WREG = 255                                                      ' \
    Addwf USARTx_wInsideLoop,f                                      ' |
    Addwfc USARTx_wInsideLoopH,f                                    ' | Decrement the inside and outside loops
    Addwfc USARTx_wOutsideLoop,f                                    ' |
    Addwfc USARTx_wOutsideLoopH,f                                   ' /
    Btfss STATUSbits_C
    Ret                                                             ' Return with the Carry flag clear to indicate timed out
    Incfsz PP1,W
    Bra _USART1_OutsideLoop
    Incfsz PP1H,W
    Bra _USART1_OutsideLoop
    USARTx_wInsideLoop = ((59 * Xtal) / 4)                          ' Set the inside loop counter based upon the Xtal frequency
    GoTo _USART1_InsideLoop

'------------------------------------------------------------------------------------------
' Wait for a byte from the interrupt driven circular buffer without timeout
' Input     : None
' Output    : PP0 and WREG hold the value received
' Notes     : Uses FSR0L\H as buffer pointers, so they are saved and restored
'
__HRsin1__:
    While USART1_bIndexIn = USART1_bIndexOut                        ' \ Wait for a byte to appear in the serial receive buffer
    Wend                                                            ' /
'
' Fall through to USART1_GetByte
'------------------------------------------------------------------------------
' Read a byte from the interrupt driven circular buffer
' Input     : None
' Output    : PP0 and WREG hold the value received
' Notes     : Uses FSR0L\H as buffer pointers, so they are saved and restored
'
Sub USART1_GetByte()
    Inc USART1_bIndexOut                                            ' Increment USART1_bIndexOut pointer (0 to 255)
    If USART1_bIndexOut >= _cUSART1_RX_BufferSize Then              ' End of the USART1 RX buffer reached?
        USART1_bIndexOut = 0                                        ' Yes. So clear USART1_bIndexOut
    EndIf
    USARTx_wFSR0Save = USARTx_wFSR0                                 ' Save FSR0L\H registers
    USARTx_wFSR0 = AddressOf(USART1_bRX_Buffer)                     ' Point FSR0L\H to the address of USART1_bRX_Buffer
    USARTx_wFSR0 = USARTx_wFSR0 + USART1_bIndexOut                  ' Add the buffer position to FSR0L\H
    PP0 = INDF0                                                     ' Read buffer location (USART1_bIndexOut) into PP0
    USARTx_wFSR0 = USARTx_wFSR0Save                                 ' Restore FSR0\H registers
    WREG = PP0                                                      ' Place the byte read from the buffer into WREG
    STATUSbits_C = 1                                                ' Set the Carry flag to indicate a byte received
EndSub

'--------------------------------------------------------------------------------
' Initialise the USART1 RX interrupt
' Input     : None
' Output    : None
' Notes     : Enables interrupt on USART1 receive
'
Proc USART1_InitInterrupt()
    Global_tByteInBuffer1 = 0                                       ' Clear the byte in buffer flag for USART1
    USART1_bIndexIn = 0                                             ' Clear the USART1 buffer internal pointer
    USART1_bIndexOut = 0                                            ' Clear the USART1 buffer external pointer
    USART1_RX_Int_Enable()                                          ' Enable interrupt on USART1 receive
EndProc

'--------------------------------------------------------------------------------
' Disable the USART1 RX interrupt
' Input     : None
' Output    : None
' Notes     : Disables interrupt on USART1 receive
'
Proc USART1_DisableInterrupt()
    Global_tByteInBuffer1 = 0                                       ' Clear the byte in buffer flag for USART1
    USART1_bIndexIn = 0                                             ' Clear the USART1 buffer internal pointer
    USART1_bIndexOut = 0                                            ' Clear the USART1 buffer external pointer
    USART1_RX_Int_Disable()                                         ' Disable interrupt on USART1 receive
EndProc

'--------------------------------------------------------------------------------
' Clear the USART1 Serial Buffer
' Input     : None
' Output    : None
' Notes     : Also resets the index pointers to the serial buffer
'
Proc USART1_ClearSerialBuffer()
    USART1_RX_Int_Disable()                                         ' Disable interrupt on USART1 receive
    WREG = RCREG                                                    ' \ Empty USART1's 2-byte serial buffer
    WREG = RCREG                                                    ' /
    USART1_RX_Flag() = 0                                            ' Clear the USART1 byte received flag
    USART1_bRX_Buffer = 0                                           ' Clear the USART1 serial buffer
    Global_tByteInBuffer1 = 0                                       ' Reset the byte in USART1 RX buffer flag
    USART1_bIndexIn = 0                                             ' Clear the USART1 buffer internal pointer
    USART1_bIndexOut = 0                                            ' Clear the USART1 buffer external pointer
    USART1_RX_Int_Enable()                                          ' Re-Enable interrupt on USART1 receive
EndProc

'--------------------------------------------------------------------------------
' Enable USART1
' Input     : None
' Output    : None
' Notes     : Also enables the USART1 RX interrupt
'
Proc USART1_Open()
    USART1_RX_Flag() = 0                                            ' Clear the USART1 RX flag
    USART1_Enable()                                                 ' Enable USART1
    USART1_ClearSerialBuffer()                                      ' Clear USART1 serial buffers
    USART1_InitInterrupt()                                          ' Enable USART1 interrupt
EndProc

'--------------------------------------------------------------------------------
' Disable USART1
' Input     : None
' Output    : None
' Notes     : Also disables the USART1 RX interrupt
'
Proc USART1_Close()
    USART1_DisableInterrupt()                                       ' Disable USART1 interrupt
    USART1_Disable()                                                ' Disable USART1
    USART1_RX_Flag() = 0                                            ' Clear the USART1 RX flag
    USART1_ClearSerialBuffer()                                      ' Clear USART1 serial buffers
EndProc

'------------------------------------------------------------------------------
_USARTx_Main_:
$endif      ' _USART_INT_BUFFER_

Copy the above code listing into the IDE and save it named as: "RX_Buffer_16F1705.inc" and place it in the same folder as the .bas files that use it, or place it in the "Includes" directory for all programs to see. The Includes directory is located here: "C:\Users\User Name\PDS\Includes\".

Adding more serial buffers for extra USARTs is very straightforward, and follows the same code mechanism as above, but with different SFRs used and seperate variables for the extra USART buffers and index pointers etc... Also, extra meta-macros and procedures for the extra USART setups.

Below is a demo code listing that uses the above library file and displays the characters typed into a serial terminal, even with a large delay between receiving and transmitting because the bytes received are held in the buffer:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Interrupt driven serial buffer demo for an enhanced 14-bit core PIC16F1705 device.
'
' Written by Les Johnson for the Positron8 compiler
'
    Device = 16F1705                                                ' Tell the compiler what device to compile for
    Declare Xtal = 32                                               ' Tell the compiler what frequency the device is operating at (in MHz)
    On_Hardware_Interrupt Goto ISR_Handler                          ' Point to the interrupt handler routine
'
' Setup USART1
'
    Declare HRSOut1_Pin  = PORTC.4
    Declare HRSIn1_Pin   = PORTC.5
    Declare Hserial_Baud = 9600                                     ' Set the Baud rate for USART1

    Include "RX_Buffer_16F1705.inc"                                 ' Load the USART1 interrupt routines into the program
'
' Create any variables for the demo
'
    Dim MyByte As Byte

'------------------------------------------------------------------------------------------
' The main program starts here
' Receive bytes from a serial terminal and re-transmit them.
' Has a large delay in the loop to show the serial buffer is working
'
Main:
    Setup()                                                         ' Setup the program

    HRsout1Ln "Type in characters and they will be displayed as they are typed on a serial terminal"
    Do                                                              ' Create a loop
Again:
       HSerin1 5000, TimedOut, [MyByte]                             ' Receive a byte from USART1 (with a 5 second timeout)
       HRsout1 MyByte                                               ' Transmit the character received
       DelayMs 200                                                  ' Perform a large delay to test the serial buffer
    Loop                                                            ' Do it forever
'
' Jump here if a timeout occurs
'
TimedOut:
    HRsout1Ln "\rTimed Out"
    Goto Again

'------------------------------------------------------------------------------------------
' Setup the program
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    OSCCON = 0b11110010                                             ' 4xPPL on, 32MHz, Internal
    USART1_Open()                                                   ' Enable USART1 and its receive interrupt

    IntPeriph_Enable()                                              ' Enable peripheral interrupts
    IntGlobal_Enable()                                              ' Enable global interrupts
EndProc

'------------------------------------------------------------------------------------------------
' Interrupt handler routine
' Input     : None
' Output    : Global_tByteInBuffer1 holds 1 if a valid byte was received via USART1
' Notes     : Interrupts on a USART1 receive and is given a serial buffer
'
ISR_Handler:
    Context Save                                                    ' Save any compiler system variables and SFRs used, before the interrupt code is performed
'
' Check the USART1 interrupt
'
    If USART1_RX_Flag() = 1 Then                                    ' Was it a USART1 byte receive that triggered the interrupt?
        WREG = RCSTA & %00000110                                    ' Yes. So mask out unwanted bits and check for errors
        If STATUSbits_Z = 0 Then                                    ' Are there any bits set in RCSTA?
            WREG = RCREG1                                           ' \ Yes. So empty the 2 byte USART1 buffer
            WREG = RCREG1                                           ' /
            RCSTAbits_CREN = 0                                      ' Disable USART1's RX to clear flags
            USART1_RX_Flag() = 0                                    ' Clear USART1's RX flag
            RCSTAbits_CREN = 1                                      ' Re-Enable USART1's RX
        Else                                                        ' Otherwise... No error so...
            USARTx_bRXByte = RCREG1                                 ' Place the byte received into USARTx_bRXByte
            Inc USART1_bIndexIn                                     ' Move up the USART1 receive buffer
            If USART1_bIndexIn >= _cUSART1_RX_BufferSize Then       ' End of USART1 receive buffer reached?
                USART1_bIndexIn = 0                                 ' Yes. So reset USART1_bIndexIn
            EndIf
            USARTx_wFSR1 = AddressOf(USART1_bRX_Buffer)             ' Point FSR1L\H to the address of USART1_bRX_Buffer
            USARTx_wFSR1 = USARTx_wFSR1 + USART1_bIndexIn           ' Add the buffer's position to FSR1L\H
            INDF1 = USARTx_bRXByte                                  ' Place the received byte into the buffer
            Global_tByteInBuffer1 = 1                               ' Indicate that there is a byte in the USART1 receive buffer (must be reset in the main program after it is checked)
        EndIf
    EndIf

    Context Restore                                                 ' Restore any compiler system variables and SFRs used in the interrupt code, and exit the interrupt handler

'------------------------------------------------------------------------------------------
' Set the config fuses for internal oscillator on a PIC16F1705 device
'
    Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_ON, MCLRE_ON, CP_OFF, BOREN_ON, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
    Config2 WRT_OFF, PPS1WAY_OFF, ZCDDIS_OFF, PLLEN_ON, STVREN_ON, BORV_LO, LPBOR_OFF, LVP_OFF